The last few days I noticed some servers being hammered with unknown requests.

Most of them are like the following:

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 -

After a bit of logging and searching I found out that some Chinese ISP (probably CERNET according to the results of whatsmydns.net ) and some Turkish ISP (probably TTNET) respond to dns queries such as a.tracker.thepiratebay.org with various IPs that have nothing to do with piratebay or torrents. In other words they seem to do some kind of DNS Cache Poisoning for some bizarre reason.

So hundreds (if not thousands) of bittorrent clients on those countries make tons of 'announces' to my webservers which result pretty much in a DDoS attack filling up all Apache's connections.

At the moment I blocked China and Turkey altogether and it does the job, but I would like to find a better way to block those requests.

I was thinking of blocking those requests with mod_security based on the HTTP Host header.

All those requests include an HTTP Host header like a.tracker.thepiratebay.org (or many other subdomains of thepiratebay.org domain).

Here's a dump of the request headers via PHP's $_SERVER variable.

DOCUMENT_ROOT: /usr/local/apache/htdocs
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
REMOTE_ADDR: 60.246.*.*
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_NAME: a.tracker.thepiratebay.org
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
PHP_SELF: /announce.php
REQUEST_TIME_FLOAT: 1420311556.43
REQUEST_TIME: 1420311556
argv: Array
argc: 1

So my question is, how can I block incoming requests to Apache based on the request domain (HTTP Host header) ? Keep in mind that the requests are on various URLs not just /announce.php so blocking by URL is not useful.

Also is that approach viable or will it cause too much load and I should keep dropping those requests before they even reach Apache?


It turns out this issue has affected many people in many countries around the globe.
There have been numerous reports and blogposts about it and various solutions to block this traffic.

I've collected some of the reports to help anyone coming here searching on a solution to block this.

Mysterious misdirected Chinese traffic : How can I find out what DNS server an HTTP request used?
Strange Bittorrent Log On My Server

  • 1
    I'm seeing a similar issue to this, I've blocked the requests but I was wondering how you'd figured out which ISPs were returning the incorrect IP addresses? I'm interested to find out where the requests are coming from so that seems like a good starting point
    – pogo
    Jan 9, 2015 at 10:31
  • According to whatsmydns.net and other glbal dns propagation checkers, CERNET and CPIP at China and TTNET at Turkey respond to queries on various subdomains of thepiratebay.org to various IPs when that domain does not resolve on any other ISP around the planet.
    – Cha0s
    Jan 9, 2015 at 12:45
  • 2
    I'm getting the exact same thing and it started about the same time you noticed it. facebook, bittorrent, porn sites. but most notably this constant pirate bay announce. serverfault.com/questions/658433/… I'm using nginx and I've returned 444 if the host doesn't match. Jan 9, 2015 at 16:07
  • the requests to announce have reduced by quite a bit. maybe it was a temporary DNS misconfiguration. are you still seeing traffic ? Jan 13, 2015 at 11:32
  • 2
    To be honest I ended up blocking China at the firewall level after all because even with mod_security they would fill up all Apache's connections. So I haven't noticed if the requests have been reduced.
    – Cha0s
    Jan 13, 2015 at 14:03

5 Answers 5


Same issue here. I am using mod_security to block the user-agent

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

I would change the log to nolog after you verify it is working to avoid filling up your log file

SecRule REQUEST_HEADERS:User-Agent "Bittorrent" "id:10000002,rev:1,severity:2,nolog,msg:'Bittorrent Hit Detected'"
  • 1
    While not exactly what I needed, your answer steered me to the right direction so I chose yours as the correct one. I ended up blocking all torrent requests by matching the '?info_hash=' string on the REQUEST_URI. User-Agent wasn't the best approach because the clients use many different bittorrent clients with different UAs. The final mod_security rule I ended up with is: SecRule REQUEST_URI "\?info_hash\=" "id:10000002,rev:1,severity:2,nolog,msg:'Torrent Announce Hit Detected'"
    – Cha0s
    Jan 6, 2015 at 13:24
  • Try to dig a.tracker.thepiratebay.org from any DNS server in this list public-dns.tk/nameserver/cn.html and on each request there is a different answer. Same for tracker.thepiratebay.org which also appeared in our Host: headers. There is a post about it on viewdns.info/research/… with some additional sites. Trying to reverse some of the returned addresses using viewdns.info/reverseip shows that its pretty much random. Jan 22, 2015 at 1:33

We are experiencing exactly the same issue with one of our client's sites. I added the following near the top of their :

# 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]

The commented-out RewriteCond can be uncommented to only block a specific user agent. But they have no content at announce or announce.php so we just blocked it all.

  • Thanks, but I needed a solution using mod_security and not mod_rewrite.
    – Cha0s
    Jan 6, 2015 at 13:25
  • see engineering.bittorrent.com/2015/01/29/… for a better way (G/410 instead of F/403, and an explicit ErrorDocument)
    – ysth
    Feb 23, 2015 at 18:17

I'm having the same issue at the moment, having torrent trackers point at my server. I've experimented with iptables for the past couple of days and inspected headers and patterns of the requests and narrowed it down to a couple of iptables rules that filters pretty much all of the recent seemingly malicious traffic from Asia (China,Malaysia,Japan and Hong Kong).

Below are the rules. Hope it helps someone.

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
  • Nice! I didn't think of that! Thanks! :D Did you choose to REJECT instead of DROP for some particular reason? (ie: clients may stop after receiving a REJECT?)
    – Cha0s
    Jan 24, 2015 at 17:21
  • 1
    Yes, REJECT should tell the client to stop requesting that resource though it doesn't seem to be helping in this case. It still filters it out so I'll leave it as REJECT hoping that some clients take a hint. Any way, iptables should perform a lot better than mod_security at this task, so I hope it works well for you.
    – Franci
    Jan 24, 2015 at 18:36
  • Yeap it should! I was blocking all Chinese prefixes. I will try this approach which is better :) I think that the bittorrent clients won't stop retrying even with REJECT. They would see it as 'connection refused' and retry after a while. I believe DROP is a better approach (and uses less resources - it simply drops the packets the moment they get matched without any further processing)
    – Cha0s
    Jan 24, 2015 at 18:43
  • 1
    The difference is quite negligible actually in all but extreme cases, and my hope was to eventually deter the traffic. If it doesn't dial down I'll change it to DROP. I'm very curious as to why or how this came to happen in the first place though. There are some discussions about the Great Firewall of China redirecting to random IPs but I'm pretty sure this is not the case here.
    – Franci
    Jan 24, 2015 at 19:54
  • 1
    +1 Nice one. We're going with --string "GET /announce" though, to cover the actual request. Jan 27, 2015 at 12:38

I wrote a blog post about how to properly tell BitTorrent clients to go away and never come back, similar to what Dan did, but using 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";

Torrent trackers (usually) have a standard URL that begins with /announce or /scrape, so I wouldn't dismiss filtering by URL so quickly. It works.

The full post is at - http://dvps.me/ddos-attack-by-torrent

  • 1
    Interesting read. Thanks for sharing :) But I believe the attack was induced by means of DNS Cache Poisoning since CERNET in China responds to TPB domains with random and non-chinese IPs. AFAIK PEX is for sharing peers, not trackers. Can you elaborate more on that or provide some documentation?
    – Cha0s
    Jan 21, 2015 at 17:04
  • There is an extension for sharing trackers described here bittorrent.org/beps/bep_0028.html. But you are correct in that the 'Host:' header for all of these requests is a.tracker.thepiratebay.org or tracker.thepiratebay.org which might be or not be the actual target of these clients. It can also be fake clients just masking themselves as Chinese bittorents :) Jan 21, 2015 at 17:25
  • 1
    the bittorrent folks suggest 410 instead of 404: engineering.bittorrent.com/2015/01/29/…
    – ysth
    Feb 23, 2015 at 18:19

i took the Chinese ip ranges from: http://www.wizcrafts.net/chinese-blocklist.html and blocked them in my csf firewall, here is the ranges in case you want to copy and paste into your deny ip list of csf:

#china blocks start
#china blocks end
  • Or you can simply add CC_DENY = "CN" on /etc/csf/csf.conf and it will automatically find the Chinese prefixes based on Maxmind's GeoIP database.
    – Cha0s
    Feb 5, 2015 at 11:37
  • thanks, but I'm not sure which way consumes less server resources like CPU usage, the CC_DENY or the direct IP blocking. I would say that direct IP blocking is better. Feb 5, 2015 at 16:38
  • I don't see any difference. Once the iptables rules are loaded (one way or another - the rules are the same essentially) the load on the system will be the same. The only difference is that your list is static (so you'll have to manually keep it up to date) while the list from the GeoIP database will be updated from time to time automatically to reflect any new or obsolete prefixes per country code. Either way when you block many prefixes with iptables, you will have an extra load on the system. The load comes from iptables themselves, not from the way you find which prefixes to block.
    – Cha0s
    Feb 5, 2015 at 17:12
  • i have to say that blocking country code CN in the csf didn't work for me, today i have found new IPs from China blocked by mod_security Feb 6, 2015 at 17:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .