# 基于連接速率自動封禁(保存為syn_protect.py) from scapy.allimport sniff, TCP, IP
import os syn_counts ={}
MAX_SYN =50# 每秒50個SYN包觸發封禁 defhandle_packet(pkt):if TCP in pkt and pkt[TCP].flags =='S': src_ip = pkt[IP].src syn_counts[src_ip]= syn_counts.get(src_ip,0)+1if syn_counts[src_ip]> MAX_SYN: os.system(f"iptables -A INPUT -s {src_ip} -j DROP")print(f"封禁SYN Flood IP: {src_ip}") sniff(filter="tcp", prn=handle_packet, store=0)
3. TCP選項過濾(防協議棧指紋探測)
# 使用iptables過濾異常TCP選項
iptables -A INPUT -p tcp -m tcp --tcp-option !2-j DROP # 僅允許MSS選項
iptables -A INPUT -p tcp --tcp-flags ALL URG -j DROP # 丟棄URG標志包
三、UDP層定制防御方案
1. 反射攻擊源端口封禁
# 封禁常見反射協議端口
iptables -A INPUT -p udp --dport123-j DROP # NTP
iptables -A INPUT -p udp --dport53-j DROP # DNS
iptables -A INPUT -p udp --dport1900-j DROP # SSDP
2. 速率限制與包大小過濾
# 限制UDP包速率(每秒1000個包)
iptables -A INPUT -p udp -m limit --limit1000/sec -j ACCEPT
iptables -A INPUT -p udp -j DROP # 過濾大尺寸UDP包(>512字節視為可疑)
iptables -A INPUT -p udp -m length --length512:65535 -j DROP
背景:該功能為幾乎所有系統開發都需要使用的功能,現提供簡單的案例。 1、MyCommand
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;namespace Wp…
從零開發Chrome廣告攔截插件:開發、打包到發布全攻略
想打造一個屬于自己的Chrome插件,既能攔截煩人的廣告,又能優雅地發布到Chrome Web Store?別擔心,這篇教程將帶你從零開始,動手開發一個功能強大且美觀…