Click here to Skip to main content
11,702,130 members (64,707 online)
Click here to Skip to main content

Simple Packet - Filter Firewall

, 27 Sep 2004 300.2K 17.3K 128
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

sudhirmangla
Web Developer
India India
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

You may also be interested in...

Comments and Discussions

 
QuestionIs there has the source code of driver? Pin
hnwyllmm18-May-13 17:06
memberhnwyllmm18-May-13 17:06 
GeneralMy vote of 5 Pin
benrabeh28-Apr-11 1:27
memberbenrabeh28-Apr-11 1:27 
GeneralIs phising possible through this? Pin
Member 784813816-Apr-11 21:06
memberMember 784813816-Apr-11 21:06 
General$ wine application.exe is giving to errors Pin
amit@iitg18-May-10 3:08
memberamit@iitg18-May-10 3:08 
Questionpacket filter driver Pin
manojqh12-Nov-09 18:41
membermanojqh12-Nov-09 18:41 
GeneralC#.Net 2005 Source code Pin
White Scropion15-Feb-09 23:00
memberWhite Scropion15-Feb-09 23:00 
GeneralRe: C#.Net 2005 Source code Pin
icl774-Apr-10 20:25
membericl774-Apr-10 20:25 
Generalerror loading driver Pin
siddharth das1-Nov-08 18:20
membersiddharth das1-Nov-08 18:20 
Generalerror loading driver Pin
suren_hisxlnc15-Oct-09 1:14
membersuren_hisxlnc15-Oct-09 1:14 
Generalhttp://www.codeplex.com/netdefender Pin
Riz Thon12-Sep-08 2:21
memberRiz Thon12-Sep-08 2:21 
Generaldemo of netdefender Pin
chandrika211126-Jan-08 2:23
memberchandrika211126-Jan-08 2:23 
GeneralCopying Files across Firewall server Pin
Jan Palmer17-Apr-07 21:58
memberJan Palmer17-Apr-07 21:58 
GeneralPacket contents Pin
bandh27-Jun-06 9:33
memberbandh27-Jun-06 9:33 
GeneralDRIVER_IRQL_NOT_LESS_OR_EQUAL error Pin
bandh9-Jun-06 20:40
memberbandh9-Jun-06 20:40 
GeneralRe: DRIVER_IRQL_NOT_LESS_OR_EQUAL error Pin
bandh11-Jun-06 20:33
memberbandh11-Jun-06 20:33 
QuestionWhat if we use Packet capture tools to build firewall [modified] Pin
bandh7-Jun-06 5:29
memberbandh7-Jun-06 5:29 
AnswerRe: What if we use Packet capture tools to build firewall Pin
spersyn21-Aug-06 11:22
memberspersyn21-Aug-06 11:22 
Generalunable to load or add rule Pin
Tim Zorn4-Apr-06 9:57
memberTim Zorn4-Apr-06 9:57 
GeneralRe: unable to load or add rule Pin
sudhir mangla22-Jun-06 18:30
membersudhir mangla22-Jun-06 18:30 
Generalpacket accessing before send to the client Pin
kkvel20-Feb-06 18:31
memberkkvel20-Feb-06 18:31 
GeneralPacket Redirect Pin
Anonymous8-Oct-05 1:58
sussAnonymous8-Oct-05 1:58 
Generalsetting rules on the fly Pin
watevaman11-Jun-05 0:33
memberwatevaman11-Jun-05 0:33 
Generalcontent based filter Pin
liqundu17-Aug-04 15:57
memberliqundu17-Aug-04 15:57 
GeneralRe: content based filter Pin
1of330-Nov-04 11:58
member1of330-Nov-04 11:58 
GeneralHowto debug Pin
mumu_9922-Jun-04 0:20
membermumu_9922-Jun-04 0:20 
GeneralShow information of packet (des ip, source ip,...) to interface???? Please help Pin
baoiph16-Jun-04 6:03
memberbaoiph16-Jun-04 6:03 
GeneralRe: Show information of packet (des ip, source ip,...) to interface???? Please help Pin
Anonymous10-Aug-04 19:24
sussAnonymous10-Aug-04 19:24 
Generalintercept the packets Pin
drbelan6-Mar-04 8:42
memberdrbelan6-Mar-04 8:42 
GeneralVC++ DLL for VB developer Pin
KillerKing15-Dec-03 18:36
memberKillerKing15-Dec-03 18:36 
GeneralJust a suggestion Pin
Netcoder10-Dec-03 6:51
memberNetcoder10-Dec-03 6:51 
GeneralSource code of a firewall Pin
Anonymous13-Jul-05 8:13
sussAnonymous13-Jul-05 8:13 
Generalopen source project Pin
Sudhir Mangla9-Dec-03 16:47
sussSudhir Mangla9-Dec-03 16:47 
GeneralRe: open source project Pin
Alexander M.10-Dec-03 5:12
memberAlexander M.10-Dec-03 5:12 
GeneralRe: open source project Pin
pro11-Dec-03 13:57
memberpro11-Dec-03 13:57 
GeneralRe: open source project Pin
Alexander M.12-Dec-03 2:36
memberAlexander M.12-Dec-03 2:36 
GeneralRe: open source project Pin
Kel ®7-Jan-04 23:07
memberKel ®7-Jan-04 23:07 
GeneralRe: open source project Pin
Kel ®7-Jan-04 23:14
memberKel ®7-Jan-04 23:14 
GeneralRe: open source project Pin
wu11-Jan-04 17:14
memberwu11-Jan-04 17:14 
GeneralRe: open source project Pin
Carbonflux29-Jan-04 14:19
memberCarbonflux29-Jan-04 14:19 
GeneralRe: open source project Pin
foolzz8-Jun-04 16:25
memberfoolzz8-Jun-04 16:25 
Generalstoring rules in a plain file... Pin
gaamoa8-Dec-03 7:59
membergaamoa8-Dec-03 7:59 
GeneralRe: storing rules in a plain file... Pin
John M. Drescher8-Dec-03 9:14
memberJohn M. Drescher8-Dec-03 9:14 
GeneralRe: storing rules in a plain file... Pin
gaamoa8-Dec-03 11:11
membergaamoa8-Dec-03 11:11 
GeneralRight issue, wrong detail Pin
dog_spawn8-Dec-03 10:03
memberdog_spawn8-Dec-03 10:03 
GeneralRe: Right issue, wrong detail Pin
gaamoa8-Dec-03 11:16
membergaamoa8-Dec-03 11:16 
GeneralRe: Right issue, wrong detail Pin
dog_spawn8-Dec-03 11:47
memberdog_spawn8-Dec-03 11:47 
GeneralRe: storing rules in a plain file... Pin
sudhirmangla8-Dec-03 16:42
membersudhirmangla8-Dec-03 16:42 
GeneralUnable to add rule to driver Pin
John M. Drescher8-Dec-03 7:51
memberJohn M. Drescher8-Dec-03 7:51 
GeneralRe: Unable to add rule to driver Pin
sudhirmangla8-Dec-03 16:38
membersudhirmangla8-Dec-03 16:38 
GeneralRe: Unable to add rule to driver Pin
John M. Drescher8-Dec-03 17:13
memberJohn M. Drescher8-Dec-03 17:13 

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.

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