Here is a solution. This will not affect people using a proxy. Apache tomcat team does not consider this a vulnerability in tomcat or plan to release a patch. This code will stop other ddos attack methods as well. ps I did not write this.
BLACKLIST=cat /usr/local/AS/etc/blacklist.txt
for i in $BLACKLIST; do
iptables -A INPUT -p tcp -m tcp --dport http -s $i -j DROP
done
-# IPs which will never be refused - partner hosts
WHITELIST=****INSERT YOUR PERMANENT WHITELIST IPS HERE ******
for i in $WHITELIST; do
iptables -A INPUT -p tcp -m tcp --dport http -s $i -j ACCEPT
done
-# don't lower too much - browsers open multiple connections
OVERLIM_NEW=500
-# overall limit for new connections per second
INDILIM_NEW=30
-# limit for individual IP, new connections per second - prevents floods
INDILIM_CURRENT=200
-# limit for individual IP, total connections - prevents overusage
CURRENT_EVAL_INTERVAL=300
-# interval length for IP usage evaluation
iptables -N LIMIT_INDIVIDUAL_NEW
iptables -N LIMIT_INDIVIDUAL_CURRENT
iptables -N LIMIT_OVERALL_NEW
iptables -A INPUT -p tcp --dport 80 -m state --state ESTABLISHED -j LIMIT_INDIVIDUAL_CURRENT
iptables -A INPUT -p tcp --dport 80 --syn -m state --state NEW -j LIMIT_INDIVIDUAL_NEW
iptables -A LIMIT_INDIVIDUAL_CURRENT -m recent --set
iptables -A LIMIT_INDIVIDUAL_CURRENT -p tcp --tcp-flags FIN FIN -m recent --remove
iptables -A LIMIT_INDIVIDUAL_CURRENT -m recent --update --seconds $CURRENT_EVAL_INTERVAL --hitcount $INDILIM_CURRENT -j DROP
iptables -A LIMIT_INDIVIDUAL_CURRENT -j ACCEPT
iptables -A LIMIT_INDIVIDUAL_NEW -m recent --set
iptables -A LIMIT_INDIVIDUAL_NEW -m recent --update --seconds 1 --hitcount $INDILIM_NEW -j DROP
iptables -A LIMIT_INDIVIDUAL_NEW -j LIMIT_OVERALL_NEW
iptables -A LIMIT_OVERALL_NEW -m limit --limit $OVERLIM_NEW/second -j ACCEPT
iptables -A LIMIT_OVERALL_NEW -j DROP