Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

权威DNS遭到DDOS攻击 #71

Closed
gaoyifan opened this issue Dec 4, 2016 · 13 comments
Closed

权威DNS遭到DDOS攻击 #71

gaoyifan opened this issue Dec 4, 2016 · 13 comments

Comments

@gaoyifan
Copy link
Member

gaoyifan commented Dec 4, 2016

权威DNS遭到DDOS攻击,平均流量13MB/s,平均包率140K pps

峰值 19MB/s 200K pps

screen shot 2016-12-05 at 2 59 59 am

部分抓包:

02:19:49.641872 IP 61.50.244.60.63943 > 202.141.160.97.53: 32975% [1au] A? ppsuls.mirrors.ustc.edu.cn. (55)
02:19:49.641877 IP 211.137.50.213.7818 > 202.141.160.97.53: 56424 A? msqkhm.mirrors.ustc.edu.cn. (44)
02:19:49.641883 IP 219.146.28.138.45423 > 202.141.160.97.53: 41070% [1au] A? nkzzgd.mirrors.ustc.edu.cn. (55)
02:19:49.641888 IP 211.138.151.34.40034 > 202.141.160.97.53: 26090 [1au] A? etslhj.mirrors.ustc.edu.cn. (55)
02:19:49.641893 IP 60.12.74.130.6131 > 202.141.160.97.53: 33209 [1au] A? mmxwmu.mirrors.ustc.edu.cn. (55)
02:19:49.641899 IP 61.50.246.116.48346 > 202.141.160.97.53: 63400% [1au] A? bkfrae.mirrors.ustc.edu.cn. (55)
02:19:49.641903 IP 202.98.0.90.12697 > 202.141.160.97.53: 37287% [1au] A? uudzit.mirrors.ustc.edu.cn. (55)
02:19:49.641909 IP 122.224.33.146.4925 > 202.141.160.97.53: 20661 [1au] A? osrfpb.mirrors.ustc.edu.cn. (55)
02:19:49.641914 IP 211.137.50.212.62208 > 202.141.160.97.53: 38971 [1au] A? vjdrkj.mirrors.ustc.edu.cn. (55)
02:19:49.641918 IP 211.137.50.214.27252 > 202.141.160.97.53: 31782 [1au] A? gnfyyv.mirrors.ustc.edu.cn. (55)
02:19:49.641923 IP 202.38.93.97.655 > 202.141.160.97.655: UDP, length 76
02:19:49.641929 IP 101.226.66.18.13504 > 202.141.160.97.53: 4049% [1au] A? cundhy.mirrors.ustc.edu.cn. (67)
@bojieli
Copy link
Member

bojieli commented Dec 4, 2016

如果确定是源地址来源广泛,但访问 pattern 固定的 DDoS,可以在 iptables 里面根据字符串临时做一下屏蔽。

iptables -A INPUT -m string --algo bm --string ".mirrors.ustc.edu.cn" -j DROP

@gaoyifan
Copy link
Member Author

gaoyifan commented Dec 4, 2016

@bojieli 如预期的一样,增加iptables string后,CPU 100%.....

@gaoyifan
Copy link
Member Author

gaoyifan commented Dec 4, 2016

https://cloud.yfgao.com/f/97aa5f3edb/ (expired)
抓包数据,供分析

@gaoyifan
Copy link
Member Author

gaoyifan commented Dec 4, 2016

换成iptables -A INPUT -m string --algo bm --from 40 --hex-string "|07|mirrors|04|ustc" -j DROP后,DNS已经可以正常响应查询请求。(虽然CPU还是100%)

目前包率降至 100K pps

@bojieli
Copy link
Member

bojieli commented Dec 4, 2016

@gaoyifan 👍 可以增加一条规则来允许 mirrors.ustc.edu.cn 的查询请求,但不允许 *.mirrors.ustc.edu.cn 的查询请求。

iptables -A INPUT -m string --algo bm --hex-string "|0007|mirrors|04|ustc|03|edu|02|cn|" -j ACCEPT
iptables -A INPUT -m string --algo bm --hex-string "|07|mirrors|04|ustc|03|edu|02|cn|" -j DROP

@gaoyifan
Copy link
Member Author

gaoyifan commented Dec 4, 2016

@bojieli 似乎不一定是0007
本地发出的包也可能是0107,即Additional RRs: 1

@bojieli
Copy link
Member

bojieli commented Dec 4, 2016

@gaoyifan 刚统计了一下 5 秒钟抓包数据,发起攻击的 IP 地址数量不足 10K 个,这些地址中大多发出了两个以上的数据包,还有少数几个地址发出了大量数据包,说明攻击者的 IP 地址池也就这么大了,可以使用黑洞路由的方法封锁。

黑洞路由就是 ip route add blackhole <attacker-ip>,然后打开 Linux 的源路由检查(默认是打开的,但我们很多服务器关掉了),这样在接收数据包的时候查 reverse 路由,就会把来自这些 IP 的包给丢掉,bind9 也就不会收到这些包了。

@gaoyifan
Copy link
Member Author

gaoyifan commented Dec 4, 2016

@bojieli 涨姿势了~ 原来源路由检查还可以这么用

@gaoyifan
Copy link
Member Author

gaoyifan commented Dec 4, 2016

@bojieli
IP范围的确不大,我统计了2个不相邻1分钟内的IP数量,分别是5875和5964。而这2分钟内独立的IP数只有6650

update: 试了一下黑洞,几乎没什么效果,bind依然会跪。

@gaoyifan
Copy link
Member Author

gaoyifan commented Dec 4, 2016

iptables -A INPUT -m string --algo bm --hex-string "|0007|mirrors|04|ustc|03|edu|02|cn|" -j ACCEPT
iptables -A INPUT -m string --algo bm --hex-string "|0107|mirrors|04|ustc|03|edu|02|cn|" -j ACCEPT
iptables -A INPUT -m string --algo bm --from 40 --hex-string "|07|mirrors|04|ustc" -j DROP

添加后,bind已经可以正常解析了,几乎不会查询失败。

@gaoyifan
Copy link
Member Author

gaoyifan commented Dec 5, 2016

7:00 a.m. 攻击停止

@gaoyifan gaoyifan closed this as completed Dec 5, 2016
@zhsj zhsj reopened this Dec 5, 2016
@zhsj
Copy link
Contributor

zhsj commented Dec 6, 2016

被攻击的域名都是泛域解析的域名,用 iptables 似乎很难处理。bind9 的 rate limit 理论上对这类泛域解析的域名能有一定防御作用,但 dns 服务器 cpu 比较弱, bind9 处理不了这么大的包量。能否先让 jamesz 帮忙加个 cpu 看是否有效果。

@zhsj
Copy link
Contributor

zhsj commented Dec 6, 2016

slave dns 挂掉估计是因为 bind9 默认用了 16 个核,从而造成系统负载过高。现在把 bind9 限制在了 2 个核(鉴于目前 mirrors 本身负载就很高了。。)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants