iptables: allowing incoming for 192.168.1.0/24 allowed incoming for all?

Posted by nortally on Server Fault See other posts from Server Fault or by nortally
Published on 2013-06-17T18:07:24Z Indexed on 2014/06/03 3:30 UTC
Read the original article Hit count: 413

Filed under:

The internal side of my ISP router has three devices:

ISP router 128.128.43.1
Firewall router 128.128.43.2
Server 128.128.43.3

Behind the Firewall router is a NAT network using 192.168.100.n/24

This question is regarding iptables running on the Server. I wanted to allow access to port 8080 only from the NAT clients behind the Firewall router, so I used this rule

-A Firewall-1-INPUT -s 192.168.100.0/24 -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

This worked, but UNEXPECTEDLY ALLOWED GLOBAL ACCESS, which resulted in our JBOSS server getting compromised. I now know that the correct rule is to use the Firewall router's address instead of the internal network, but can anyone explain why the first rule allowed global access? I would have expected it to just fail.

Full config, mostly lifted from a RedHat server:

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:Firewall-1-INPUT - [0:0]
-A INPUT -j Firewall-1-INPUT
-A FORWARD -j Firewall-1-INPUT
-A Firewall-1-INPUT -i lo -j ACCEPT
-A Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A Firewall-1-INPUT -m comment --comment "allow ssh from all"
-A Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A Firewall-1-INPUT -m comment --comment "allow https from all"
-A Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A Firewall-1-INPUT -m comment --comment "allow JBOSS from Firewall"
### THIS RESULTED IN GLOBAL ACCESS TO PORT 8080
### -A Firewall-1-INPUT -s 192.168.100.0/24 -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
### THIS WORKED
-A Firewall-1-INPUT -s 128.128.43.2 -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPt
###
-A Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT

© Server Fault or respective owner

Related posts about iptables