How to send a SYN packet using C # or Java

I want to send the SYN package to a remote host, now the problem is that if I use any of the .NET framework classes, then I can not do this; for example, a TCP client accepts a host number and port number and establishes a connection, similar to the case with the ClientSocket class in java.

I want to control the connection establishment myself; I want to say that I want to send a connection request (SYN packet), and then wait for the connection to respond and then send the packet. I know this can be tricky without external libraries, so if anyone can help me how to do this in C # or Java.,

+6
c #
source share
3 answers

Instead of commenting on both answers so far ... raw sockets have been limited on Windows with XP (countermeasures for malicious attacks). Read the following:

http://msdn.microsoft.com/en-us/library/ms740548(v=vs.85).aspx

After that, you can certainly create a raw socket, following your rules, based on the answer of Mat for Java or Ritch for C #.

It will be very limited and very system dependent anyway. I do not know a method for completing a three-way handshake and transmitting data over TCP / UDP (although I would be interested to hear it).

I thought I should make one quick amendment to this answer. If you are not using winsock and instead use a different TCP stack, you can probably get what you want (but this is still not directly accessible on the OS). Take a look at this as an example suggesting: http://www.komodia.com/tcpip-library-v5-1/ or this previous SO thread What is a popular, open source multi-platform free socket library

+2
source share

What you are looking for is called raw sockets. I do not know about C #, but there are Java libraries that allow you to do this, for example. RockSaw . As far as I know, you cannot do this using pure Java.

Please note that on some operating systems (at least Linux), you need administrator privileges to be able to open raw sockets. And on Windows, there are many limitations. (See the page I'm linked to.)

+2
source share

Use the Socket class with SocketType raw and the correct protocol type. I think you need TCP.

var sock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Tcp); 
+2
source share

All Articles