From: Elver Loho Subject: Possible dangerous flaw in the NAT howto Date: Sun, 22 Jun 2003 05:44:49 +0300 Sender: netfilter-admin@lists.netfilter.org Message-ID: <20030622024450.19E60105939@hot.ee> Content-Transfer-Encoding: quoted-printable Return-path: Errors-To: netfilter-admin@lists.netfilter.org List-Help: List-Post: List-Subscribe: , List-Id: List-Unsubscribe: , List-Archive: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" To: netfilter@lists.netfilter.org I was on #netfilter (irc.freenode.net) earlier and asked about a possible f= law in the NAT howto, but got no reply (people sleeping?) so I'm just going= to paste what I said here and go to sleep. (nearing 6am currently) I have a question about masquerading. The NAT howto gives an exampl= e like this: "iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE", but si= nce it masks the packets that are outgoing on ppp0 (by the destination IP, = interface IP and netmask) then could that rule also be exploited by outside= hosts tunneling? For example, we have host A on subnet where the gateway to the inte= rnet is B (running that same rule) and then there are external hosts on the= internet C and D. A's packets to C and D are masq'ed by B, but can't C and= D also use B as a IP-level proxy to communicate to eachother? Over LAN the routing is done on the ethernet level usually, but ove= r the internet this could possibly done by IP encapsulation (RFC 2003 and R= FC 1853) Coming back to the example, C tunneling through B to D would look s= omething like [ IP layer: from C to B [ IP layer: from C to D [ TCP layer [= Data ] ] ] ] RFC 2003 does however define that if the source IP is the same as a= ny interface on itself, then it should drop it. So therefore, C can't fake = the address part to be B. However, with masquerading, it would NAT the conn= ection and thus to D it would appear as if the data was coming from B. Since Netfilter does NAT in the POSTROUTING table, then it only car= es about the outgoing interface, which would be ppp0 or whatever your inter= net link might be. The problem would be delivering the packet to B so that B would thi= nk that it is outgoing on it's internet link. Since routing is done at a higher layer (Ethernet layer above the I= P layer for example) then IP encapsulation could possibly used to deliver i= t to host B. The quick and dirty masquerading part of the NAT howto at netfilter= .org (http://www.netfilter.org/documentation/HOWTO//NAT-HOWTO-4.html#ss4.1)= does not build any safeguards against this. Sensible way would be denying all forwarding requests coming in ove= r the internet link. Potentially this could mean that there are hundreds of Linux gatewa= ys out there that could be used as anonymous proxies. Funny. The Masquerading Simple Howto (http://www.linuxdocs.org/HOWT= Os/Masquerading-Simple-HOWTO/summary.html) DOES address that specific secur= ity hole by adding "iptables -A FORWARD -i eth0 -o eth0 -j REJECT". So I would say that anyone using just netfilter.org howto could be = vulnerable. (http://www.netfilter.org/documentation/HOWTO//NAT-HOWTO-4.html= #ss4.1) This inconsistency between howtos was pointed out by Peter Johansson (x-g@g= amleby.net) when he was looking for docs while setting up his Linux gateway= . I did the additional research into the subject. Elver Loho kernelpenguin@hot.ee ----------------------------------------- Hot Mobiil - helinad, logod ja pilts=F5numid! http://portal.hot.ee