如何保護 Nginx 免受 HULK DoS 工具的侵害

如何保護 Nginx 免受 HULK DoS 工具的侵害

有一個工具叫浩克(Http難以承受負載王)。它是一個 Web 伺服器拒絕服務工具。它旨在在網路伺服器上產生大量獨特且模糊的流量,繞過快取引擎,從而到達伺服器的直接資源池。

我一直在 Nginx 上測試這個,它在幾秒鐘內就讓 Nginx 崩潰了。以下是我的測試的日誌片段。

192.168.1.10 - - [17/May/2013:16:37:35 +0800] "GET /?UDY=CLZFTJP HTTP/1.1" 200 199265 "http://www.usatoday.com/search/results?q=BZWVGQ" "Opera/9.80 (Windows NT 5.2; U; ru) Presto/2.5.22 Version/10.51"
192.168.1.10 - - [17/May/2013:16:37:35 +0800] "GET /?YGNBNQK=BEPPWCSMKJ HTTP/1.1" 200 199272 "http://www.google.com/?q=PJCSSRQLT" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; .NET CLR 2.0.50727; InfoPath.2)"
192.168.1.10 - - [17/May/2013:16:37:35 +0800] "GET /?XETRTJ=LFV HTTP/1.1" 200 199264 "http://www.usatoday.com/search/results?q=QHDEEM" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; .NET CLR 2.0.50727; InfoPath.2)"
192.168.1.10 - - [17/May/2013:16:37:35 +0800] "GET /?JYJHZB=ZHIB HTTP/1.1" 200 199265 "http://www.mywebsite.com/UPHIBL" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) Gecko/20090718 Firefox/3.5.1"
192.168.1.10 - - [17/May/2013:16:37:35 +0800] "GET /?VHXLKAIB=NCU HTTP/1.1" 200 199266 "http://www.mywebsite.com/KIPQLJH" "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)"
192.168.1.10 - - [17/May/2013:16:37:36 +0800] "GET /?IGCQSNG=BNKSM HTTP/1.1" 200 199267 "http://engadget.search.aol.com/search?q=POZWPGSTV" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; .NET CLR 2.0.50727; InfoPath.2)"
192.168.1.10 - - [17/May/2013:16:37:36 +0800] "GET /?HUL=BMZAQXXXF HTTP/1.1" 200 199267 "http://www.usatoday.com/search/results?q=KUQNRADOUP" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; .NET CLR 2.0.50727; InfoPath.2)"
192.168.1.10 - - [17/May/2013:16:37:36 +0800] "GET /?ZWOWYGEZ=PBEAVXZF HTTP/1.1" 200 199271 "http://engadget.search.aol.com/search?q=FXWHN" "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)"

我的測試伺服器(CentOS 6.4 64位元)配置了Varnish,但正如工具所說,它繞過了Varnish的快取。

我可以安裝fail2ban,但是我應該如何為這種請求定義正規表示式?或者有沒有辦法設定 Nginx 來防止這種攻擊?也許重寫規則什麼的?

答案1

我剛剛偶然發現了這個帖子,發現它有 2 票反對。不管怎樣,我只是想發布我為阻止 HULK 請求所做的事情。

/etc/nginx/conf.d/default.conf(或類似)。我在區塊內添加了以下內容server

if ($args ~* "(.{1,})=(.{1,})" ){
        rewrite ^/$ /444_rewrite?;
}
location  /444_rewrite {
        return 444;
}

它能做什麼? 由於該網站使用友善的 URL,並且沒有一個網站 URL 以 和 開頭?=因此我可以將所有這些奇怪的 GET 請求重定向到(.{1,})=(.{1,})444 =

相關內容