Pages

Wednesday, 31 July 2019

Linux桌面系统下,丢弃 DNS 伪包

iptables -N dnsfilter -t mangle
iptables -t mangle -I dnsfilter -p udp -m udp -m u32 --u32 "0&0x0F000000=0x05000000 && 22&0xFFFF@16=0x042442b2,0x0807c62d,0x253d369e,0x2e52ae44,0x3b1803ad,0x402158a1,0x4021632f,0x4042a3fb,0x4168cafc,0x41a0db71" -j DROP
iptables -t mangle -I dnsfilter -p udp -m udp -m u32 --u32 "0&0x0F000000=0x05000000 && 22&0xFFFF@16=0x422dfced,0x480ecd63,0x480ecd68,0x4e10310f,0x5d2e0859,0x80797e8b,0x9f6a794b,0xa9840d67,0xc043c606,0xca6a0102" -j DROP
iptables -t mangle -I dnsfilter -p udp -m udp -m u32 --u32 "0&0x0F000000=0x05000000 && 22&0xFFFF@16=0xcab50755,0xcb620741,0xcba1e6ab,0xcf0c5862,0xd0381f2b,0xd1244921,0xd1913632,0xd1dc1eae,0xd35e4293,0xd5a9fb23" -j DROP
iptables -t mangle -I dnsfilter -p udp -m udp -m u32 --u32 "0&0x0F000000=0x05000000 && 22&0xFFFF@16=0xd8ddbcb6,0xd8eab30d,0xf3b9bb27,0x4a7d7f66,0x4a7d9b66,0x4a7d2771,0x4a7d2766,0xd155e58a" -j DROP
iptables -t mangle -I PREROUTING -m udp -p udp --sport 53 -j dnsfilter
当然也适用于基于 Linux 系统的路由器,Tomato,DD-WRT,OpenWRT 等,把脚本丢到路由器启动脚本里面即可。
------------------

通过ttl判断,过滤欺骗污染.
  获取你的dns服务器正常响应包的ttl,
  以正常的ttl=44举例如下:
  iptables -A INPUT -p udp -sport 53 -m ttl --ttl-lt 44 -j DROP
  iptables -A INPUT -p udp -sport 53 -m ttl --ttl-gt 44 -j DROP
  iptables -A INPUT -p udp -sport 53 -m ttl --ttl-eq 44 -j ACCEPT

No comments:

Post a Comment