News for hackers. Stuff that matters.
Re:Ask HN: Best way to block an EC2-hosted scraper? by jrockway on Sunday January 09, 2011 @01:30PM (#2085987)
I use an iptables rule like:

    # connection limit for HTTP
    -A INPUT -i eth0 -p tcp --syn --dport www -m connlimit ! --connlimit-above 128 --connlimit-mask 24 -j ACCEPT
This basically means, "only accept requests to port 80 if the /24 has fewer than 128 open connections". It is to kill things like Slowloris, but you can bring the limit down and kill scrapers. You can also block based on connection rate:

    -N RATE_CHECK
    -A INPUT -p tcp -m multiport --dports www -m state --state NEW -j RATE_CHECK
    -A RATE_CHECK -m recent --set --name RATE
    -A RATE_CHECK -m recent --update --seconds 60 --hitcount 4 --name RATE -j REJECT
    -A RATE_CHECK -p tcp -m multiport --dports www -j ACCEPT
This will deny any connection that is the 5th connection or higher in a single minute. I use this rule for ssh and smtp, but some tweaking might be adequate for a web server.

(Note: all these rules are for default deny with a rule like "-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT" to ignore established states. If your firewall setup is different, then the rules will need to be modified.)

There is also a program called fail2ban that will read logs and apply temporary bans based on what the logs say.

My solution to this problem is to just cache agressively. Hundreds of requests per second is nothing for Varnish.

Re:Ask HN: Best way to block an EC2-hosted scraper? by ehutch79 on Sunday January 09, 2011 @03:02PM (#2086251)
be careful with things like this, it could get you locked out of your server very quick.

denyhosts and fail2ban are better ideas for dropping bad actors on the net.

Re:Ask HN: Best way to block an EC2-hosted scraper? by jrockway on Sunday January 09, 2011 @04:44PM (#2086515)
It's not a problem; the rules only apply to eth0, but I connect over tun0. And, it's time-limited to 60 seconds either way. And, I have web console access.

So this is not something I worry about. ssh password crackers and script kiddies taking down my website are a little more worrisome.