Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RAW Sockets - C# - Set Flags

Tags:

c#

sockets

I am trying to write an application that sends raw sockets in C#. I do not have a lot of experience in C/C++, so would prefer C#. I have found several options for raw sockets in C#, but none allow me to set the flags such as ACK, SYN, PSH, FIN, etc. Any ideas on if this can be accomplished in C#?

Any tips would be much appreciated.

Update: I am trying to write a tool to test a firewall, I would like to send out of state packets, packets with different flags. I am using Win 2008, and as far as I read, I can do raw sockets on it. I will resort to C/C++ if needed, and so far that is what it looks like.

Further Update: SharpPcap looks good, it seems v4.0 does not have source, only 3.5 does. I am going to try and muddle through it, as the documentation is not complete either. Has anyone used it before?

Final Edit: SharpPcap looks great! It is doing what I need!! I will post a follow up question, as I am not a .NET guru, it is capturing well, I just can't send a packet from in the capture delegate portion.

Thanks everyone!

like image 644
Loki Avatar asked Oct 09 '22 23:10

Loki


2 Answers

Check out SharpPcap.

According to the description:

SharpPcap is a cross-platform packet capture framework for the .NET environment, based on the famous pcap / WinPcap libraries. It provides an API for capturing, injecting, analyzing and building packets using any .NET language such as C# and VB.NET.

It internally uses the WinPcap driver, so it will allow you to build raw packets with your own IP/TCP headers.

like image 76
Ryan Stecker Avatar answered Oct 13 '22 10:10

Ryan Stecker


Short answer, on desktop versions of windows, you can't. From Wikipedia

When Microsoft released Windows XP in 2001 with raw socket support implemented in the Winsock interface, the media criticized Microsoft asserting that raw sockets are only of use to hackers to perform TCP reset attacks. Three years after the Windows XP release, Microsoft silently limited Winsock's raw socket support in a non-removable hotfix and offered no further support or workarounds for applications that used them.

like image 20
Erik Funkenbusch Avatar answered Oct 13 '22 10:10

Erik Funkenbusch