Skip to contentSkip to conversation

Is iptables kickin' that much?

DISCUSSION wickedsun 3 participants 5 messages Sep 6, 2002 – Sep 7, 2002

lore
Share & tools
lore

wickedsun

author
#0 lore raw

I'm not sure I understood very well what you explained. But I have only one thing to say, it works. Now the question is, will this work with any protocol? (ftp, irc, etc). The thing is scary me a bit. I read in your email that you have to load up a FTP module (which I have compiled in the kernel) and it seems to me that it works with other protocol as well. (I was able to enable Active in DC++ without having to forward manually each ports like I used to do).

This was of a huge help for the iptables newbies (including me) and thanks.

Charles

-----------------------
Original Message:
As alot of others replies the problem is when ftp enters passive mode,
the server initiates a dataconnection to your machine.

Fortunatly, is a "port" command is send first over the command channel, in order to let the client and server know how and where this new connection will be established.

This can be caught by the netfilter code, and netfilter can allow this connection to be accepted from the server in a quite clever way, because netfilter is _statefull_. ipchans was not, and hence this was not possible.

The following gives an example of how netfilter can handle this:
Lets assume that you are sittin behind a iptables firewall doing nat, and all you want is to allow users from the inside (eth0) to conenct to the internet through the external link (ppp0)

# First load the heper modules for the ftp protocol connection tracking. # Delete these lines, if the modules are compiled statically into the

# kernel.
modprobe ip_conntrack_ftp
# And the nat part for the ftp protocol.
modprobe ip_nat_ftp

# Set default policies.
iptables -P INPUT drop
iptables -P FORWARD drop
iptables -P OUTPUT accept

# NAT all connections
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUEADE

# Allow the mashine to make any kind of connections. iptables -A INPUT -m state --state ESTABLISHED,RELATED \
-j ACCEPT

# Allow the same for machines located behind the firewall. iptables -A FORWARD -i eth0 -o ppp0 -j ACCEPT iptables -A FORWARD -o eth0 -i ppp0 -m state \
--state ESTABLISHED,RELATED -j ACCEPT

And we are all done. The trick is to use the 'state' match. The RELATED state will match the first packet in the data-connection from the ftp-server in passive mode. Any packets hereafter will be in the ESTABLISHED state.

As you might have noticed, there is no protocol speicifer. So this also works for e.g. DNS lookups (udp) and ICMP packets related to an already esablished connection. Statefull firewalling is just sooo great.

There is no reason for you to patch the kernel in order to do this, this has been possible for a long time.

Regards
Anders Fugmann

-----------------
Charles D'Aoust
[email protected]
[email protected]

#1 lore raw
Quoted 1 line · wickedsun

thing to say, it works.

Great.

Quoted 2 lines

Now the question is, will this work with any
protocol? (ftp, irc, etc).

as of today, only ftp and IRC is implemented in the vanilla tree. POM may have connection tracking for other protocols.

A protocol that requests something and then receives an answer is handled by basic connection tracking (Which is why you dont need connection tracking modules for e.g. http and pop, since no new connection are established). It is the RELATED packets that are hard to find.

Quoted 5 lines

The thing is scary me a bit. I read in your email
that you have to load up a FTP module (which I have compiled in the kernel) and it seems to me that it works with other protocol as well. (I was able to enable Active in DC++ without having to forward manually each ports like I used to do).

Active DC++???? Never heard of it.

Quoted 2 lines

This was of a huge help for the iptables newbies (including me) and thanks.

No problem.

Regards
Anders Fugmann

--
Author of FIAIF
FIAIF Is An Intelligent Firewall
http://fiaif.fugmann.dhs.org

author
#2 lore raw

DC++ is a Direct Connect client. You can use either Passive or Active mode. It's just like FTP. In passive you get the search responces from the server where as Active, the users send you the responces directly thru port 1412. I used to have to map the ports, but after flushing my forwards and adding your rules to my IPtables, it worked.

Look on sourceforge for DC++.

-------Original Message-------

From: Anders Fugmann
Date: Friday, September 06, 2002 7:52:52 PM
To: wickedsun
Cc: netfilter
Subject: Re: Is iptables kickin' that much?

Quoted 1 line · wickedsun

thing to say, it works.

Great.

Quoted 2 lines

Now the question is, will this work with any
protocol? (ftp, irc, etc).

as of today, only ftp and IRC is implemented in the vanilla tree. POM may have connection tracking for other protocols.

A protocol that requests something and then receives an answer is handled by basic connection tracking (Which is why you dont need connection tracking modules for e.g. http and pop, since no new connection are established). It is the RELATED packets that are hard to find.

Quoted 2 lines

The thing is scary me a bit. I read in your email
that you have to load up a FTP module (which I have compiled in the

kernel)

Quoted 1 line

and it seems to me that it works with other protocol as well. (I was able

to

Quoted 2 lines

enable Active in DC++ without having to forward manually each ports like I used to do).

Active DC++???? Never heard of it.

Quoted 2 lines

This was of a huge help for the iptables newbies (including me) and thanks

No problem.

Regards
Anders Fugmann

--
Author of FIAIF
FIAIF Is An Intelligent Firewall
http://fiaif.fugmann.dhs.org

.

#3 lore raw
Quoted 2 lines · wickedsun

DC++ is a Direct Connect client. You can use either Passive or Active mode. It's just like FTP. In passive you get the search responces from the server where as Active, the users send you the responces directly thru port 1412. I used to have to map the ports, but after flushing my forwards and adding your rules to my IPtables, it worked.

If Active mode spawns a new connection, then I do not understand why it works. Try to see if the port is always open by telnetting to it from a host on the internet.

Also you should try to use NMAP (from a remote machine) to see what how many ports are open on your machine.

Regards
Anders Fugmann

#4 lore raw
In reply to Anders Fugmann

----- Original Message -----
From: "Anders Fugmann" <[email protected]>
To: "wickedsun" <[email protected]>
Cc: "netfilter" <[email protected]>
Sent: Friday, September 06, 2002 7:44 PM
Subject: Re: Is iptables kickin' that much?

Quoted 6 lines
Quoted 1 line · wickedsun

thing to say, it works.

Great.

Quoted 2 lines

Now the question is, will this work with any
protocol? (ftp, irc, etc).

Quoted 11 lines

as of today, only ftp and IRC is implemented in the vanilla tree. POM may have connection tracking for other protocols.

A protocol that requests something and then receives an answer is handled by basic connection tracking (Which is why you dont need connection tracking modules for e.g. http and pop, since no new connection are established). It is the RELATED packets that are hard to find.

Quoted 2 lines

The thing is scary me a bit. I read in your email
that you have to load up a FTP module (which I have compiled in the

kernel)

Quoted 1 line
Quoted 1 line

and it seems to me that it works with other protocol as well. (I was

able to

Quoted 1 line
Quoted 1 line

enable Active in DC++ without having to forward manually each ports like

I

Quoted 5 lines
Quoted 1 line

used to do).

Active DC++???? Never heard of it.

Quoted 2 lines

This was of a huge help for the iptables newbies (including me) and

thanks.

Quoted 11 lines

No problem.

Regards
Anders Fugmann

--
Author of FIAIF
FIAIF Is An Intelligent Firewall
http://fiaif.fugmann.dhs.org