Click here to Skip to main content
Licence 
First Posted 7 Dec 2003
Views 249,686
Bookmarked 111 times

Simple Packet - Filter Firewall

By | 27 Sep 2004 | Article
A simple packet filtering based open source Firewall. It uses Filter hook driver for its basic working

Introduction

It is very difficult to find free source code of a firewall . So I with my friend Rajender developed this firewall. It is a simple firewall based on packet filtering technology.

Background

I have used the driver as describe in an article in http://www.codeproject.com/ - Code Project/Internet & Network - Developing Firewalls for Windows 2000/XP by Jesús O at the URL : http://www.codeproject.com/useritems/drvfltip.asp .

Using the code

Working of the filter

Working of firewall is based on the following steps

  • Extract the packet header
  • Check the protocol associated
  • Compare with the rules
  • Check the source and destination add. If protocol is same
  • Check out the port if protocol is TCP
  • Drop or pass the packet

Brief description

After declaring structure variables an integer type “countrule” is declared and initialized it holds the value of the number the rule, it is incremented when new rule is required. Filterlist is initialized to first, its size increases as more and more rules are added. Now the packet header is extracted and is assigned to the variable ipp. Next the protocol is checked.

If the protocol is numbered as 6 means it is TCP. We accept all the packets if the connection is already established. Also if we don't have the bit SYN activate then we pass the packet by using return PF_FORWARD.

Otherwise the packet is compared against the rules from the list until there is no member is in the list means till the condition while (aux! =NULL) persists. Now check if the protocol is same, if it is then look for the source and destination address and each time increment the countrule. Now it the protocol is TCP check for the port.

Now the decision can be taken whether to drop or pass the packet according to the following statements

If (aux->ipf.drop) 
    return PF_DROP; //drop the packet 
else 
    return PF_FORWARD; //forward the packet 

The same procedure is done for the packets of the UDP protocols. For other packet we don't look more and now we have decided what to do with the packet. After this countrule is incremented. And we accept all the packets which are not registered.

Here is the description of various classes/source files.

  • DrvFltIp.H - This file contains structure of the various headers that are being used in the TCP IP Protocol suite.
  • TDRIVER.H - This file contains the definition of the various method used to load, unload ,read and write into the driver. It also contains code for adding rules into the firewall
  • TDRIVER.CPP - This file contains various definition of the functions that are defined inside the TDriver class.
  • ADDRULEDLG.H - This file contains the definition of the various functions that are used for the checking whether the given IP address is in the valid format or not and is used for translating the user defined inputs into the driver readable format
  • AddRuleDlg.cpp : implementation file. This is the file that will contain the definition of the class functions that were defined in the AddRuleDlg.h header file
  • FIREVIEW.H - interface of the CFireView class
  • FIREVIEW.CPP - implementation of the CFireView class
  • Sockutil.h - This file contains the basic declarations of the functions that are used for the conversion of the network address into the internet address and for conversion of port numbers into comp readable format
  • SockUtil.CPP - Implementation of Sockutil.cpp
  • PortScanDlg.cpp - Implementation of port scanner.
  • StarWarsCtrl.cpp - Implementation of about dialog box in animated view.
  • SystemTray.cpp - Class for sending the firewall to system tray. taken from code project.

Points of Interest

I have written this program to share my Knowledge with you. I want you to do further work on it and help me to make it a successful open source project by mailing me back modified code. You can find more articles and software projects with free source code on my web site :-

You can also mail to me at sudhirmangla@hotmail.com or my partner in this project Mr. Rajender Singh. His email address is : rajenderdangwal@indiatimes.com

History

  • Date Posted: December 08, 2003

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

sudhirmangla

Web Developer

India India

Member

I am a B.E in Information Technology form Lingaya's Institute of Managemant and Technology Faridabad, India.
I has worked on VC++, MFC, VB, Sql Server. Currently I am working on .net, C# and ASP.net
I keeps my free source code projects and articles at website http://programmerworld.net

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmemberbenrabeh1:27 28 Apr '11  
GeneralIs phising possible through this? PinmemberMember 784813821:06 16 Apr '11  
General$ wine application.exe is giving to errors Pinmemberamit@iitg3:08 18 May '10  
Questionpacket filter driver Pinmembermanojqh18:41 12 Nov '09  
GeneralC#.Net 2005 Source code PinmemberWhite Scropion23:00 15 Feb '09  
GeneralRe: C#.Net 2005 Source code Pinmembericl7720:25 4 Apr '10  
Generalerror loading driver Pinmembersiddharth das18:20 1 Nov '08  
Generalerror loading driver Pinmembersuren_hisxlnc1:14 15 Oct '09  
Generalhttp://www.codeplex.com/netdefender PinmemberRiz Thon2:21 12 Sep '08  
Generaldemo of netdefender Pinmemberchandrika21112:23 26 Jan '08  
GeneralCopying Files across Firewall server PinmemberJan Palmer21:58 17 Apr '07  
GeneralPacket contents Pinmemberbandh9:33 27 Jun '06  
GeneralDRIVER_IRQL_NOT_LESS_OR_EQUAL error Pinmemberbandh20:40 9 Jun '06  
GeneralRe: DRIVER_IRQL_NOT_LESS_OR_EQUAL error Pinmemberbandh20:33 11 Jun '06  
QuestionWhat if we use Packet capture tools to build firewall [modified] Pinmemberbandh5:29 7 Jun '06  
We have freely available tools and libraries that capture packets for us e.g WinPcap etc. What if we use these tools to capture packet for us and we use the packet fields in our firewall to filter?With this without going into complexity of driver programing we can filter data contents too.
 
-- modified at 11:32 Wednesday 7th June, 2006
AnswerRe: What if we use Packet capture tools to build firewall Pinmemberspersyn11:22 21 Aug '06  
Generalunable to load or add rule PinmemberTim Zorn9:57 4 Apr '06  
GeneralRe: unable to load or add rule Pinmembersudhir mangla18:30 22 Jun '06  
Generalpacket accessing before send to the client Pinmemberkkvel18:31 20 Feb '06  
GeneralPacket Redirect PinsussAnonymous1:58 8 Oct '05  
Generalsetting rules on the fly Pinmemberwatevaman0:33 11 Jun '05  
Generalcontent based filter Pinmemberliqundu15:57 17 Aug '04  
GeneralRe: content based filter Pinmember1of311:58 30 Nov '04  
GeneralHowto debug Pinmembermumu_990:20 22 Jun '04  
GeneralShow information of packet (des ip, source ip,...) to interface???? Please help Pinmemberbaoiph6:03 16 Jun '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 27 Sep 2004
Article Copyright 2003 by sudhirmangla
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid