I like your implementation. I'd tweak the period and count personally, but looks pretty good. You could add that to a startup script or even modify the iptables startup to start this.
Since I don't have any outside SIP connections other than static IP I don't have this issue, but if I did I'd probably give them 2-3 chances and at least a 3 minute outage. Once your setups are saved and no retry is necessary then you could lower the trigger threshold.
I'm not sure, as I haven't tested, but I think each time someone connects to 5060 you'll count them 2x. Once on the set, and once on the update. So you've given them a total of 1 chances to login every 60 seconds.
|
Code:
|
--set
This will add the source address of the packet to the list. If the source address is already in the list, this will update
the existing entry. This will always return success. |
Here's what I would probably try (Note: My example is using "-A" for add to go in a permanent ruleset. If you are using "-I" for insert it goes to the top of the list, but you should setup your rules in reverse order from last to first if doing that.)
|
Code:
|
# iptables -A INPUT -p udp --dport 5060 -i eth0 -m state --state NEW -m recent --set
# iptables -A INPUT -p udp --dport 5060 -i eth0 -m state --state NEW -m recent --rcheck --seconds 3600 --hitcount 100 -j DROP
# iptables -A INPUT -p udp --dport 5060 -i eth0 -m state --state NEW -m recent --rcheck --seconds 600 --hitcount 20 -j DROP
# iptables -A INPUT -p udp --dport 5060 -i eth0 -m state --state NEW -m recent --rcheck --seconds 300 --hitcount 10 -j DROP
# iptables -A INPUT -p udp --dport 5060 -i eth0 -m state --state NEW -m recent --rcheck --seconds 180 --hitcount 5 -j DROP
# iptables -A INPUT -p udp --dport 5060 -i eth0 -m state --state NEW -m recent --rcheck --seconds 60 --hitcount 3 -j DROP |
^ That example first sets or updates new UDP 5060 connections counter for the remote IP. Then checks to see how many hits there are on that port, and applies a timeout accordingly. Higher timeouts come first since once a "-j" action is found the evaluation of that packet stops.
So for 3 attempts the lockout is 1 minute. If the IP continues trying the timeout will increment automatically:
5 hits 3 minutes, 10 hits 5 minutes, 20 hits 10 minutes, 100 hits 1 hour.
More info regarding the recent module in iptables.
http://snowman.net/projects/ipt_recent/
http://www.e18.physik.tu-muenchen.de/~tnagel/ipt_recent/