Prevention of brute force attacks:
There are many tools and strategies that will help you with this, and which are completely dependent on your server implementation and requirements.
Without the use of a firewall, IDS, or other network management tools, you will not be able to stop DDOS and also refuse to service your application. However, you can change your application to make brute force attacks much more difficult.
The standard way to do this is to implement blocking or progressive delay . Blocking prohibits the IP address from making a login request for X minutes if they cannot log in N times. Progressive delay adds a large and large delay for processing each failed login request.
If you use Tomcat authentication system (i.e. you have the <login-constraint> element in your webapp configuration), you should use Tomcat LockoutRealm , which makes it easy to put IP addresses in a lock as soon as they make a lot of failed requests.
If you are not using the Tomcat authentication system, you will need to post additional information about what you are using to get more specific information.
Finally, you can simply increase the length of your API keys. 64 bits seem to be an insurmountable huge number of keys to search, but its insufficient weight by modern standards. A number of factors can help make it much less secure than you expect:
- A botnet (or other large network) can make tens of thousands of attempts per second if you do not have protection.
- Depending on how you generate your keys and collect entropy, your actual key space may be much smaller.
- As the number of valid keys increases, the number of keys you need to try to find a real (at least theoretically) drop sharply.
Increasing the length of the API key to 128 (or 256 or 512) will not be expensive, and you will significantly increase the search space (and therefore complexity) of any brute-force attack.
Mitigation of DDOS attacks:
However, to mitigate DDOS attacks, you need to do a little work. DDOS attacks are tough to defend against them and especially hard if you do not control the network your server is running on.
As the saying goes, there are several server-side actions you can do:
- Install and configure a web application firewall, such as mod_security , to reject incoming connections that violate the rules that you define.
- Setting up an IDS system, such as Snort , to detect when a DDOS attack occurs and take the first steps to eliminate it
- See the @Martin Muller post for another great option, fail2ban
- Create your own Tomcat
Valve , as described here , to reject incoming requests from their User-Agents (or any other criteria) as the last line of defense.
In the end, however, you can do this to stop the DDOS attack for free. A server has only so much memory, so many processor cycles, and so much network bandwidth; with enough incoming connections, even the most efficient firewall will not make you refuse. You can better attack DDOS attacks if you invest in a higher bandwidth Internet connection and more servers, or if you deploy your application on Amazon Web Services , or if you bought one of many products to reduce consumer demand and DDOS Enterprise ( @SDude has some excellent recommendations in his post ). None of these options are cheap, fast, or easy, but they are affordable.
Bottom line:
If you rely on your application code to mitigate DDOS, you've already lost