Click here to Skip to main content
Click here to Skip to main content

Developing Firewalls for Windows 2000/XP

By , 3 Nov 2003
 
Prize winner in Competition "MFC/C++ Nov 2002"
Sample Image

Introduction

If you decide to develop a firewall for Linux, you will find a lot of information and source code, all free. However, people interested in a firewall for Windows platforms have a little more difficulty, not only with finding information, as finding free source code is a task almost impossible!! So, I decided to write this article that describes a simple method for developing firewalls for Windows 2000/XP to help people interested in this subject.

Background

In the Windows 2000 DDK, Microsoft includes a new type of network driver denominated Filter-Hook Driver. With it, you can establish a function to filter all traffic that arrives/leaves the interfaces. Because the documentation about this topic is small and doesn't include samples, I write in this article the steps needed to use it successfully. I hope this article will help you to understand this easy method.

The Filter-Hook Driver

As I said before, the Filter-Hook Driver was introduced by Microsoft in the Windows 2000 DDK. In fact, it is not a new network driver class; it is only a way to extend IP Filter Driver (included with Windows 2000 and ¿later?) functionality. In fact, Filter-Hook Driver isn't a Network driver; it is a Kernel Mode Driver. Basically, in this Filter-Hook Driver, we implement a callback function and then we register this callback with the IP Filter Driver. When we do this, the IP Filter Driver calls our callback function when a packet has been sent or received. Then... what are the main steps to do this? We can summarize them in the following steps:

  1. Create a Filter-Hook Driver. For this, you must create a Kernel Mode Driver. You choose the name, DOS name and other driver characteristics, nothing obligatory but I recommend using descriptive names.
  2. If we want to install the filter function, first we must get a pointer to IP Filter Driver. So, It will be the second step.
  3. We already have the pointer, so now we can install the filter function. We can do it by sending a specific IRP. The data passed in this "message" includes a pointer to the filter function.
  4. Filtering packets!!!!
  5. When we decide to finish filtering, we must deregister the filter function. We can do it by "registering" as a filter function the null pointer.

Oh, oh, five steps only and it seem very easy, but... how can I make a Kernel mode driver? How can I get a pointer to the IP Filter Driver? How can I ..... yessssssss, one moment please, I will explain all these steps now :P, showing the source code sample.

Create the Kernel Mode Driver

Filter-Hook driver is a Kernel Mode Driver, so if we want to do one, we have to make a Kernel Mode Driver. This article isn't a "How to develop Kernel Mode drivers in 5 minutes" guide, so I assume that the reader has some knowledge on the subject. The structure of the Filter-Hook driver is the typical Kernel Mode Driver structure:

  1. A driver entry where we create the device, set the standard routines in order to process IRPs (Dispatch, load, unload, create....) and create the symbolic link for communication with user applications.
  2. The standard routines to manage IRPs. Before you begin to code, I recommend, think what IOCTL you "export" to applications from a device driver. In my sample, I implement four IOCTL Codes: START_IP_HOOK (registers the filter function), STOP_IP_HOOK (deregisters the filter function), ADD_FILTER (installs a new rule) and CLEAR_FILTER (frees all rules).
  3. For our driver, we must implement one more function: the filter function.

I recommended you to use a program that generates the structure of a Kernel Mode Driver, so you only have to put code into the generate functions. For example, I have used QuickSYS in this project. You can see my own implementation of the structure of the Driver in the following code:

NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, 
                IN PUNICODE_STRING RegistryPath)
{

    //....

    dprintf("DrvFltIp.SYS: entering DriverEntry\n");

    //we have to create the device
    RtlInitUnicodeString(&deviceNameUnicodeString, NT_DEVICE_NAME);

    ntStatus = IoCreateDevice(DriverObject,
                0,
                &deviceNameUnicodeString, 
                FILE_DEVICE_DRVFLTIP,
                0,
                FALSE,
                &deviceObject);



    if ( NT_SUCCESS(ntStatus) )
    { 
        // Create a symbolic link that Win32 apps can specify to gain access
        // to this driver/device
        RtlInitUnicodeString(&deviceLinkUnicodeString, DOS_DEVICE_NAME);

        ntStatus = IoCreateSymbolicLink(&deviceLinkUnicodeString, 
                                        &deviceNameUnicodeString);

        //....

        // Create dispatch points for device control, create, close.

        DriverObject->MajorFunction[IRP_MJ_CREATE]         =
        DriverObject->MajorFunction[IRP_MJ_CLOSE]          =
        DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DrvDispatch;
        DriverObject->DriverUnload                         = DrvUnload;
    }

    if ( !NT_SUCCESS(ntStatus) )
    {
        dprintf("Error in initialization. Unloading...");
        
        DrvUnload(DriverObject);
    }

    return ntStatus;
}

NTSTATUS DrvDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{

    // ....

    switch (irpStack->MajorFunction)
    {
    case IRP_MJ_CREATE:

        dprintf("DrvFltIp.SYS: IRP_MJ_CREATE\n");

        break;

    case IRP_MJ_CLOSE:

        dprintf("DrvFltIp.SYS: IRP_MJ_CLOSE\n");

        break;

    case IRP_MJ_DEVICE_CONTROL:

        dprintf("DrvFltIp.SYS: IRP_MJ_DEVICE_CONTROL\n");

        ioControlCode = irpStack->Parameters.DeviceIoControl.IoControlCode;

        switch (ioControlCode)
        {
        // ioctl code to start filtering
        case START_IP_HOOK:
        {
            SetFilterFunction(cbFilterFunction);

            break;
        }

        // ioctl to stop filtering
        case STOP_IP_HOOK:
        {
            SetFilterFunction(NULL);

            break;
        }
        
        // ioctl to add a filter rule
        case ADD_FILTER:
        {
            if(inputBufferLength == sizeof(IPFilter))
            {
                IPFilter *nf;

                nf = (IPFilter *)ioBuffer;
                
                AddFilterToList(nf);
            }

            break;
        }

        // ioctl to free filter rule list
        case CLEAR_FILTER:
        {
            ClearFilterList();

            break;
        }

        default:
            Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;

            dprintf("DrvFltIp.SYS: unknown IRP_MJ_DEVICE_CONTROL\n");

            break;
    }

        break;
    }


    ntStatus = Irp->IoStatus.Status;

    IoCompleteRequest(Irp, IO_NO_INCREMENT);

    // We never have pending operation so always return the status code.
    return ntStatus;
}


VOID DrvUnload(IN PDRIVER_OBJECT DriverObject)
{
    UNICODE_STRING deviceLinkUnicodeString;

    dprintf("DrvFltIp.SYS: Unloading\n");

    SetFilterFunction(NULL);

    // Free any resources
    ClearFilterList();
   
    // Delete the symbolic link
    RtlInitUnicodeString(&deviceLinkUnicodeString, DOS_DEVICE_NAME);
    IoDeleteSymbolicLink(&deviceLinkUnicodeString);

    
    // Delete the device object
    IoDeleteDevice(DriverObject->DeviceObject);
}

We have already made the driver main code, so we follow with code of the Filter-Hook Driver.

Registering a Filter Function

In the above code, you have seen a function called SetFilterFunction(..). I implemented this function to register a function in the IP Filter Driver. I will describe the steps followed:

  1. First, we must get a pointer to the IP Filter Driver. This requires that the driver be installed and executed. My user application loads and starts IP Filter Driver before loading this driver, in order to assure this.
  2. Second, we must build an IRP specifying IOCTL_PF_SET_EXTENSION_POINTER as IO Control Code. We must pass as a parameter a PF_SET_EXTENSION_HOOK_INFO structure that has information about the pointer to filter function. If you want to uninstall the function, you have to follow the same steps, but passing NULL as the pointer to filter function.
  3. Send the build IRP to the device driver.

Here there is one of the bigger problems of this driver. Only one filter function can be installed, so if other applications installed one, you can't install your function. I will show in the following lines the code of this function:

NTSTATUS SetFilterFunction
            (PacketFilterExtensionPtr filterFunction)
{
    NTSTATUS status = STATUS_SUCCESS, waitStatus=STATUS_SUCCESS;
    UNICODE_STRING filterName;
    PDEVICE_OBJECT ipDeviceObject=NULL;
    PFILE_OBJECT ipFileObject=NULL;

    PF_SET_EXTENSION_HOOK_INFO filterData;

    KEVENT event;
    IO_STATUS_BLOCK ioStatus;
    PIRP irp;

    dprintf("Getting pointer to IpFilterDriver\n");

    //first of all, we have to get a pointer to IpFilterDriver Device
    RtlInitUnicodeString(&filterName, DD_IPFLTRDRVR_DEVICE_NAME);
    status = IoGetDeviceObjectPointer(&filterName,STANDARD_RIGHTS_ALL, 
                                    &ipFileObject, &ipDeviceObject);

    if(NT_SUCCESS(status))
    {
        //initialize the struct with functions parameters
        filterData.ExtensionPointer = filterFunction;

        //we need initialize the event used later by 
        //the IpFilterDriver to signal us
        //when it finished its work
        KeInitializeEvent(&event, NotificationEvent, FALSE);

        //we build the irp needed to establish fitler function
        irp = IoBuildDeviceIoControlRequest(IOCTL_PF_SET_EXTENSION_POINTER, 
                                                            ipDeviceObject,
        if(irp != NULL)
        {
            // we send the IRP
            status = IoCallDriver(ipDeviceObject, irp);

            //and finally, we wait for 
            //"acknowledge" of IpFilter Driver
            if (status == STATUS_PENDING) 
            {
                waitStatus = KeWaitForSingleObject(&event, 
                                Executive, KernelMode, FALSE, NULL);

                if (waitStatus != STATUS_SUCCESS ) 
                    dprintf("Error waiting for IpFilterDriver response.");
            }

            status = ioStatus.Status;

            if(!NT_SUCCESS(status))
                dprintf("Error, IO error with ipFilterDriver\n");
        }

        else
        {
            //if we cant allocate the space, 
            //we return the corresponding code error
            status = STATUS_INSUFFICIENT_RESOURCES;

            dprintf("Error building IpFilterDriver IRP\n");
        }

        if(ipFileObject != NULL)
            ObDereferenceObject(ipFileObject);

        ipFileObject = NULL;
        ipDeviceObject = NULL;
    }

    else
        dprintf("Error while getting the pointer\n");

    return status;
}

You can see that when we finish the process of establishing the filter function, we must de-reference the file object obtained when we get a pointer to the device driver. I use an event to be notified when IpFilter Driver finishes the processes of the IRP.

The Filter Function

We have seen how we can develop the driver and how to install the filter function, but we don't know anything about this function yet. I already said that this function is always called when the host receives or sends a packet. Depending on the return value of this function, the system decides what to do with the packet. The prototype of this function must be:

typedef  PF_FORWARD_ACTION 
(*PacketFilterExtensionPtr)(
  // Ip Packet Header
  IN unsigned char *PacketHeader,
  // Packet. Don't include Header 
  IN unsigned char *Packet, 
  // Packet length. Don't Include length of ip header
  IN unsigned int PacketLength, 
  // Index number for the interface adapter 
  //over which the packet arrived    
  IN unsigned int RecvInterfaceIndex, 
  // Index number for the interface adapter 
  //over which the packet will be transmitted
  IN unsigned int SendInterfaceIndex,    
  //IP address for the interface 
  //adapter that received the packet
  IN IPAddr RecvLinkNextHop,
  //IP address for the interface adapter 
  //that will transmit the packet  
  IN IPAddr SendLinkNextHop 
  ); 

PF_FORWARD_ACTION is an enumerated type that can value (in Microsoft Words):

  • PF_FORWARD

    Specifies for the IP filter driver to immediately return the forward response to the IP stack. For local packets, IP forwards them up the stack. If the destination for packets is another computer and routing is enabled, IP routes them accordingly.

  • PF_DROP

    Specifies for the IP filter driver to immediately return the drop response to the IP stack. IP should drop the packet.

  • PF_PASS

    Specifies for the IP filter driver to filter packets and return the resulting response to the IP stack. How the IP filter driver proceeds to filter packets is determined by how it was set with the Packet Filtering API. The filter hook returns this pass response if it determines that it should not process the packet, but should allow the IP filter driver to filter the packet.

Although DDK documentation only includes these 3 values, if you look into pfhook.h (include needed for Filter-Hook Driver), you can see one more. This value is PF_ICMP_ON_DROP. I suppose this value corresponds with dropping the packet and informing source for errors with an ICMP packet. As you can see in the definition of the filter function, the packet and its header are passed as pointers. So, you can modify header or payload and then forward the packets. This is very useful, for example, to do Network Address Translation (NAT). If we change destination address, IP routes the packets. In my implementation, the filter function compares each packet with a list of rules introduced by the user application. This list is implemented as a linked list that is built in runtime with each START_IP_HOOK IOCTL. You can see this in my source code.

The Code

In the first version of this article, I included a simple example and -- because some people requested me to help them to develop real applications -- I updated it with a more complex one. The new example is a little packet filtering application. With this new program, you can establish your filter rules as you can do in some commercial firewalls. As the first version, this application has two components:

  • User Application: it's an MFC application that manages the filter rules. This application sends the rules to the application and decides when the driver must begin to filter. Three steps for filtering the traffic:
    • Define the rules you need. With the Add and Delete commands, you can add or delete filter rules.
    • Install Rules. When you define the rules, click the install button to send them to the driver.
    • Start Filtering. You only have to click the start button in order to begin filtering.
  • Filter-Hook Driver: Driver that filter IP Traffic based in the filter rules received from the user application.

The Filter-Hook Driver must be in the same directory as the user application executable.

Why Use this Method to Develop a Firewall?

It isn't the unique method to developing firewalls for Windows. There are others such as NDIS Firewall, TDI Firewall, Winsock Layered Firewall, Packet Filtering API,.... so I will mention some advantages and disadvantages of Filter-Hook Driver in order for you to decide if your future firewall must use this driver.

  • You have much flexibility filtering with this method. You can filter all IP traffic (and above). However, you can't filter lower layer headers. For example, you can't filter Ethernet frames. You need an NDIS filter to do that, which is more complicated to develop but more flexible.
  • It is an easy method. Installing a firewall and implementation of the filter function are easy procedures with this method. However, the Packet Filtering API is more easy yet, although it is less flexible. You can't access packet content and you can't modify this with Packet Filtering API.

Result: Filter-Hook Driver isn't the best in anything, but it hasn't any bad characteristics. However, why is this method not used in commercial products? The answer is simple. Although this driver hasn't any bad characteristics, it has a great disadvantage, too. As I mentioned before, only one filter function can be installed each time. We can develop a great firewall and it can be downloaded and installed by thousands of users, but if other applications use this filter (and installed the filter function before) our program won't do anything.

This method has another disadvantage not documented by Microsoft. Although DDK documentation says that you can access packet content in a filter function, it's not real. You can access packet content for received packets, but for sent packets you can only read IP and TCP, UDP or ICMP headers. I don't understand why... Microsoft introduced another type of driver without this limitation in Windows XP: the firewall-hook driver. Its installation is very similar, but Microsoft doesn't recommend its use because "it ran too high in the network stack." Maybe this driver will disappear in later Windows versions.

Conclusion

Ok, this is the finish. I know this is not the best method for developing firewalls (I mentioned the great disadvantage before), but I think this is a good beginning for interested people who are searching for information, or for people who are interested now. I hope you understood something and that you want to develop a great firewall now.

History

  • 21 December, 2002 -- Original version posted
  • 4 November, 2003 -- Update

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jesus Oliva
Chief Technology Officer
Spain Spain
To summarize: learn, learn, learn... and then try to remember something I.... I don't Know what i have to remember...
 
http://www.olivacorner.com

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionhelp needed in running the applicationmemberRamyaSankaralingam7-Mar-12 18:18 
how to install the rules in this application. do we need only windows 2000 or it can run in windows xp ? please reply
GeneralWin7 - Error loading the drivermemberSandalopalo19-Mar-10 6:21 
Hi,
 
Thanks for this article, its really helpfull.
The program works fine on Windows XP, but on Windows 7 it says: Error loading the driver.
I have tried everything: run the program as admin, compatible mode with XP, etc., but nothing.
 
Could u give me some help about that?
 
Thanks
Jorge
GeneralError path not found when starting the drvfltip.sysmembersuren_hisxlnc28-Sep-09 20:32 
Hey Jess,
 
Thanks for this application,
 
But I found some problem, which needs ur help to solve.
 
I have used ur application to build a firewall.
 
I am, using Windows Xp service pack 2 with Visual Studio 2005 express edition.
 
On my system the StartService() function on line 511 in TDriver.cpp fails with error code 3(ERROR_PATH_NOT_FOUND).
 
Can I know what is going wrong, so that the system is not able to find the path.
 
Once i started encountering this error , I tried just running ur application which also started failing and StartService() function in returning ERROR_PATH_NOT_FOUND.
 

I have some things or observations or queries to share with u
 
1. Should I need to unload any thing before loading next time
2. I am changing the filter conditions on run time, in my application is it allowed(or is this the culprit??)
3. I found that on a fresh system where my application never installed, things works fine, but on same system,on later run this loading fails.
 
I am ready to give u any other inputs related to this problem
 

Please help me in this regard,
 
Suren
GeneralOnly one Filter workmemberpku200925-Dec-08 19:00 
I find that it only works in this case:
 
Source IP.0.0.0, Port, IP Mask: 255.255.255.255
 
Destination IP .0.0.0, Port, IP Mask: 255.255.255.255 (this rule drop all,but it's not I want)
 
Other case such as
 
Source IP:192.168.1.8, Port, IP Mask: 255.255.255.0
 
Destination IP :58.61.158.71.0.0.0, Port, IP Mask: 255.0.0.0 (this rule dosen't work)
 
it doesn't work. Why?? Who know? Thanks!
 
今天没有时间,以后再写吧。

GeneralRe: Only one Filter workmemberapokryphus1-May-09 10:44 
I am also facing the same problem. But in my case, it doesn't work even for the case that pku2009 mentioned. Please help!!!
GeneralRe: Only one Filter workmember-80526-Aug-09 22:43 
hi,
 
whenever i try to build the project i get errors.
 
it seems you could build that. im using visual c++ 2008 under win xp.
 
i think my biggest problem is, that i dont know what includes are needed. when i try to build the sourcecode from this side i only get errors.
 
can you help me?
 
thx.
 
chris
GeneralRe: Only one Filter workmemberMember 239171429-Apr-10 11:01 
Destination IP :58.61.158.71.0.0.0
----
Possibly becouse line-of-numbers-with-dots is not an IP4 or IP6
QuestionFilter comparision [modified]memberbvboca4-Aug-08 15:36 
if(((tcph->flags & TH_SYN) != TH_SYN) || ((tcph->flags & (TH_SYN | TH_ACK)) == (TH_SYN | TH_ACK))){
if((ipp->destination & aux->ipf.sourceMask) == aux->ipf.sourceIp)
{
retTraffic = TRUE;
}
}
 
I can't make it out,what does retTraffic mean here?
 
modified on Monday, August 4, 2008 9:48 PM

AnswerRe: Filter comparisionmemberprashu10018-Aug-09 7:04 
That variable acts as flag to differentiate already established connections.
GeneralRe: Filter comparisionmember-80526-Aug-09 22:44 
hi,
 
whenever i try to build the project i get errors.
 
it seems you could build that. im using visual c++ 2008 under win xp.
 
i think my biggest problem is, that i dont know what includes are needed. when i try to build the sourcecode from this side i only get errors.
 
can you help me?
 
thx.
 
chris
Questionis this method(filter hook driver) can implemented on pocket pc programming?memberkura2lincah6-Jul-08 17:26 
i want to know, is this method can implemented on pocket pc programming.
as far i know about firewall programming in pocket pc:
1. NDIS firewall, it can be used in pocket pc.
2. TDI firewall, i still don't know
3. Winsock Layered Firewall, it can't be implemented, coz pocket pc don't support this
 
if filter hook driver can implemented in pocket pc, please give me example or source code how to make firewall in pocket pc through this method..
 
and, anybody know, where i can get clearly explained example about NDIS firewall for pocket pc? i have been searching, but until now, i still don't get good source code.
 
thank..
 
ilyanto nova radikiya

GeneralHolamembermanuelp2515-Apr-08 15:46 
Buenas noches Compañero….
 
Cordial saludo….
 
El presente tiene como objetivo felicitarlo por el magnifico trabajo que realizo con el FIREWALL PAPI… me parece muy interesante….
 
A demás me gustaría saber si usted es tan amable y me dice como podría cambiar el idioma de las opciones a español, como usted bien sabe la aplicación no permite modificaciones.
 
Gracias por su atención……
 
Manuel Pretelt.
manuelp25@gmail.com
GeneralRe: HolamemberEmployMen12-Jun-08 4:00 
Hello,
 
You can get a "Multilanguage" version in http://www.sourceforge.net/projects/firewallpapi
QuestionWhat about filtering IPv6 packets on win XPmemberAther Zaidi9-Apr-08 5:00 
Hi, thanks for the article.
I want to filter IPv6 traffic flowing into and out of my machine, filter it on the basis of source destination prefixes , next headers, ports, protocols etc.
I have used some network traffic sniffers to read the information from IPv6 packets that land up on my machine.
Now i am locking for ways of filtering or blocking that traffic
QuestionHow to get the process involved in the communicationmemberMember 165763325-Feb-08 1:04 
Hi,
 
Just wanted to know how would i get the process id of the process that is trying to send or receive the packet, further more is there any way to determine ports that are in listening state.
 
Thanks in advance,
Hassaan
AnswerRe: How to get the process involved in the communicationmemberprashu10018-Aug-09 7:12 
If that is ur requirement then TDI would be better.
Generalrunning in WinServer 2003memberMember 38859661-Jan-08 0:38 
I compiled the source code in Vc++ 2005. The executable file created in Debug folder that is running in WinXP well. But this file doesn't work in WinServer 2003 and gives this message "this program can't start because it has been configured incorrectly ....."
 
But when I extract downloaded folder, "firewall.exe" can be installed on WinServer 2003 without any problem and runs very well.
 
Can anyone please help me and advise me which configurations are required so that I can install and run the executable file created in Debug folder on WinServer 2003?
GeneralRe: running in WinServer 2003memberarr2arr1arr25-Jul-09 15:53 
That happened to me before... its because you can't run a debug version in a machine that hasn't the debug runtime libraries installed (them are installed with Visual Studio for example)
 
Just compile it in Release mode
 
I hope that helps!
Questionsome questionmemberMember 388596610-Dec-07 2:31 
Dear Jess O
 
I studied your article. I has some questions and much appreciate to help me in this regard.
1- what is the file name related to the filter-hook driver, in the source codes?
2- there is no file named Pfhook.h in my PC. as I know it's requested by filter-hook driver. how the filter-hook driver works without that file?
3- have you used "packet filtering API" in this application? if yes, where?
 
your prompt reply would be highly appreciated.
Best Regards
Yashar
Questionsome questionsmemberMember 388596610-Dec-07 2:27 
Dear Jess O
 
I studied your article. I has some questions and much appreciate to help me in this regard.
1- what is the file name related to the filter-hook driver, in the source codes?
2- there is no file named Pfhook.h in my PC. as I know it's requested by filter-hook driver. how the filter-hook driver works without that file?
3- have you used "packet filtering API" in this application? if yes, where?
 
your prompt reply would be highly appreciated.
Best Regards
Yashar
QuestionBlock domain names instead of IP addresses?memberxxin221-Nov-07 7:49 
Hello,
 
Thanks for sharing your great work!
 
Somewhat we need to block requests to a domain name but not all the requests to an IP address. Do you have any suggestions?
 
Thanks again.

GeneralProblem with header filememberchabry29-Jan-07 5:16 
Hi,
 
Congratulation for the quality of your project, I've downloaded it to know how we can implement a firewall on windows OS.
But I have a pb:
I'm working with MS Visual C++ Express Edition 2005 and each time I want to Build the solution, I find these errors:
 
---- Build started: Project: FirewallApp, Configuration: Debug Win32 ------
Compiling...
StdAfx.cpp
d:\chahir\cours\projet\firewallfhk_src\stdafx.h(15) : fatal error C1083: Cannot open include file: 'afxwin.h': No such file or directory
Creating browse information file...
Microsoft Browse Information Maintenance Utility Version 8.00.50727
Copyright (C) Microsoft Corporation. All rights reserved.
BSCMAKE: error BK1506 : cannot open file '.\debug\FirewallAppDoc.sbr': No such file or directory
Build log was saved at "file://d:\Chahir\cours\projet\FirewallFHK_src\Debug\BuildLog.htm"
FirewallApp - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 
Thanks a lot.;)
GeneralRe: Problem with header filemembermugman2121-Feb-07 0:16 
Visual studio 05 express does not support MFC.
GeneralRe: Problem with header filememberchabry26-Feb-07 5:05 
thank you,
I moved to Visual Studio 6.I can compile the program and see the MFC interface but I can't block port, I tryed to block the HTTP port(80) but I still be able to conect to internet.When I run the program, I have this message "The terms of the End User License User Agreement for Visual C++ Introductory Edition do not permit redistribution of executables you create withe this Product".It can be the reason of this problem
I haven't changed anything in the code but It cant to apply added rules.
Help.Frown | :(
Generalspinlocksmemberdiablo30004-Dec-06 19:24 
To variable "first" ,why not use spinlocks?

GeneralRange for Port Filteringmemberkaukau29-Jun-06 22:34 
How can i modify the code to able to filter a range of port (ex.port 1024-5699)...not only one single port for every rule input? Confused | :confused:
 
thanx
GeneralNeed guide developing this firewall applicationmemberkaukau19-May-06 8:15 
Anyone who has already downloaded the source code and able to make it work...please help me on this...i'm trying to develop this firewall application for my acedemic project and i'm lost Confused | :confused: ...anyone who can help me on this please e-mail me at : ellow_lin@yahoo.com
 
PS.Urgently needed help on this...PLZ Dead | X|
 
regards,
lina lee
JokeRe: Need guide developing this firewall applicationmemberprashu10019-Feb-09 23:00 
if u can't make it work,forget developing firewall Big Grin | :-D
GeneralDriver fails to get the IpFilterDriver ptrmemberteit25-Aug-05 2:58 
Hello.
The subject pretty much describes my problem, when the driver is called with the IOCTL START_IP_HOOK (or STOP_IP_HOOK) the SetFilterFunction allways fails at the same place:
"Getting pointer to IpFilterDriver" - "Error while getting the pointer". I've tried to solve this, but from what I've read on MSDN I can't find anything wrong with the source code. I'm using a computer running Windows XP professional with SP2 to test the driver. I could really use some help because I'm stuck.
 
Thanks in Advance
 
/Teit
GeneralRe: Driver fails to get the IpFilterDriver ptrmemberingtabby26-Jan-06 3:45 
i have the same problem..
help!!!!
 
thanks!
 
francesco
GeneralRe: Driver fails to get the IpFilterDriver ptrmemberboolman26-Jan-06 6:16 
You must load the IpFilterDriver from your control-program before you attempt to load your own filter driver. I thought that it was enough to make sure that it was loaded and running on the system, but it isn't. You must first load it from the process that will attempt to load your own driver. See the example control program, that will show you how it's done.
GeneralRe: Driver fails to get the IpFilterDriver ptrmemberingtabby26-Jan-06 7:45 
thanks a lot! now it works! but at the end of my application i must unload ipfilter too or i must keep it loaded?

GeneralRe: Driver fails to get the IpFilterDriver ptrmemberboolman26-Jan-06 9:19 
I'm keeping IpFilterDriver loaded when my application terminates, I just uninstall my filter driver. It hasn't caused me any problems, so obviously that works. I'm not sure if this is the right thing to do though.
GeneralRe: Driver fails to get the IpFilterDriver ptrmemberchabry26-Feb-07 5:10 
Hi,
 
How can I load the IpFilterDriver on my PC(XP SP2).
 
Thank you.
Sigh | :sigh:
GeneralRe: Driver fails to get the IpFilterDriver ptrmembernoobvb21-Jun-07 7:30 
easy, in console screen (cmd) simple typing following line
net start ipfilterdriver
In the console screen will show something like this : "The IP Traffic Filter Driver service was started successfully"
To stop it just typing: net stop ipfilterdriver
 
Thank all!

QuestionPort blocking in Win98?memberSPartha2-May-05 3:46 
Hi great article..
But is there any way to programatically block tcp and udp ports in win 98 machines?
 
Thnx in advance,
Partha .S
AnswerRe: Port blocking in Win98?memberALS Markus2-Nov-05 11:58 
Yes there is. Look at "Packet Filtering" under Remote Access Service in the Platform SDK or MSDN. IP Helper is also required. There are simple interfaces to set udp, tcp, or icmp filters to single or multiple network adapters, dial-up or ethernet type.
 
IP helper is needed for some of the structures it usesSmile | :) .
 
May be under "Routing and Remote Access - IP filters"
 
There are examples on the codeproject.com using this method.
 
Can't access packets directly with this but it is very easy to implement and
you can add many thousands of rules to the filter.
Smile | :)
QuestionDestroy IP PacketmemberRedaemon21-Dec-05 5:39 
If using the IP filters, can we dismiss the packet so that the packet, not continue to the internet. Because i try to develop new net cafe billing (not like ordinary use time limit, but use packet size limit). To know the packet size i use sniff methods (and it works), but then came a problem that if a client have reach the packet quota (for example down and up rate only 2 gigs) i want to dismiss the client request packet. So if we dismiss the packet that need access to internet, then it will not interrupt the client for accessing intranet (because if we close the TCP/IP port then all will be blocked not only internet access but also intranet access too).
 
Thanks
GeneralProblem with firewallmemberdarsh1_kool1-Apr-05 6:55 
I do have a problem while executing the firewall given by Jesús O which uses Filter Hook Driver.
 
The error msg is "Error loading the driver."
 
I dont know what to do with this.
can anyone please help me with this?
 
Darshan
GeneralRe: Problem with firewallmemberALS Markus2-Nov-05 11:28 
Copy the .sys file to your app directory for the driver to load.
GeneralRe: Problem with firewallmemberBlaster Man4-Jul-07 10:07 
I have the same problem...Copy sys file dont solve my problem.. other idea?
 
Tks..
GeneralRunning this drivermemberaggarwaa20-Mar-05 17:18 
Hello,
First I would like to thank you for such a wonderful article. I was trying to run this driver.
I have compiled this driver using DDK and all contents are in one folder e.g. 'FilterHook' I have the testDrv (Application MFC) in the same folder as well. My question to you now is "what else do I need to do to start this driver application?" Could you please give me step by step instructions as how to run this driver? Do i need the Ip Filter Driver running first?
 
I ll be very grateful to you for your kind help.
 


 
Ankit
Questionis this method good for syncache?memberk_oyot7-Mar-05 2:51 
Hi!
I want to develop syncache (or syncookie) driver in win2003. Is filter-hook sufficient for this task (dropping syn packets and create fully established connection on syn,ack packet) or should i try different approach ?
 
koyot
GeneralCTL function codememberabhinay_nag22-Feb-05 5:13 
Dear J olivia, how did you determine that the function code of the driver was 0x830? and the driver type 0x00654322?
 
abhi
GeneralRe: CTL function codemembernoobvb8-May-07 12:51 
yah, I wonder too...What happen to it if we change that value to other? Driver can't load...But why must we choose this value?
 
Thank you!

Questionimplement the drop function modifying winpcap?memberorguss17-Feb-05 22:19 
I want to implement the capture, the sending and the drop together.
But, WinPcap don't support the drop fucntion.
I want to add the drop fucntion to WinPcap.
Can I develop the new version of winpcap modifying the old version of winpcap?
Do you think that this idea is possible?
 
I don't know well...
Thanks...
Generalstack locationmemberfirstx6-Feb-05 9:25 
hi
 
do someone know where in network stack is this driver ?
 
soory for my english Smile | :)
QuestionHow can the Filter modify a packet?memberChuaaico19-Jan-05 17:59 
Here is the interface of a filter function
 
typedef PF_FORWARD_ACTION
(*PacketFilterExtensionPtr)(
IN unsigned char *PacketHeader,
IN unsigned char *Packet,
IN unsigned int PacketLength,
IN unsigned int RecvInterfaceIndex,
IN unsigned int SendInterfaceIndex,
IN IPAddr RecvLinkNextHop,
IN IPAddr SendLinkNextHop
);
 
If I want to modify a packet and then want to pass it IP Filter, is it correct if I do as follows:
 
1. Modify data referenced by *Packet
2. Return PF_PASS
 
After that the IP Filter will get the modified data from *Packet.
 
Sorry for my poor English
 
Thank you
AnswerRe: How can the Filter modify a packet?memberJesús O.4-Feb-05 11:30 
Hi,
 
Sorry a filter hook driver isn't design to modify packets. If you want to implement this funcionality you have to use another method.
 
Regards,
 
Jesus O.
 
Website: www.txakynetwork.com .

GeneralRe: How can the Filter modify a packet?sussAnonymous31-Jul-05 23:10 
can you please specifie possible méthods to do that

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130619.1 | Last Updated 4 Nov 2003
Article Copyright 2002 by Jesus Oliva
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid