C#原始套接字端口转发 [英] C# Raw Sockets Port Forwarding

查看:282
本文介绍了C#原始套接字端口转发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的C#应用​​程序,它确实端口转发,并且需要知道如何使用IP_HDRINCL套接字选项,试图伪造出来的接收端认为连接是真正的来源。任何例子将不胜感激。


解决方案

 袜子=新的Socket(AddressFamily.InterNetwork, SocketType.Raw,ProtocolType.IP); 
sock.Bind(新IPEndPoint(IPAddress.Parse(10.25.2.148),0));
sock.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.HeaderIncluded,1);
字节[] = trueBytes新的字节[] {1,0,0,0};
字节[] = outBytes新的字节[] {0,0,0,0};
sock.IOControl(IOControlCode.ReceiveAll,trueBytes,outBytes);
sock.BeginReceive(数据,0,data.Length,SocketFlags.None,新的AsyncCallback(的onReceive),NULL);



唯一的问题是,我已经能够从一个原始套接字成功接收数据这样, (包括IP头),但不能发送。


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.

解决方案

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.

这篇关于C#原始套接字端口转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆