Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
iptables question (ipcop)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
mr98ai
n00b
n00b


Joined: 12 Dec 2003
Posts: 44
Location: Ontario, Canada

PostPosted: Fri Jan 07, 2005 4:33 pm    Post subject: iptables question (ipcop) Reply with quote

Hi, i am very new to this linux firewall thing. At work, on every windows machine (there is only about 10 or so), we run tiny personal firewall (very good firewall I might add). It is an application type firewall, so each time an application tries to get out for the first time (eg firefox) then a rule must be created to allow that app to get out / in. However, allowing firefox to connect, does not automatically allow say internet explorer to use port 80 and connect to the web. In other words, tiny personal firewall does not allow every app to access port 80 just because one application can. This is a nice feature because it prevents bad applications from leaving my computer.

My question is, how do I use iptables (I am actually using ipcop which uses iptables) to do the same thing? I want to allow just select applications to use port 80, for web access, and port 110 for email access. I installed the BlockOutTraffic mod which allows me to define which activity I allow out from my computer.

By default, (please tell me if I am wrong) ipcop blocks all incoming activity , unless it first originated from my firewall. I have no problems with this. However, it also allows all outgoing activity, which is a problem, hence the need for the BlockOutTraffic mod.

Thanks in advance
Back to top
View user's profile Send private message
scarr
Tux's lil' helper
Tux's lil' helper


Joined: 24 Jun 2002
Posts: 88
Location: Lebanon, TN

PostPosted: Fri Jan 07, 2005 6:56 pm    Post subject: Reply with quote

I am not aware of a program that does what you are asking.

IPTables are done at the kernel level, there is nothing tying a port to a specific process on your computer. So the kernel doesn't know that Firefox is trying to use port 80, it just knows that A process is trying to use port 80.

One of the reason this was needed in Windows was because so many different ways exist for a system to be compromised and have a zombie process started. I don't think you will have as much of a problem with this on Linux.

To get this functionality, someone would probably have to rewrite some of the Socket code to include requesting process in the IP stream. THis of course is from what I can tell, anyway.
_________________
Scott Carr * OpenOffice.org * Documentation Maintainer
http://documentation.openoffice.org
jabber: scarr@progbits.com
Back to top
View user's profile Send private message
djnauk
Apprentice
Apprentice


Joined: 11 Feb 2003
Posts: 183
Location: Caerphilly, Wales, UK

PostPosted: Sat Jan 08, 2005 1:22 am    Post subject: Re: iptables question (ipcop) Reply with quote

mr98ai wrote:
My question is, how do I use iptables (I am actually using ipcop which uses iptables) to do the same thing? I want to allow just select applications to use port 80, for web access, and port 110 for email access. I installed the BlockOutTraffic mod which allows me to define which activity I allow out from my computer.


I haven't checked for a long time, but there used to be a module which would allow you to block or allow traffic based on the process that created it, however, you would need to run the patch-o-matic and update the kernel, selecting the right patch to run first, and then, you would only be able to use it for processes based on the machine that the firewall was running on. For remote machines sending their traffic though, it's useless.

mr98ai wrote:
By default, (please tell me if I am wrong) ipcop blocks all incoming activity , unless it first originated from my firewall. I have no problems with this. However, it also allows all outgoing activity, which is a problem, hence the need for the BlockOutTraffic mod.

Thanks in advance


I also remember a module which would be able to check the type of traffic that was being sent. It was called something like sub7 or 7layer (I think there is a seven in the name :). It used regular expressions and pattern checking against the data in the packet to check against the type of data, like DNS or HTTP. You could use that to some degree, but that doesn't protect against a virus sending out e-mails on port 25 or a trogen annoucing itself over the normal HTTP port 80.

I think what you are trying to do is very near impossible using stateful firewalls via a router.

Your best option is probably to stick with the personal firewall on each PC (at least that way, if one PC on the network does get infectied in some way, like a drive-by-download, then the others are at less of a risk), and look into shutting down the outgoing connections to only those that are required and any that are related.
_________________
Jonathan Wright (Technical Director, JAB Web Solutions)

UK Hosting & Reseller Hosting from JAB Web Solutions
Back to top
View user's profile Send private message
Ox-
Guru
Guru


Joined: 19 Jun 2003
Posts: 305

PostPosted: Sat Jan 08, 2005 9:22 am    Post subject: Reply with quote

I'm iptables illiterate, so I use firehol for a front-end.

It has an option to specify command source, for example like this:
Code:

interface "eth0+" internet
    client "http" allow command "/usr/bin/firefox"

I ran firehol in "explain" mode, and it told me the iptables rules it would generate for the above script would be:
Code:

# Command  : interface "eth0" internet

# Creating chain 'in_internet' under 'INPUT' in table 'filter'
/sbin/iptables -t filter -N in_internet
/sbin/iptables -t filter -A INPUT -i eth0+ -j in_internet

# Creating chain 'out_internet' under 'OUTPUT' in table 'filter'
/sbin/iptables -t filter -N out_internet
/sbin/iptables -t filter -A OUTPUT -o eth0+ -j out_internet

# Command  : client "http" allow command "firefox"

# Preparing for service 'http' of type 'client' under interface 'internet'

# Creating chain 'in_internet_http_c2' under 'in_internet' in table 'filter'
/sbin/iptables -t filter -N in_internet_http_c2
/sbin/iptables -t filter -A in_internet -j in_internet_http_c2

# Creating chain 'out_internet_http_c2' under 'out_internet' in table 'filter'
/sbin/iptables -t filter -N out_internet_http_c2
/sbin/iptables -t filter -A out_internet -j out_internet_http_c2

# Running simple rules for  client 'http'
/sbin/iptables -t filter -A out_internet_http_c2 -p tcp --sport 32768:61000 --dport 80 -m owner --cmd-owner /usr/bin/firefox -m state --state NEW\,ESTABLISHED -j allow

/sbin/iptables -t filter -A in_internet_http_c2 -p tcp --sport 80 --dport 32768:61000 -m state --state ESTABLISHED -j allow

I have no clue if the --cmd-owner option works or not, or how to enable it if it's in some optional module.

(djnauk: I think it was l7filter, and yeah, I think it's purpose is just to make sure only http commands are used on port 80, etc.)


Last edited by Ox- on Sat Jan 08, 2005 11:44 am; edited 1 time in total
Back to top
View user's profile Send private message
djnauk
Apprentice
Apprentice


Joined: 11 Feb 2003
Posts: 183
Location: Caerphilly, Wales, UK

PostPosted: Sat Jan 08, 2005 11:21 am    Post subject: Reply with quote

Quote:
Code:
/sbin/iptables -t filter -A out_internet_http_c2 -p tcp --sport 32768:61000 --dport 80 -m owner --cmd-owner /usr/bin/firefox -m state --state NEW\,ESTABLISHED -j allow
/sbin/iptables -t filter -A in_internet_http_c2 -p tcp --sport 80 --dport 32768:61000 -m state --state ESTABLISHED -j allow

I have no clue if the --cmd-owner option works or not, or how to enable it if it's in some optional module.

(djnauk: I think it was l7filter, and yeah, I think it's purpose is just to make sure only http commands are used on port 80, etc.)


That's interesting. Didn't realise that they integrated it into iptables! :) I might look into that and setup some improved rules in my firewall. But, at the end of the day, they still only work on the local machine, not across the network! :)

Thanks for the name aswell! :) It's been so long since I tinkered with iptables! :) I'm a little but rusty!
_________________
Jonathan Wright (Technical Director, JAB Web Solutions)

UK Hosting & Reseller Hosting from JAB Web Solutions
Back to top
View user's profile Send private message
Ox-
Guru
Guru


Joined: 19 Jun 2003
Posts: 305

PostPosted: Sat Jan 08, 2005 11:42 am    Post subject: Reply with quote

I just went to netfilter.org to check on this feature. It looks like it's in the patch-o-matic "extra repository" under the name "ownercmd". Status is "untested", so who knows :)
Back to top
View user's profile Send private message
mr98ai
n00b
n00b


Joined: 12 Dec 2003
Posts: 44
Location: Ontario, Canada

PostPosted: Sat Jan 08, 2005 2:51 pm    Post subject: Reply with quote

Thanks for your replies.

Here is the problem though. In my work network, there are 2 computers running gentoo, about 10 running windows, and there is one firewall running ipcop. I am not worried about the linux machines running trojan horses, but I am worried about the windows machines. We just finished cleaning up a nasty virus which downloaded all kinds of files into the main directory, and every possible subdirectory, and these files would be named as porn.jpg.exe or something like that. There was about 80 different names it could be named as. Deleting the files only made room for the next batch, unless the spawning process was found and deleted.

I could do as djnauk suggested, and keep the tpf on the windows machines, but this makes administration a nightmare as more and more machines are added to the netwok, not to mention the increased cost.

Please bare with me here, I would just to make this clear in my mind: if an application on box A sends a tcp/ip packet through the firewall, is there no way for the firewall to tell (by examining the packet) which application the packet originated from? Or is this kind of packet filtering only possible on the machine that it originated from? If so, is this a "limitation" of the linux kernel, would it be possible for a different OS, or is this simply the nature of a tcp/ip packet, that the application that sent the packet is in no way connected to the packet data (other than via the ip address / port number of course)
Back to top
View user's profile Send private message
Ox-
Guru
Guru


Joined: 19 Jun 2003
Posts: 305

PostPosted: Sun Jan 09, 2005 12:57 am    Post subject: Reply with quote

Oh yeah, this ownercmd thing for iptables only works locally.

The limitation is in tcp/ip and it's not really a limitation. The packets only contain source and destination addressess and ports (speaking from a very high level hand waving standpoint). The ownercmd filter can work its magic by looking in the local linux kernel memory to see which process owns the port address in the packet.

iptables can do this because it's linux specific (but even then can only do it locally because of the inherent problems with looking directly into kernel memory on a remote machine).

tcp/ip cannot embed command names because a) tcp is portable across many operating systems including some that have very different ideas about processes, b) it would add a huge overhead to packets, and c) it could be easily spoofed anyway.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum