CC 攻擊(Challenge Collapsar)透過模擬大量使用者不斷請求特定頁面,耗盡伺服器資源導致服務癱瘓。本文彙整一組常用的 netstat、tcpdump、iptables 指令,協助管理員快速識別異常連線來源並實施封鎖。

netstat -nat | grep -i "80" | wc -l
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
netstat -nat | awk '{print $6}' | sort | uniq -c | sort -rn
netstat -anlp | grep 80 | grep tcp | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | head -n20
netstat -ant | awk '/:80/{split($5,ip,":");++A[ip[1]]} END {for(i in A) print A[i],i}' | sort -rn | head -n20
tcpdump 嗅探 80 埠流量,快速定位高頻 IPtcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr | head -20
TIME_WAIT 或 SYN 連線netstat -n | grep TIME_WAIT | awk '{print $5}' | sort | uniq -c | sort -rn | head -n20
netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more
| 封鎖範圍 | 指令範例 |
|---|---|
| 單一 IP | iptables -I INPUT -s 211.1.0.0 -j DROP |
| IP 段(/16) | iptables -I INPUT -s 211.1.0.0/16 -j DROP |
| 整個 A 類網段(/8) | iptables -I INPUT -s 211.0.0.0/8 -j DROP |
| 多個特定段 | iptables -I INPUT -s 61.37.80.0/24 -j DROPiptables -I INPUT -s 61.37.81.0/24 -j DROP |
/etc/rc.localiptables-save > /etc/sysconfig/iptablesservice iptables save(推薦,啟動順序早於 network,更安全)iptables -D INPUT -s IP地址 -j REJECTiptables -Ffail2ban 或 WAF 自動化防護。