Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

I am wondering how do you mitigate a ddos attack which is coming from a botnet and hitting random URLs on a website.

If there was a consistent URL it was hitting then it would be fairly simple, and wouldn't matter that it is coming from random IPs.

How do you prevent an attack which is random IPs and URLs?

share|improve this question
If the URLs are random, they are probably resulting in HTTP 404, is this correct? You imply that you know how to block a consistent URL, do you? If so, do you mind letting us know what tool you would use? This would give us some context as to what tools you currently have at your disposal. –  George Bailey Feb 6 '13 at 0:25
All I have at this point is apache access logs. The next part is determining a solution to prevent it from happening, which will have to be a software solution since it's in Amazon's cloud. –  Zippy Zeppoli Feb 6 '13 at 0:26
Do you have a performance or bandwidth usage problem yet? Is your system responding with 404 pages, or are the bots accessing real stuff? How random are the URLs, is it complete gibberish, or only partial gibberish? Do you have access to the user-agent header? Would you be interested in a solution that allows the bot to get through for the first few hits, and then completely blocks the IP for limited time (to reduce the problem, without completely stopping it.)? I ask all these questions because they could contribute significantly to giving you a better answer. Please answer what you know. –  George Bailey Feb 6 '13 at 0:32
Forgive me if my questions seem obvious. I personally ask theoretical questions all the time on this site. So, there is no point in asking for details if it is theoretical question, and there is no point in avoiding specifics if the problem is real. Further, please forgive my long list of questions. You have not stated the severity of your problem yet, and you have not posted sample access logs. While we might still make a good answer based on what you have stated, the best possible answer will come from having specifics. –  George Bailey Feb 6 '13 at 0:39
@GeorgeBailey Bottleneck is CPU at the moment. They are using a user agent header that resembles a real browser. I appreciate your help and am happy to answer any questions. –  Zippy Zeppoli Feb 6 '13 at 2:03
add comment

6 Answers

up vote 8 down vote accepted

The tricky part is to distinguish between requests from the botnet, and requests from humans who actually want to read the pages. There is no 100% reliable way to do that in all generality, because some DDoS tools are quite good at imitating humans, and also because most humans appear to be quite good at behaving like mindless drones. Nevertheless, that's the gist of the issue: you must find a distinguishing characteristic between botnet requests and non-botnet requests (and if you find one, next month's botnet will have adapted -- this is an endless race).

One possible defence is to require a Proof of Work from clients. Embed in your site some Javascript code which performs a relatively complex computation, the output of which being embedded in the next request from that client. If done properly, then you could make sure that the botnet burned at least some substantial amount of CPU in the process; the idea being that if DDoSing your server is too expensive, then the botnet master will direct his wrath to another target. After all, he is a businessman...

I have not seen PoW deployed in a Web context, and the Javascript idiosyncrasies may make it difficult to do (a browser with a Javascript interpretor will not make that much "work" per second), but the concept seems sound.

share|improve this answer
its a pain in the ass for the user also. but that will work. –  Zippy Zeppoli Feb 6 '13 at 1:25
It only needs to be implemented for the duration of the attack. Make sure it's something you can easily remove when the attack is over. –  deed02392 Feb 6 '13 at 12:16
Proof of Work would work against DoS but I don't see how it can even stop DDoS. All it takes is several requests from each zombie to bring a server down. –  Pacerier Aug 16 '13 at 4:38
How will it stand against replay attacks? –  thefourtheye Apr 16 at 4:12
add comment

Do a little bit of work to figure out if there are commonalities - common headers that uniquely identify the bots, etc.. Don't forget to look for things the bots don't have - a number leave out fields like Host and Accept-Encoding because they concentrate on the minimum HTTP request to maximise their effectiveness.

You're either going to hit a bandwidth or a compute cap - determine which you're up against because you're likely able to trade one off against the other.

From there, you have a few options. I'm going to assume that DNS changes aren't quick enough, you're using hosting that makes changing IP hard and that load balancers, etc. are out of the price range (otherwise, you're likely to know your coping options):

  1. Talk to your ISP; they may have mitigation options they can enable for you. If you can give them a signature, they may be able to simply block it. They may be able to temporarily increase your available bandwidth to simply absorb the DDoS.
  2. Set a cookie on every legitimate page. Check for the cookie on the 404 page. If you don't see that cookie, blacklist (if you're at a compute cap) or blackhole (if it's bandwidth you're running out of) the IP.
  3. Blacklist whole countries that you've never seen in your logs before.
  4. Proof Of Work is an idea; it could be very simple - work out the time of day in JavaScript in UNIX time and set a cookie with that value. Check on every page for that cookie, if you're within 600 seconds, reset cookie to current time. If you're not, execute while(1); in your backend at the very end of your page. Minimal user impact (page functional, but seems to load for some reason forever).
  5. Optimise your pages. If you can, switch over to a totally static HTML setup temporarily (it's pretty good practice to have a switch that does this anyway on a large site, in case of sudden popularity). This may well bring your compute time down enough so the DDoS doesn't toast the server. This trades off compute time in favour of bandwidth, so will increase your throughput.
  6. Do the opposite of 5 - if you have plenty of compute time available, slow down your 404 response. Add a 60s sleep into whatever you're using to generate the page, keep the socket open as long as you can. This trades off bandwidth in favour of compute time, so will decrease your bandwidth use and drive up load.
share|improve this answer
add comment

DDoS attacks primarily succeed by exhausting your bandwidth, not by avoiding detection by your application or infrastructure. The best way to defeat DDoS attacks, therefore, is to catch them upstream, and many ISPs offer DDoS mitigation products specifically designed for this.

share|improve this answer
Besides being upstream of the bandwidth chokepoint, the other advantage of the carrier services include: (1) they have a preestablished blacklist from analyzing the bots and controllers across their entire network (and pay for threat intel services), (2) they can 'afford' fancier detection and scrubbing algorithms because it's a shared service –  Duncan Feb 8 '13 at 11:38
What do you mean by catch them upstream? –  Pacerier Aug 16 '13 at 4:39
add comment

If you run your own DNS, "views" (or split-horizon DNS) can be very useful as a first defence, you really need to have a whitelist though, which is where your historic web server logs come in. You could also build a blacklist, if you can recognise the problem clients. The suspect or non-whitelisted clients get (or somewhere unroutable) to talk to, everyone else gets the real IP address(es).

The next step is make sure you have read these:

Depending on your platform you may also be able to optimise your system (SYN cookies, HTTP accept filtering, Apache's mod_reqtimeout or 3rd party options like mod_security).

share|improve this answer
add comment

It would be better if you could use a hardware firewall. Otherwise, you will need a software option like this http://blog.solidshellsecurity.com/2012/05/21/barf-block-apache-request-flood-script-block-ddos-based-script/

share|improve this answer
add comment

A few people have suggested a Javascript proof-of-work scheme.

I've actually seen a proof-of-work scheme in the wild. The British supermarket Sainsbury's use one on www.sainsburys.co.uk.

The big problem with it is that hackers are free to use whatever tools they like, so they can write a cracking tool that runs at native speed. Meanwhile, legitimate users may well be stuck using an outdated version of IE.

On the Sainsbury's site, native crackers were around 100x faster than IE6, so it's not much of an advantage.

There's some more info on this blog post.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.