LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-16-2003, 06:19 AM   #1
gregory76
LQ Newbie
 
Registered: May 2003
Location: Aus
Distribution: Redhat 8.0
Posts: 10

Rep: Reputation: 0
iptables OUTPUT rules: DROP by process (PID)?


Hi all,

I have a good iptables firewall set up to filter INPUT packets, but I want to be able to filter packets traversing the OUTPUT chain. Specifically, I want to limit the applications (ie, processes) that are allowed through the firewall to the internet.

I want to DROP all out-going packets from applications other than those I choose. This would prevent communications from trojans, spyware, update agents (!) etc etc from my box.

(ZoneAlarm, a popular Windows firewall, provides similar functionality: all applications are blocked until they are explicitly permitted. In addition, users are prompted when unauthorised applications attempt to communicate past the firewall.)

I have searched the forums without success. I see that it is possible to filter on PID (see http://iptables-tutorial.frozentux.n.../pid-owner.txt). The obvious problem is mapping from PIDs to applications (especially as they will be dynamic!)

Does anyone have any suggestions? Any scripts/applications/tools out there that can handle this? Has anyone done something similar before?

thanks in advance!
gregory.
 
Old 06-16-2003, 08:17 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Interesting, though IMO this is more of a programming question than a security related one. Anyway. Like everyone else I've been pondering this as well. If you want to explore this I think you need to look for functionality in a few area's:
Process discovery should
- scan for "valid" PID's and,
- queue them for processing and,
- leave out PIDs below 20 that belong to kernel processes or,
- are already in the state table.
- During the scanning it should check if processes in the queue haven't already died: those of you who are familiar with running Chkrootkit on boxen with short-living processes know the approach to checking PID's the way chkrootkit does it fails. This part will either make up for 99 percent of the app's overhead or make it fail, IMO.
Process validation should check if
- the app is capable of requesting a client or server socket,
- the name of the app on the commandline is equal to the name of the binary,
- if the checksum of the binary in /proc matches the binary on disk: something like "sha1sum /proc/$(/sbin/pidof someApp)/exe $(strings /proc/$(/sbin/pidof someApp)/cmdline)" if you want to have an idea,
- the process UID is part of a group that has privileges/restrictions: check out std Linux capabilities in LINUX_CAPABILITIES (caps intended) and Grsecurity.org patch for usable socket restriction options, you need to be able to filter server apps from user apps, do user/group management,
- the process already is in the state table or has no rules attached.
Examples of apps that could have "user servicable parts" could be Procwatch or Nabou: the FreeBSD port of Systrace looks promising in the way it handles authorization but I have only skimmed the docs a while ago.
Rule management then only has to deal with adding/deleting rules.

As far as I can see there are three basic hooks for getting an app. One is scanning /proc, the other is waiting for an app to call for a socket to be set up and the third one will be sniffing for traffic.
Scanning /proc will be more of a "brute force" approach because for instance starting up a client app like Nutscrape doesn't mean I'm going out on the network. Sniffing for traffic and denying it as soon as it doesn't match up with any criteria is just too late, so waiting for an app to make a call to set up a socket seems the best way so far. Having a static list of apps that are always allowed could speed up the decision part. Also for all of the above you have to ask yourself if an app could DoS this "ZA for Linux" approach.


I hope this gives you some idea about what I think you could be looking at in terms of needed functionality on a high level.
 
Old 06-18-2003, 06:30 AM   #3
gregory76
LQ Newbie
 
Registered: May 2003
Location: Aus
Distribution: Redhat 8.0
Posts: 10

Original Poster
Rep: Reputation: 0
unSpawn,

Thanks for this informative post. Clearly some excellent advice here!

I was hoping someone else would have addressed this already and there would be an easy solution! Oh well, there is a lot to think about here anyway....thanks again. :-)
 
Old 07-11-2003, 08:40 AM   #4
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
If you're willing to recompile your kernel, it is supported in iptables.

<snip from man iptables>
owner
This module attempts to match various characteristics of
the packet creator, for locally-generated packets. It is
only valid in the OUTPUT chain, and even this some packets
(such as ICMP ping responses) may have no owner, and hence
never match.

--uid-owner userid
Matches if the packet was created by a process with
the given effective user id.

--gid-owner groupid
Matches if the packet was created by a process with
the given effective group id.

--pid-owner processid
Matches if the packet was created by a process with
the given process id.

--sid-owner sessionid
Matches if the packet was created by a process in
the given session group.

--cmd-owner name
Matches if the packet was created by a process with
the given command name. (this option is present
only if iptables was compiled under a kernel sup-
porting this feature)
</snip>

These features can be used, for instance, to make a box only capable of making port 80 connections from mozilla, or IRC from XChat. Cool stuff.

HTH

Ben.
 
Old 07-11-2003, 02:39 PM   #5
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Rep: Reputation: 30
Quote:
--cmd-owner name
Matches if the packet was created by a process with
the given command name. (this option is present
only if iptables was compiled under a kernel sup-
porting this feature)
anyone know if 2.4.x supports this... or is this 2.5.x only
 
Old 07-11-2003, 03:20 PM   #6
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
I think it's 2.5... I couldn't make it work on 2.4.18 or 2.4.20, though I can't say I tried very hard.

B.
 
Old 07-11-2003, 04:28 PM   #7
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Rep: Reputation: 30
lol, thx for the tip german. Too bad I need to have a stable kernel on this one box, and I was planning on writing a new iptables script one of these days.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting pid of a process!! vishamr2000 Programming 34 03-12-2015 07:12 AM
Using Firestarter ... Can I Add/Drop rules from a terminal prompt? rickh Linux - Security 1 06-15-2005 03:21 AM
iptables - drop all -> allow needed OR allow all -> drop specific lucastic Linux - Security 5 12-21-2004 02:07 AM
Process order of iptables chain rules. mrpc_cambodia Linux - Networking 1 07-14-2004 12:21 AM
Get Next PID of Process Tree zer0python Programming 7 11-26-2003 11:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 11:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration