Is accepting RELATED,ESTABLISHED for all sources in iptables considered “too open”

ipiptablesSecuritytcp

I've often seen the rule -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT applied. Whilst I'm not an expert, that particular line concerns me. It's pretty obvious that the rule allows all traffic with the only exception that the connection has to have been established or related to an established connection.

Scenario

  • I'll allow connections to the default SSH port 22 from the servers
    LAN in the subnet 192.168.0.0/16 or whatever.
  • SuperInsecureApp® exposes something on port 1337,
    which I add to my INPUT chain.
  • I've added the conntrack rule to accept ESTABLISHED and RELATED from all sources
  • Chain policy is DROP

So basically that configuration shoud allow SSH-connections from the LAN only, whilst allowing inbound traffic on port 1337 from world.

This is where my confusion blooms. Would the conntrack in any way expose a security flaw that would allow one to get an established connection on 1337 (since it's world open), and then utilize that connection to gain access to the SSH port (or any other port for that matter)?

Best Answer

I would not consider ESTABLISHED and RELATED traffic too open. You may be able to omit RELATED, but should definitely allow ESTABLISHED. Both of these traffic categories use conntrack states.

ESTABLISHED connections have already been validated by another rule. This makes it much simpler to implement unidirectional rules. This only allows you to continue transactions on the same port.

RELATED connects are also validated by another rule. They don't apply to a lot of protocols. Again they make it much simpler to configure rules. They also ensure proper sequencing of connections where they apply. This actually makes your rules more secure. While this may make it possible to connect on a different port, that port should only be part of a related process like an FTP data connection. Which ports are allow are controlled by protocol specific conntrack modules.

By allowing ESTABLISHED and RELATED connections, you can concentrate on which new connections you want the firewall to accept. It also avoids broken rules meant to allow return traffic, but which allow new connections.

Given you have classified the program on port 1337 as insecure, it should be started using a dedicated non-root user-id. This will limit the damage someone can do if they do manage to crack he application and gain enhanced access.

It is highly unlikely a connection on port 1337 could be used to access port 22 remotely, but it is possible that a connection to port 1337 could be used to proxy a connection to port 22.

You may want to ensure SSH is secured in depth:

  • Use hosts.allow to limit access in addition to the firewall restrictions.
  • Prevent root access, or at least require the use of keys and limit their access in the authorized_keys file.
  • Audit login failures. A log scanner can send you periodic reports of unusual activity.
  • Consider using a tool like fail2ban to automatically block access on repeated access failures.
Related Question