Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Raw Sockets Port Forwarding

I am trying to create a simple C# app which does port forwarding, and need to know how to use the IP_HDRINCL socket option to try to fake out the receiving end to think the connection is really to the source. Any examples would be greatly appreciated.

like image 498
Superman Avatar asked Jan 24 '23 20:01

Superman


1 Answers

sock = new Socket( AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP );
sock.Bind( new IPEndPoint( IPAddress.Parse( "10.25.2.148" ), 0 ) );
sock.SetSocketOption( SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1 );   
byte[] trueBytes = new byte[] { 1, 0, 0, 0 };
byte[] outBytes = new byte[] { 0, 0, 0, 0 };
sock.IOControl( IOControlCode.ReceiveAll, trueBytes, outBytes );
sock.BeginReceive( data, 0, data.Length, SocketFlags.None, new AsyncCallback( OnReceive ), null );

The only problem is that I've been able to successfully receive data from a raw socket like this, (including the IP header) but not send it.

like image 163
dviljoen Avatar answered Jan 30 '23 08:01

dviljoen