Search code examples
c#.netsharppcap

packet manipulation (dropping and altering)


I am writing a simple network security program in C#. For capturing the traffic in a network, I will use sharppcap library which can capture all the packets and display their details on the UI. However, I cannot find any methods in the library that can be used to drop any packets subjected to their port,source,destination or data content. Does Sharppcap support such kind of function? If not, will there be any library I can use?


Solution

  • The sharppcap library just provides a common API for packet interception and transmission. On Windows, you would probably be using WinPcap with sharppcap. On Windows, you cannot inspect and alter packets without writing a special kind of driver for the Windows packet filtering platform. That would also mean you would need to use C++ or C.

    WinPcap supports reading packets that arrive at the network card and also supports the transmission of raw data from the network card, which includes the capability of transmitting custom packets for debugging, security research, or developing tools to probe networks or what have you.

    The short answer is, no sharppcap does not support this and you will need to make your own driver. If you can move away from Windows, you can set up a dedicated hardware firewall with a custom interceptor written in C in under one day if you go with a Linux distribution like Debian or Arch Linux.

    If you decide to stick with Windows, you will also be in for a nasty surprise during times when your load is near 50% of the network card capabilities. Windows will stop forwarding to the network filtering stack under significant load, to improve performance. I noticed that on a gigabit network card under about 200 mbit/sec, WinPcap wasn't seeing even 5% of all packets. To test this, I used a dedicated capture device that sat between the switch and the machine being tested. The capture device can capture at line speed and the remote machine can as well, but the network filtering stack on Windows does not.