As always Im learning the more advanced features of iptables. Lately I have been using the ttl, string, and length matches. Here are some examples:
String Match
Suppose you have a site under a get, cc, or other http attack. Lets say they are hitting GET index.php. Here is what you can do, may be only a temp fix as attacker will change up when he catches on but you can rename index.php, change teh directory index and make a string match like this.
iptables -I INPUT -j DROP -p tcp -s 0.0.0.0/0 -d 0.0.0.0/0 -m string –algo bm –string “index.php”
Make sure oyu put these in the beginning of your rules.
Also I noticed that some bots have a fatal flaw of using double slashes when attacking a site this way. When this happens you dont have to rename anything and can simply block whatever they are requesting with double quotes. Example:
iptables -I INPUT -j DROP -p tcp -s 0.0.0.0/0 -m string –algo bm –string “//trade/?a=forgot_password”
Now as far as the algo arg on these, Im not totally sure but using bm has not failed for me yet.
For the next rules, the way to find out these values is to run a tcpdump as so
tcpdump -nn -vvv host atatckedip
TTL Match
Another flaw some bots have when they attack is they all have the same or similar ttl value in their packets. Now when you do this you need to test and make sure you are not blocking legit packets. First do a tcpdump of the attacked ip, see if you see a pattern in the ttl or if they are all the same or just a few numbers apart. Then make sure your ip is not whitelisted form your firewall. Do a tcpdump but this time grepping your ip as you visit and jump around the attacked site. If you see the same ttl values as the attacking bots most likely using this rule will block legit traffic but if they are different then here goes. For example, you do a dump and all bots have a ttl of 111 you add a rule like this:
iptables -A INPUT -p tcp -s 0.0.0.0/0 -d attackedip -m ttl –ttl 111 -j DROP
Then of course with this as well as any other rule you insert make sure oyu are not blocking legit traffic by testing the site yourself and even have otehrs test it for you.
Length Match
you find out the length of the packets same as you do the ttl, if you notice a patetrn and they are different then the legit packlets you can add a rule like this. You can specify on length or a range of lengths.
iptables -A INPUT -p tcp -d attackedip -m length –length 40:48 -j DROP