AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 656093
Accepted
Cha0s
Cha0s
Asked: 2015-01-04 11:13:48 +0800 CST2015-01-04 11:13:48 +0800 CST 2015-01-04 11:13:48 +0800 CST

mod_security 通过 http-host 标头阻止请求

  • 772

最近几天,我注意到一些服务器受到未知请求的冲击。

它们中的大多数如下所示:

60.246.*.* - - [03/Jan/2015:20:59:16 +0200] "GET /announce.php?info_hash=%80%85%8e%9bu%cfJ.%85%82%e9%25%bf%8e%9e%d7%bf%c5%b0%12&peer_id=-UT3420-v%8bN%aa%60%60%fd%5d%d1%b0Ux&port=15411&uploaded=48588531&downloaded=0&left=0&corrupt=0&key=9E124668&numwant=200&compact=1&no_peer_id=1 HTTP/1.1" 200 -

经过一些记录和搜索后,我发现一些中国 ISP(根据 whatsmydns.net 的结果可能是 CERNET)和一些土耳其 ISP(可能是 TTNET)响应 dns 查询,例如a.tracker.thepiratebay.org使用与 piratebay 无关的各种 IP或种子。换句话说,他们似乎出于某种奇怪的原因进行了某种 DNS 缓存中毒。

因此,这些国家/地区的数百个(如果不是数千个)bittorrent 客户端向我的网络服务器发出大量“通知”,这几乎导致 DDoS 攻击填满了所有 Apache 的连接。

目前我完全屏蔽了中国和土耳其,它确实有效,但我想找到一种更好的方法来屏蔽这些请求。

我正在考虑使用基于 HTTP Host 标头的 mod_security 阻止这些请求。

所有这些请求都包含一个 HTTP Host 标头,例如a.tracker.thepiratebay.org(或 thepiratebay.org 域的许多其他子域)。

这是通过 PHP$_SERVER变量转储的请求标头。

DOCUMENT_ROOT: /usr/local/apache/htdocs
GATEWAY_INTERFACE: CGI/1.1
HTTP_ACCEPT_ENCODING: gzip
HTTP_CONNECTION: Close
HTTP_HOST: a.tracker.thepiratebay.org
HTTP_USER_AGENT: uTorrent/342(109415286)(35702)
PATH: /bin:/usr/bin
QUERY_STRING: info_hash=%80%85%8e%9bu%cfJ.%85%82%e9%25%bf%8e%9e%d7%bf%c5%b0%12&peer_id=-UT3420-v%8bN%aa%60%60%fd%5d%d1%b0Ux&port=15411&uploaded=48588531&downloaded=0&left=0&corrupt=0&key=9E124668&numwant=200&compact=1&no_peer_id=1
REDIRECT_STATUS: 200
REMOTE_ADDR: 60.246.*.*
REMOTE_PORT: 3445
REQUEST_METHOD: GET
REQUEST_URI: /announce.php?info_hash=%80%85%8e%9bu%cfJ.%85%82%e9%25%bf%8e%9e%d7%bf%c5%b0%12&peer_id=-UT3420-v%8bN%aa%60%60%fd%5d%d1%b0Ux&port=15411&uploaded=48588531&downloaded=0&left=0&corrupt=0&key=9E124668&numwant=200&compact=1&no_peer_id=1
SCRIPT_FILENAME: /usr/local/apache/htdocs/announce.php
SCRIPT_NAME: /announce.php
SERVER_ADDR: *.*.*.*
SERVER_ADMIN: *@*.*
SERVER_NAME: a.tracker.thepiratebay.org
SERVER_PORT: 80
SERVER_PROTOCOL: HTTP/1.1
SERVER_SIGNATURE: 
SERVER_SOFTWARE: Apache/2.2.29 (Unix) mod_ssl/2.2.29 OpenSSL/1.0.1e-fips mod_bwlimited/1.4 mod_perl/2.0.8 Perl/v5.10.1
UNIQUE_ID: VKg8BJBMIPQAD01XYzgAAAAD
PHP_SELF: /announce.php
REQUEST_TIME_FLOAT: 1420311556.43
REQUEST_TIME: 1420311556
argv: Array
argc: 1

所以我的问题是,如何根据请求域(HTTP 主机标头)阻止对 Apache 的传入请求?请记住,请求在各种 URL 上,而不仅仅是 /announce.php,因此通过 URL 阻止是没有用的。

这种方法是否可行,或者它会导致过多的负载,我应该在它们到达 Apache 之前继续丢弃这些请求?

更新:

事实证明,这个问题已经影响了全球许多国家的许多人。
有很多关于它的报告和博客文章以及阻止这种流量的各种解决方案。

我收集了一些报告来帮助任何来这里寻找解决方案的人来阻止这个。

神秘的误导中文流量:如何找出一个HTTP请求使用的DNS服务器?
奇怪的 Bittorrent 登录我的服务器
http://blog.devops.co.il/post/108740168304/torrent-ddos-attack
https://www.webhostingtalk.com/showthread.php?t=1443734
http://torrentfreak。 com/zombie-pirate-bay-tracker-fuels-chinese-ddos-attacks-150124/
https://isc.sans.edu/forums/diary/Are+You+Piratebay+thepiratebayorg+Resolving+to+Various+Hosts/ 19175/
http://furbo.org/2015/01/22/fear-china/
http://www.jwz.org/blog/2015/01/chinese-bittorrent-the-gift-that-keeps-on-给予/

apache-2.2
  • 5 5 个回答
  • 16974 Views

5 个回答

  • Voted
  1. Best Answer
    user262546
    2015-01-06T23:26:03+08:002015-01-06T23:26:03+08:00

    这里同样的问题。我正在使用 mod_security 来阻止用户代理

    SecRule REQUEST_HEADERS:User-Agent "Bittorrent" "id:10000002,rev:1,severity:2,log,msg:'Bittorrent Hit Detected'"
    

    在您确认它正在工作后,我会将日志更改为 nolog,以避免填满您的日志文件

    SecRule REQUEST_HEADERS:User-Agent "Bittorrent" "id:10000002,rev:1,severity:2,nolog,msg:'Bittorrent Hit Detected'"
    
    • 7
  2. Dan Armstrong
    2015-01-06T20:46:25+08:002015-01-06T20:46:25+08:00

    我们的客户网站之一遇到了完全相同的问题。我在他们的顶部附近添加了以下内容:

    # Drop Bittorrent agent 2015-01-05 before redirect to https
    <IfModule mod_rewrite.c>
        RewriteEngine on
        # RewriteCond %{HTTP_USER_AGENT} =Bittorrent
        RewriteRule ^/announce$ - [F]
        RewriteRule ^/announce\.php$ - [F]
    </IfModule>
    

    注释掉的 RewriteCond 可以取消注释以仅阻止特定的用户代理。但他们在announce 或announce.php 中没有内容,所以我们将其全部屏蔽。

    • 5
  3. Evgeny
    2015-01-22T08:37:45+08:002015-01-22T08:37:45+08:00

    我写了一篇关于如何正确告诉 BitTorrent 客户端离开并且永远不会回来的博客文章,类似于 Dan 所做的,但使用的是 nginx。

    server {
        location /announc {
            access_log off;
            error_log off;
            default_type text/plain;
            return 410 "d14:failure reason13:not a tracker8:retry in5:nevere";
        }
    }
    

    /announceTorrent 跟踪器(通常)有一个以or开头的标准 URL /scrape,所以我不会这么快就放弃按 URL 过滤。有用。

    完整的帖子位于 - http://dvps.me/ddos-attack-by-torrent

    • 5
  4. Franci
    2015-01-25T09:18:22+08:002015-01-25T09:18:22+08:00

    我现在遇到了同样的问题,让洪流跟踪器指向我的服务器。在过去的几天里,我对 iptables 进行了试验,检查了请求的标头和模式,并将其缩小到几个 iptables 规则,这些规则过滤了几乎所有来自亚洲(中国、马来西亚、日本和香港)。

    以下是规则。希望它可以帮助某人。

    iptables -I INPUT -p tcp --dport 80 -m string --algo bm --string "Bittorrent" --to 1000 -j REJECT
    iptables -I INPUT -p tcp --dport 80 -m string --algo bm --string "spider" --to 1000 -j REJECT
    iptables -I INPUT -p tcp --dport 80 -m string --algo bm --string "announce" --to 1000 -j REJECT
    iptables -I INPUT -p tcp --dport 80 -m string --algo bm --string "deviantart" --to 1000 -j REJECT
    iptables -I INPUT -p tcp --dport 80 -m string --algo bm --string "Bittorrent" --to 1000 -j REJECT
    iptables -I INPUT -p tcp --dport 80 -m string --algo bm --string "baidu" --to 1000 -j REJECT
    iptables -I INPUT -p tcp --dport 80 -m string --algo bm --string "Baiduspider" --to 1000 -j REJECT
    
    • 5
  5. user3601800
    2015-02-05T23:18:34+08:002015-02-05T23:18:34+08:00

    我从 http://www.wizcrafts.net/chinese-blocklist.html中获取了中文 IP 范围, 并在我的 csf 防火墙中阻止了它们,这是您想要复制并粘贴到 csf 拒绝 ip 列表中的范围:

    #china blocks start
    1.80.0.0/13
    1.92.0.0/14
    1.192.0.0/13
    1.202.0.0/15
    1.204.0.0/14
    14.144.0.0/12
    14.208.0.0/12
    23.80.54.0/24
    23.104.141.0/24
    23.105.14.0/24
    27.8.0.0/13
    27.16.0.0/12
    27.36.0.0/14
    27.40.0.0/13
    27.50.128.0/17
    27.54.192.0/18
    27.106.128.0/18
    27.115.0.0/17
    27.148.0.0/14
    27.152.0.0/13
    27.184.0.0/13
    36.32.0.0/14
    36.248.0.0/14
    42.96.128.0/17
    42.120.0.0/15
    58.16.0.0/15
    58.20.0.0/16
    58.21.0.0/16
    58.22.0.0/15
    58.34.0.0/16
    58.37.0.0/16
    58.38.0.0/16
    58.40.0.0/16
    58.42.0.0/16
    58.44.0.0/14
    58.48.0.0/13
    58.56.0.0/15
    58.58.0.0/16
    58.59.0.0/17
    58.60.0.0/14
    58.68.128.0/17
    58.82.0.0/15
    58.100.0.0/15
    58.208.0.0/12
    58.242.0.0/15
    58.246.0.0/15
    58.248.0.0/13
    59.32.0.0/12
    59.51.0.0/16
    59.52.0.0/14
    59.56.0.0/13
    59.72.0.0/16
    59.108.0.0/15
    59.172.0.0/14
    60.0.0.0/13
    60.11.0.0/16
    60.12.0.0/16
    60.24.0.0/13
    60.160.0.0/11
    60.194.0.0/15
    60.208.0.0/13
    60.216.0.0/15
    60.220.0.0/14
    61.4.64.0/20
    61.4.80.0/22
    61.4.176.0/20
    61.48.0.0/13
    61.128.0.0/10
    61.135.0.0/16
    61.136.0.0/18
    61.139.0.0/16
    61.145.73.208/28
    61.147.0.0/16
    61.150.0.0/16
    61.152.0.0/16
    61.154.0.0/16
    61.160.0.0/16
    61.162.0.0/15
    61.164.0.0/16
    61.175.0.0/16
    61.177.0.0/16
    61.179.0.0/16
    61.183.0.0/16
    61.184.0.0/16
    61.185.219.232/29
    61.187.0.0/16
    61.188.0.0/16
    61.232.0.0/14
    61.236.0.0/15
    61.240.0.0/14
    101.64.0.0/13
    101.72.0.0/14
    101.76.0.0/15
    101.80.0.0/12
    103.253.4.0/22
    106.112.0.0/13
    110.6.0.0/15
    110.51.0.0/16
    110.52.0.0/15
    110.80.0.0/13
    110.88.0.0/14
    110.96.0.0/11
    110.173.0.0/19
    110.173.32.0/20
    110.173.64.0/18
    110.192.0.0/11
    110.240.0.0/12
    111.0.0.0/10
    111.72.0.0/13
    111.121.0.0/16
    111.128.0.0/11
    111.160.0.0/13
    111.172.0.0/14
    111.176.0.0/13
    111.228.0.0/14
    112.0.0.0/10
    112.64.0.0/14
    112.80.0.0/12
    112.100.0.0/14
    112.111.0.0/16
    112.122.0.0/15
    112.224.0.0/11
    113.0.0.0/13
    113.8.0.0/15
    113.12.0.0/14
    113.16.0.0/15
    113.18.0.0/16
    113.62.0.0/15
    113.64.0.0/10
    113.128.0.0/15
    113.136.0.0/13
    113.194.0.0/15
    113.204.0.0/14
    114.28.0.0/16
    114.80.0.0/12
    114.96.0.0/13
    114.104.0.0/14
    114.112.0.0/14
    112.109.128.0/17
    114.216.0.0/13
    114.224.0.0/11
    115.24.0.0/15
    115.28.0.0/15
    115.32.0.0/14
    115.48.0.0/12
    115.84.0.0/18
    115.100.0.0/15
    115.148.0.0/14
    115.152.0.0/15
    115.168.0.0/14
    115.212.0.0/16
    115.230.0.0/16
    115.236.96.0/23
    115.236.136.0/22
    115.239.228.0/22
    116.1.0.0/16
    116.2.0.0/15
    116.4.0.0/14
    116.8.0.0/14
    116.16.0.0/12
    116.52.0.0/14
    116.76.0.0/15
    116.90.80.0/20
    116.112.0.0/14
    116.128.0.0/10
    116.204.0.0/15
    116.208.0.0/14
    116.224.0.0/12
    116.254.128.0/18
    117.8.0.0/13
    117.21.0.0/16
    117.22.0.0/15
    117.24.0.0/13
    117.32.0.0/13
    117.40.0.0/14
    117.44.0.0/15
    117.60.0.0/14
    117.79.224.0/20
    117.80.0.0/12
    117.136.0.0/13
    118.26.0.0/16
    118.72.0.0/13
    118.112.0.0/13
    118.120.0.0/14
    118.132.0.0/14
    118.144.0.0/14
    118.180.0.0/14
    118.186.0.0/15
    118.192.0.0/15
    118.248.0.0/13
    119.0.0.0/13
    119.8.0.0/16
    119.10.0.0/17
    119.18.192.0/20
    119.36.0.0/16
    119.57.0.0/16
    119.60.0.0/16
    119.88.0.0/14
    119.96.0.0/13
    119.112.0.0/13
    119.120.0.0/13
    119.128.0.0/12
    119.144.0.0/14
    119.164.0.0/14
    119.176.0.0/12
    119.233.0.0/16
    120.0.0.0/12
    120.24.0.0/14
    120.32.0.0/13
    120.40.0.0/14
    120.68.0.0/14
    120.80.0.0/13
    120.192.0.0/10
    121.0.16.0/20
    121.8.0.0/13
    121.16.0.0/12
    121.32.0.0/14
    121.60.0.0/14
    121.76.0.0/15
    121.196.0.0/14
    121.204.0.0/14
    121.224.0.0/12
    122.10.128.0/17
    122.51.128.0/17
    122.64.0.0/11
    122.119.0.0/16
    122.136.0.0/13
    122.156.0.0/14
    122.188.0.0/14
    122.192.0.0/14
    122.198.0.0/16
    122.200.64.0/18
    122.224.0.0/12
    123.4.0.0/14
    123.8.0.0/13
    123.52.0.0/14
    123.64.0.0/11
    123.97.128.0/17
    123.100.0.0/19
    123.112.0.0/12
    123.128.0.0/13
    123.138.0.0/15
    123.150.0.0/15
    123.152.0.0/13
    123.164.0.0/14
    123.180.0.0/14
    123.184.0.0/14
    123.196.0.0/15
    123.232.0.0/14
    123.249.0.0/16
    124.42.64.0/18
    124.64.0.0/15
    124.67.0.0/16
    124.73.0.0/16
    124.114.0.0/15
    124.126.0.0/15
    124.128.0.0/13
    124.160.0.0/15
    124.162.0.0/16
    124.163.0.0/16
    124.192.0.0/15
    124.200.0.0/13
    124.226.0.0/15
    124.228.0.0/14
    124.236.0.0/14
    124.240.0.0/17
    124.240.128.0/18
    124.248.0.0/17
    125.36.0.0/14
    125.40.0.0/13
    125.64.0.0/12
    125.79.0.0/16
    125.80.0.0/13
    125.88.0.0/13
    125.104.0.0/13
    125.112.0.0/12
    125.210.0.0/15
    140.224.0.0/16
    140.237.0.0/16
    140.246.0.0/16
    140.249.0.0/16
    142.4.117.0/30
    159.226.0.0/16
    171.34.0.0/15
    171.36.0.0/14
    171.40.0.0/13
    175.0.0.0/12
    175.16.0.0/13
    175.24.0.0/14
    175.30.0.0/15
    175.42.0.0/15
    175.44.0.0/16
    175.46.0.0/15
    175.48.0.0/12
    175.64.0.0/11
    175.102.0.0/16
    175.106.128.0/17
    175.146.0.0/15
    175.148.0.0/14
    175.152.0.0/14
    175.160.0.0/12
    175.178.0.0/16
    175.184.128.0/18
    175.185.0.0/16
    175.186.0.0/15
    175.188.0.0/14
    180.76.0.0/16
    180.96.0.0/11
    180.136.0.0/13
    180.152.0.0/13
    180.208.0.0/15
    182.18.0.0/17
    182.32.0.0/12
    182.88.0.0/14
    182.112.0.0/12
    182.128.0.0/12
    183.0.0.0/10
    183.64.0.0/13
    183.129.0.0/16
    183.148.0.0/16
    183.160.0.0/12
    183.184.0.0/13
    183.192.0.0/11
    192.34.109.224/28
    192.74.224.0/19
    198.2.203.64/28
    198.2.212.160/28
    202.43.144.0/22
    202.46.32.0/19
    202.66.0.0/16
    202.75.208.0/20
    202.96.0.0/12
    202.111.160.0/19
    202.112.0.0/14
    202.117.0.0/16
    202.165.176.0/20
    202.196.80.0/20
    203.69.0.0/16
    203.86.0.0/18
    203.86.64.0/19
    203.93.0.0/16
    203.169.160.0/19
    203.171.224.0/20
    210.5.0.0/19
    210.14.128.0/19
    210.21.0.0/16
    210.32.0.0/14
    210.51.0.0/16
    210.52.0.0/15
    210.77.0.0/16
    210.192.96.0/19
    211.76.96.0/20
    211.78.208.0/20
    211.86.144.0/20
    211.90.0.0/15
    211.92.0.0/14
    211.96.0.0/13
    211.136.0.0/13
    211.144.12.0/22
    211.144.96.0/19
    211.144.160.0/20
    211.147.0.0/16
    211.152.14.0/24
    211.154.64.0/19
    211.154.128.0/19
    211.155.24.0/22
    211.157.32.0/19
    211.160.0.0/13
    211.233.70.0/24
    218.0.0.0/11
    218.56.0.0/13
    218.64.0.0/11
    218.84.0.0/14
    218.88.0.0/13
    218.96.0.0/14
    218.102.0.0/16
    218.104.0.0/14
    218.108.0.0/15
    218.194.80.0/20
    218.200.0.0/13
    218.240.0.0/13
    219.128.0.0/11
    219.154.0.0/15
    219.223.192.0/18
    219.232.0.0/16
    219.234.80.0/20
    219.235.0.0/16
    220.112.0.0/16
    220.154.0.0/15
    220.160.0.0/11
    220.181.0.0/16
    220.191.0.0/16
    220.192.0.0/12
    220.228.70.0/24
    220.242.0.0/15
    220.248.0.0/14
    220.250.0.0/19
    220.252.0.0/16
    221.0.0.0/12
    221.122.0.0/15
    221.176.0.0/13
    221.192.0.0/14
    221.200.0.0/14
    221.204.0.0/15
    221.206.0.0/16
    221.207.0.0/16
    221.208.0.0/12
    221.212.0.0/15
    221.214.0.0/15
    221.216.0.0/13
    221.224.0.0/13
    221.228.0.0/14
    221.232.0.0/13
    222.32.0.0/11
    222.64.0.0/12
    222.80.0.0/12
    222.132.0.0/14
    222.136.0.0/13
    222.168.0.0/13
    222.172.222.0/24
    222.176.0.0/13
    222.184.0.0/13
    222.200.0.0/16
    222.208.0.0/13
    222.219.0.0/16
    222.220.0.0/15
    222.240.0.0/13
    223.4.0.0/14
    223.64.0.0/11
    223.144.0.0/12
    223.240.0.0/13
    #china blocks end
    
    • 0

相关问题

  • Apache Django Mod_Wsgi - 自动重新加载应用程序

  • Apache:对多个虚拟主机使用相同的目录指令

  • Apache 上的子域不工作 - 找不到服务器

  • PHP 作为 CGI 还是 Apache 模块?

  • 避免将某些丢失的文件记录到 Apache2 错误日志中

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve