在母雞上,一個客戶的小雞就可能讓整個業務陷入風險。一台對外掃描、傳送垃圾郵件或參與 DDoS 攻擊的 VPS 會招來 abuse 投訴,讓你的 IP 被 Spamhaus 等黑名單收錄,甚至導致整個 IP 段被過濾。本文介紹如何在 KVM 母雞(Proxmox VE 或任何基於 Linux 網橋的環境)上快速找出肇事的 VPS,判斷濫用類型,在不影響其他客戶的前提下制止濫用,並預防最常見的幾種情況。
每台 KVM VPS 在母雞上都有自己的 tap 網絡卡(在 Proxmox VE 中,VM 101 對應 tap101i0)。tap 網絡卡上的計數是從母雞視角統計的,因此 rx 是 VPS 發出的流量,tx 是 VPS 收到的流量。
# Packets and bytes each VPS sent in the last 10 seconds (rx on the tap = outbound from the VPS)
for t in /sys/class/net/tap*; do n=$(basename $t); echo "$n $(cat $t/statistics/rx_packets) $(cat $t/statistics/rx_bytes)"; done > /tmp/a
sleep 10
for t in /sys/class/net/tap*; do n=$(basename $t); echo "$n $(cat $t/statistics/rx_packets) $(cat $t/statistics/rx_bytes)"; done > /tmp/b
join /tmp/a /tmp/b | awk '{printf "%-12s %8d pps %8.1f Mbps\n", $1, ($4-$2)/10, ($5-$3)*8/10/1000000}' | sort -k2 -nr | head
# Live view of who talks to whom on the bridge
iftop -i vmbr0 -nNP
每秒發出數萬個包、但頻寬(Mbps)並不高的 VPS,通常是在發起洪水攻擊或掃描;持續不斷地向 25 埠發起連線,通常是在發垃圾郵件。
# Sample the traffic of one VPS (replace tap101i0)
tcpdump -ni tap101i0 -c 300 -w /root/evidence-vps101-$(date +%F-%H%M).pcap
tcpdump -nr /root/evidence-vps101-*.pcap | head -50
# Outgoing SMTP connections (spam)
tcpdump -ni tap101i0 'tcp dst port 25 and tcp[tcpflags] & tcp-syn != 0' -c 50
# Connections tracked for the VPS's IP (apt install conntrack)
conntrack -L -s 203.0.113.11 2>/dev/null | wc -l
conntrack -L -s 203.0.113.11 2>/dev/null | awk '{print $5}' | sort | uniq -c | sort -nr | head
| 你看到的現象 | 可能原因 |
|---|---|
| 向大量不同 IP 的同一埠(22、23、3389、80)傳送 SYN 包 | 埠掃描或暴力破解,通常是小雞已被入侵 |
| 向不同郵件伺服器的 25 埠發起大量連線 | 傳送垃圾郵件,或郵件指令碼被黑 |
| 向一個或少數幾個目標傳送極高速率的 UDP 或 SYN 包 | 參與 DDoS 攻擊 |
| 持續連線 3333、4444 等埠 | 挖礦(從流量上看通常不算違規,但可能違反你的服務條款) |
先選擇能解決問題的最溫和措施;如果濫用仍在繼續,再逐步升級處理。
# Throttle the VPS immediately to about 8 Mbps (rate is in MB/s; keep the NIC's MAC from "qm config")
qm set 101 --net0 virtio=BC:24:11:AA:BB:CC,bridge=vmbr0,firewall=1,rate=1
# Block outbound SMTP for this VPS with the Proxmox firewall
cat >> /etc/pve/firewall/101.fw <<'EOF2'
[RULES]
OUT DROP -p tcp -dport 25 -log nolog
EOF2
# Pause the VPS (keeps memory state for investigation) or shut it down
qm suspend 101
qm shutdown 101
如果檔案中已經有 [RULES] 段,請把規則加到該段中,不要再追加第二個同名段。然後告知客戶你觀察到的情況,提供證據並說明需要修復的問題;被入侵的 VPS 通常需要重灌系統並更換所有密碼(參見 Linux 木馬排查與清除)。
儘快回覆投訴,寫明涉及的 IP、確認濫用來源的時間、已採取的措施(已限速、已封禁 25 埠、已暫停 VPS),並說明已聯絡客戶。快速、清晰的回覆,是讓 IP 段在上遊網路和黑名單運營方那裡保持良好信譽的關鍵。
# Datacenter-wide security group in /etc/pve/firewall/cluster.fw
[group no-smtp]
OUT DROP -p tcp -dport 25 -log nolog
# Use it in each VPS file, e.g. /etc/pve/firewall/101.fw
[RULES]
GROUP no-smtp
掃描和暴力破解佔用的頻寬非常小。要看包速率和連線數(步驟 1 和步驟 2),而不能只看 Mbps。
在面板或虛擬機器配置中搜尋:grep -r 203.0.113.11 /etc/pve/qemu-server/ /etc/pve/firewall/ 可以顯示是哪臺虛擬機器在使用該 IP。
反覆發生或不予回覆的濫用會導致 IP 被拉黑,並可能迫使上遊服務商為保護自身網路而過濾相關地址。按上述步驟快速處理,並在回覆投訴時說明你採取的措施,就能把影響控制在涉事的那臺 VPS 上。
如果按以上步驟操作後問題仍未解決,請提交工單聯絡 IMIDC 7×24 技術支援,並附上母雞伺服器 IP、受影響的 IP 地址、abuse 投訴編號以及上述命令的輸出,方便工程師快速定位。