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

Linux 系統偵測與防禦 CC 攻擊的實戰指令集

編輯:關於 Linux

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

CC 攻擊流量分析示意圖

一、連線統計與異常 IP 識別

1. 查看 80 埠總連線數

netstat -nat | grep -i "80" | wc -l

2. 依連線數排序 IP(找出佔用最多的前幾名)

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

3. 查看 TCP 連線狀態分佈

netstat -nat | awk '{print $6}' | sort | uniq -c | sort -rn

4. 找出 80 埠連線數最多的前 20 個 IP

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

5. 使用 tcpdump 嗅探 80 埠流量,快速定位高頻 IP

tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr | head -20

6. 檢查大量 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

二、iptables 封鎖策略

封鎖範圍指令範例
單一 IPiptables -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 DROP
iptables -I INPUT -s 61.37.81.0/24 -j DROP

三、規則持久化與解封

  • 持久化(三種方式擇一):
    1. 加入 /etc/rc.local
    2. iptables-save > /etc/sysconfig/iptables
    3. service iptables save(推薦,啟動順序早於 network,更安全)
  • 解封單一 IP: iptables -D INPUT -s IP地址 -j REJECT
  • 清空所有規則: iptables -F

操作建議

  1. 先用統計指令確認異常 IP,避免誤封正常使用者。
  2. 生產環境建議搭配 fail2ban 或 WAF 自動化防護。
  3. 封鎖大網段(/8、/16)風險極高,務必二次確認。
Copyright © Windows教程網 All Rights Reserved