Ambiguities in TCP/IP May Allow Firewall Bypassing
21 Oct. 2002
Summary
There are ambiguities in implementations of the TCP/IP suite for various operating systems. Even if this fact has been used since a long time in different software for OS fingerprinting, no real attempt has been made to identify the security impact of the differences in the TCP/IP semantics. Paul Starzetz has done some research on the TCP/IP connection open semantics which is of course very important for security of networked systems. Paul Starzetz believes that the flaws that he detected have a big impact on design of firewalls and packet filters since an improper implementation can easily lead to serious security problems.
The TCP/IP protocol stack offers a three way handshake for connection oriented communication using the TCP protocol. Basically, a connection can be opened by sending a synchronization packet to a listening service on a particular host. The host will respond with a synchronization acknowledgment packet which in turn must be acknowledged by the requesting host. Then, the connection is considered to be open (at least at the transport layer) and the two hosts may exchange some data.
The three way handshake is an essential part of the communication using the TCP protocol. Therefore many packet filter firewalls try to prevent the three way handshake from completion in order to protect an internal/corporate network from being accessed from the outside. Of course, statefull firewalls may have some more sophisticated mechanism.
Paul Starzetz have found a very ambiguous behavior of TCP/IP implementations while doing some research on the connection request phase. Below you will find the findings about various OSes, however the list should not be considered complete. We have used the NemesisTCP tool [1] to generate the traffic and tcpdump to capture the responses.
* The normal behavior (of all OSes) is like this:
14:18:00.595517 192.168.1.184.12345 > 192.168.1.111.9999: S 420:420(0) win 512 (DF) [tos 0x18]
14:18:00.595731 192.168.1.111.9999 > 192.168.1.184.12345: S 1679763291:1679763291(0) ack 421 win 5840 <mss 1460> (DF)
The first host sends a SYN packet from port 12345 to a service on port 9999 and receives a SYN, ACK
* Linux 2.4.19
The examination of the source code of the TCP engine reveals that a TCP connection can be opened by any combination of the TCP flags having the SYN bit set and the ACK bit reset. For example we can open a TCP connection by sending an obviously bogus SYN, RST packet:
Other OSes than those tested above are expected to behave in a similar manner after obtaining such a discouraging result...
Impact:
The ambiguities can be used to bypass/tunnel firewalls filtering TCP packets according to the TCP flags set. Especially stateless firewalls simply comparing the flags field with some expected value(s) to distinguish between synchronization packets and packet from an already open connection can be easily bypassed just by sending a bogus synchronization packet to a listening port. The currently deployed TCP stacks seem to be highly bogus and lazy implemented.
Administrators of firewall devices should set up some filtering rules to drop bogus TCP packets as mentioned above. For example on systems using iptables to filter packets bogus packets can be easily distinguished by following rules: