Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Linux 簡易判斷 CC 攻擊的三條 tcpdump 實戰指令

編輯:關於伺服器

背景

CC 攻擊成本低、發起易,多使用現成工具,特徵明顯。利用 tcpdump 即時抓封包分析,可快速判斷是否遭受攻擊。

前置準備

# CentOS/RHEL
yum install -y tcpdump

# Debian/Ubuntu
apt-get install -y tcpdump

指令一:分析 HTTP 請求路徑分布

tcpdump -s0 -A -n -i any | grep -o -E '(GET|POST|HEAD) .*'

正常流量特徵

GET /static/css/style.css HTTP/1.1
GET /api/user/info HTTP/1.1
POST /order/submit HTTP/1.1
GET /images/logo.png HTTP/1.1

靜態資源 (css, js, jpg, png) 請求佔比高,路徑多樣。

攻擊流量特徵

  • 大量固定路徑:GET / HTTP/1.1 (攻擊首頁)
  • 特定規律路徑:/thread-隨機數-1-1.html (針對 Discuz 論壇)
  • 單一 API 瘋狂請求:POST /ajax/validator.php

指令二:檢視 User-Agent 分布

tcpdump -s0 -A -n -i any | grep '^User-Agent'

正常

UA 多樣:Chrome, Firefox, IE, 爬蟲 (bingbot, Googlebot) 等交替出現。

攻擊

  • 單一 UA 刷屏:Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) 持續重複。
  • 異常亂碼 UA:axd5m8usy 等明顯非標準字串。

指令三:鎖定被攻擊域名 (Host 頭)

tcpdump -s0 -A -n -i any | grep '^Host'

輸出範例

Host: www.45it.com
Host: www.45it.com
Host: sos.45it.com
Host: sos.45it.com
...

若某域名佔比極高,即為攻擊目標,可針對性防護 (WAF 規則、限流、封禁 IP)。

實戰建議

  • 配合 awk/sort/uniq -c 做統計:
    tcpdump ... | grep '^Host' | awk '{print $2}' | sort | uniq -c | sort -nr
  • 生產環境建議部署專業 WAF (ModSecurity, OpenResty + lua-resty-waf) 或雲端防護 (Cloudflare, 阿里云盾)。
Copyright © Windows教程網 All Rights Reserved