Skip to contentSkip to conversation

netfilter observation

DISCUSSION Ethy H. Brito 3 participants 6 messages Jan 26, 2006 – Jan 27, 2006 netfilter

lore
Share & tools
lore
#0 lore raw

Dear developer

I observed an "unusual" behavior when using NAT table that I consider at least dangerous. Maybe it has already been corrected in newer versions or this have to be discussed somewhere else. You tell me please.

Assumptions:
a) conntracking database is always mantained by kernel even in absence of netfilter rules;
b) a new NAT dataflow is only accepted if there exist a rule in NAT table that matches it;
c) remaining NAT dataflow may be ACCEPT'ed by a convenient ESTABLISHED FORWARD rule.

That said I wrote a set of rules that NAT an Internet request to an internal server at a given BCP-5 IP address.

I can see the connection beeing updated in /proc/net/ip_conntrack output.

So far so good.

The problem resides in the fact that if I want to interrupt this and accept another NAT'ed data flow. If I flush all tables (NAT and TALBLE), change the IP address for the internet client and run the script again, the old data flow is not interrupted! The kernel continues to NAT packets even if there is no NAT rules to them.

I suspect that due to (a) the old data flow is not deleted from the database with the flush of NAT table. When I inserted the new rules (new (b)), the old data stream is still forwarded due to (c) since its state is ESTABLISHED. I then ended with two NAT'ed data flows (one unwanted and one as requested)

This is leading to a non authorized dataflow beeing carried out (remember that there is no old (b) anymore) without admin knoledge.

This is happening now to one of my machines (I did not inspect others). Does this make any sence to you?
Is this the expect behavior? How to "kill" the old data flow?

Or even worst: I completely get out of my mind and begun to see "hair in eggs" (as we say in here).

Environment:
iptables -V reports iptables v1.2.11
Linux kernel 2.4.31 (no modules. ipt_* compiled hardwired)

Regards

Signature · 4 lines
Ethy H. Brito         /"\
InterNexo Ltda.       \ /  CAMPANHA DA FITA ASCII - CONTRA MAIL HTML
+55 (12) 3941-6860     X   ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
S.J.Campos - Brasil   / \ 
#1 lore raw

Hello Ethy,

to make a short answer to a long (and well-formulated) question:

Quoted 1 line

Is this the expect behavior?

Yes. Not only expected, but desired, and relied upon in many many real world setups. conntracking/NAT and table processing are as independant as can be. conntracking establishes the concept of a L4 connection, NAT manipulates its addresses, and table processing (filter table) is the point where you permit or deny things.

In the filter table, matches like '-m conntrack' can be used to refer to the NAT state of the packet under inspection.

It's up to you to use this system to implement your policies.

Quoted 1 line

How to "kill" the old data flow?

per-flow: simulate a suitable TCP RST, or use one of the new style userlevel conntrack manipulation tools (work in progress, as far as I know)

per policy and separate implementation: if you have clients changing IP addresses, implement a system (yourself) which learns when that happens, and changes rules - independant of conntrack, in the filter table - which do the right thing for what you want. To help with such things, is why I invented the ippool match, which became ipset, which you can find in patch-o-matic. This is only one example helper. There are lots of other ways. And the problem for you: how to get at the IP assignment change "messages", near real time.

best regards
Patrick

#2 lore raw
Quoted 8 lines · On Fri, 27 Jan 2006 07:14:33 +0100 Patrick Schaaf <[email protected]> wrote:

Hello Ethy,

to make a short answer to a long (and well-formulated) question:

Quoted 1 line

Is this the expect behavior?

Yes. Not only expected, but desired, and relied upon in many many real world setups.

I've already suspected that. This could not have passed hidden that long.

Quoted 2 lines

conntracking/NAT and table processing are as
independant as can be.

And this must be this way, I think. I will use some external tool to make things happen. Someone told me about Cutter (a TCP FIN-ACK-RST tool).

Quoted 2 lines

In the filter table, matches like '-m conntrack' can be used to refer to the NAT state of the packet under inspection.

I can't see how this could help me. The old data stream has already its state set to ESTABLISHED.

Quoted 5 lines
Quoted 1 line

How to "kill" the old data flow?

per-flow: simulate a suitable TCP RST, or use one of the new style userlevel conntrack manipulation tools (work in progress, as far as I know)

Could you gimme some pointer about these tools? They are not in trunk/conntrack tree and google was not of much help (too much garbage to dig into).

Quoted 2 lines

best regards
Patrick

Best Regards

Ethy

#3 lore raw
Quoted 5 lines
Quoted 2 lines

In the filter table, matches like '-m conntrack' can be used to refer to the NAT state of the packet under inspection.

I can't see how this could help me. The old data stream has already its state set to ESTABLISHED.

Hmm. You could use different connmark mark values, and match on those in the filter table. When you flush your NAT rules and rebuild them, use a different set of mark values, and use the same mark values in the filter table.

That's not supposed to be a nice, clean solution. But I think it could work.

Quoted 5 lines
Quoted 1 line

per-flow: [...] one of the new style userlevel conntrack manipulation

tools (work in progress, as far as I know)

Could you gimme some pointer about these tools? They are not in trunk/conntrack tree and google was not of much help (too much garbage to dig into).

Sorry, I did not really track the relevant discussions.

Help/HOWTO/Pointers, somebody?

best regards
Patrick

#4 lore raw

From: Patrick Schaaf <[email protected]>
Date: Fri, 27 Jan 2006 12:13:40 +0100

Quoted 15 lines
Quoted 5 lines
Quoted 2 lines

In the filter table, matches like '-m conntrack' can be used to refer to the NAT state of the packet under inspection.

I can't see how this could help me. The old data stream has already its state set to ESTABLISHED.

Hmm. You could use different connmark mark values, and match on those in the filter table. When you flush your NAT rules and rebuild them, use a different set of mark values, and use the same mark values in the filter table.

That's not supposed to be a nice, clean solution. But I think it could work.

Quoted 1 line
Quoted 1 line

per-flow: [...] one of the new style userlevel conntrack manipulation

Quoted 8 lines
Quoted 4 lines

tools (work in progress, as far as I know)

Could you gimme some pointer about these tools? They are not in trunk/conntrack tree and google was not of much help (too much garbage to dig into).

Sorry, I did not really track the relevant discussions.

Help/HOWTO/Pointers, somebody?

man page of 'conntrack' is here.

http://svn.netfilter.org/cgi-bin/viewcvs.cgi/trunk/conntrack/

Maybe what you want to do is 'conntrack -D conntrack .....'.

-- Yasuyuki Kozakai

#5 lore raw

Sorry,

From: Yasuyuki KOZAKAI <[email protected]>
Date: Fri, 27 Jan 2006 20:31:28 +0900 (JST)

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

Could you gimme some pointer about these tools? They are not in trunk/conntrack tree and google was not of much help (too much garbage to dig into).

Sorry, I did not really track the relevant discussions.

Help/HOWTO/Pointers, somebody?

man page of 'conntrack' is here.

http://svn.netfilter.org/cgi-bin/viewcvs.cgi/trunk/conntrack/

man page is 'conntrack.8' in this directory. ;)

-- Yasuyuki Kozakai