C # Raw Sockets Port Forwarding

I am trying to create a simple C # application that does port forwarding, and you need to know how to use the socket parameter IP_HDRINCL to try to fake the receiving side to think that the connection is really from the source. We will be very grateful for any examples.

+3
source share
4 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 was able to successfully receive data from a raw socket like this (including the IP header), but not send it.

+4
source

- , .

MSDN

Windows 7, Windows Vista Windows XP 2 (SP2), :

  • TCP .
  • UDP- . IP- UDP- . , " " (TCP/IP- IP- ).
  • IPPROTO_TCP . (IPPROTO_IP, IPPROTO_UDP IPPROTO_SCTP, .

Windows Server 2008 R2, Windows Server 2008, Windows Server 2003 Windows XP 2 (SP2).

+3

IP_HDRINCL

.NET Socket RAW, SocketOptionName.HeaderIncluded Socket.SetSocketOption.

Reflector, .NET .

0

Source: https://habr.com/ru/post/1703540/


All Articles