LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-18-2009, 11:15 AM   #1
arafat.sultan
LQ Newbie
 
Registered: Aug 2009
Posts: 5

Rep: Reputation: 0
developing a firewall


Hi,

I am new to Linux but have some C coding skills. I am using Fedora Core 11 (2.6.29.6-217.2.7.fc11.x86_64). What I want to develop is a firewall, but with some other capabilities.

Here is what I want to do:
1. I want to catch all HTTP, IRC and P2P traffic.
2. I want to be able to dump all outgoing and incoming packets (in a file) for these protocols in each communication session as a separate group of packets for later analysis.
3. I want to inspect contents of each incoming and outgoing packet online and based on that, decide whether to allow that packet to continue or drop it and also dump it in a file.

I am not sure but I think adding a netfilter module is probably one way to do this. I am wondering if there are other better and easier ways.

Before starting the coding, I want to be sure I am doing it in a right way. So, please suggest me some way. I also don't know whether or not I am reinventing the wheel. In that case, can anyone please provide me the resources?

Thanks in advance.

- Arafat
 
Old 08-18-2009, 03:27 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Netfilter is one of the things you will definitely use. Remember, however, that it is important for the code of your module to be simple and fast. Too complicated code can easily slow down the machine. Another question is how you'd decide if the packet is P2P, for instance, or not. This is not trivial. Usually you need to examine content, sometimes also rebuild the transactions, so you (and your software) need to understand the protocols.

Instead, you may do it in userspace (all except point 3) by using pcap library. You should also think if it is better to drop the connection immediately in the kernel module, or to allow this packet pass, process it in userspace and decide to blacklist the flow. The decision depends on many factors.
 
Old 08-18-2009, 03:33 PM   #3
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by arafat.sultan View Post
What I want to develop is a firewall...
I don't think that you do. Or, at least, to do what you want to do, in as much as I understand it, you shouldn't. You might still want to in spite of it not being a particularly useful way to make progress, but, in that case, I don't think I can help.


Quote:
1. I want to catch all HTTP, IRC and P2P traffic.
Up to a point, doing that with a firewall isn't too bad, but its an extra few rules for the existing netfilter/iptables firewall. Read the tutorial at frozentux if that's still of interest. (I assume that, eg, http traffic can be relied on to come in the standard ports for http traffic. If you think that the problem is the someone is managing to divert http traffic around the normal mechanism that makes things more fun.)

Quote:
2. I want to be able to dump all outgoing and incoming packets (in a file) for these protocols in each communication session as a separate group of packets for later analysis.
You could do that, but the performance would be terrible. Put another way, it will only be practical if the data rate is low. OTOH, if you are prepared to capture packets with wireshark (or other similar util) this is more possible because you don't save packets to disk at capture time, although you may do that later. And it may entail some sampling rather than 100% capture, depending on whether you can define useful filters.

Quote:
3. I want to inspect contents of each incoming and outgoing packet online and based on that, decide whether to allow that packet to continue or drop it and also dump it in a file.
If I have understood (by 'online' do you mean something like 'in real time'?) this starts to get difficult however you do it. I am imagining you sat at a console watching traffic and deciding what action to take as packets fly past you.

(Or when you say 'I' do you mean 'the computer based on some algorithm'?)

If you are trying to do something like watch the packets, occasionally see accesses to a bad site and take action on that, you could consider setting up a firewall (or squid...there advantages to that) which takes in a blacklist of your bad sites and you could occasionally add to your blacklist, that would be easier.

So the first thing to decide is whether this 'blacklist method' would be adequate for your needs.
 
Old 08-18-2009, 06:40 PM   #4
hkhalid
LQ Newbie
 
Registered: Aug 2009
Posts: 4

Rep: Reputation: 0
Hi,
As said above, in order to code point 1 of your post, you should understand the protocols.
Concerning inspecting packets contents, you can do it in userspace mode.
If you want to inspect technical information (ip addresses, protocols...) then use the libiptc library.
If you want to inspect data contained in the packets, then use the libpcap library.
Personnally, I've never used libpcap. I've just read some tutorials but it seems to be a good tool.
Concerning libiptc, I've used it to develop a packet filter. It allows you to use the C language to manage iptables rules.
Good luck.
 
Old 08-20-2009, 11:30 AM   #5
arafat.sultan
LQ Newbie
 
Registered: Aug 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks all of you for your replies.
 
  


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
Developing a Firewall rooky Programming 17 04-23-2009 10:14 AM
developing GUI in C arooj_ciit Programming 2 12-24-2008 10:50 AM
Developing Distro Netgh0st Linux - Distributions 3 03-11-2007 02:09 PM
where to start with developing suicideducky Linux - General 9 12-18-2006 04:36 PM
Need help in developing a script ostech Linux - General 2 04-22-2004 09:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:30 AM.

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