Hi, I have had a few attempts on my router to bruteforce the password over port 22 (SSH). [I assume thats what tehy are trying since I get a number of connections on port 22 from the same IP in my log).
So I thought I would make it a bit harder to get in: I am attempting to open port 443 instead of port 22 from WAN, and to limit the number of connections from the same host within a timeframe. Redirecting works like a charm and to honest I have very little problems with hacking attempts from this only, but my attempts to limit number of connections from the same host are unsuccesful. It seems the rules do not work. (I think it's because of the redirect.) Here are my firewall.user:
### INIT
insmod ipt_LOG
### Log Traffic
# Log traffic incoming from WAN on open port (443)
iptables -t nat -A prerouting_wan -p tcp --dport 443 -j LOG --log-prefix "FW Incoming: "
### SSH (Dropbear running on port 22, WAN redirect from port 443)
## SSH: Rules for new incoming connection on tcp-22
# Block direct access to port 22 from WAN
iptables -t nat -A prerouting_wan -p tcp --dport 22 -j DROP
# Redirect port 443 from WAN to port 22
iptables -t nat -A prerouting_wan -p tcp --dport 443 -j DNAT --to :22
# Drop repeated connection attempts to WAN
# Port 22
iptables -t nat -A prerouting_wan -p tcp --dport 22 -m state --state NEW -m recent --set --name ATTACKER_SSH
iptables -t nat -A prerouting_wan -p tcp --dport 22 -m state --state NEW -m recent --update --name ATTACKER_SSH --seconds 300 --hitcount 1 -j LOG --log-prefix "FW SSH Attack on port22: "
iptables -t nat -A prerouting_wan -p tcp --dport 22 -m state --state NEW -m recent --update --name ATTACKER_SSH --seconds 300 --hitcount 1 -j DROP
# Port 443
iptables -t nat -A prerouting_wan -p tcp --dport 443 -m state --state NEW -m recent --set --name ATTACKER_SSH2
iptables -t nat -A prerouting_wan -p tcp --dport 443 -m state --state NEW -m recent --update --name ATTACKER_SSH --seconds 180 --hitcount 3 -j LOG --log-prefix "FW Attack on port 8022: "
iptables -t nat -A prerouting_wan -p tcp --dport 443 -m state --state NEW -m recent --update --name ATTACKER_SSH2 --seconds 180 --hitcount 3 -j DROP
# Accept if connection doesn't hit the limit
iptables -A input_wan -p tcp --dport 22 -m state --state NEW -j ACCEPT
Can anybody see what I am doing wrong ?
/Selepo