如何将原始数据包注入我的网络
在测试某些网络设备驱动程序接收功能时,我需要在线发送特殊数据包。我知道我需要打开一个原始套接字并将字节推出。是否有一些众所周知的示例(C,perl,等等)代码已经可以用于这个级别的游戏?
(稍后添加)我更喜欢非特定于平台的答案,它们对每个人来说都是最有用的。
In testing certain network device driver receive features, I need to send special packets on the wire. I know I need to open a raw socket and push the bytes out. Is there some well-known example (C, perl, whatever) code already available for playing at this level?
(added later) I would prefer non-platform-specific answers, they'll be the most useful for everyone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
查看数据包的文档。基本上,您使用 SOCK_RAW 或 SOCK_DGRAM 创建套接字,然后使用普通套接字 I/O 写入套接字。但是,您发送的数据将直接放在线路上,而不是自动获取大多数网络互操作所需的标头。
Look at the documentation for packet. Basically, you create a socket with SOCK_RAW or SOCK_DGRAM, then write to the socket using normal socket i/o. However, the data you send will be put directly on the line, rather than automatically getting the headers that are necessary for most network interop.
http://www.codeproject.com/KB/IP/sendrawpacket.aspx
已有一个项目可能可以帮助您解决此问题。
http://www.codeproject.com/KB/IP/sendrawpacket.aspx
There's already an existing project that may be able to help you with this.
查看 http://tcpreplay.synfin.net/wiki/tcprewrite#RewritingLayer2
和 http://tcpreplay.synfin.net/
Check out http://tcpreplay.synfin.net/wiki/tcprewrite#RewritingLayer2
and http://tcpreplay.synfin.net/
在我看来,您正在寻找一个工具来生成自己的数据包,Scapy 是安全行业(例如渗透测试人员)中经常使用的此类工具。
演示可用:http://www.secdev.org/projects/scapy/demo。 html
Seems to me you are looking for a tool to generate your own packets, Scapy is such a tool often used in the security industry (such as pentesters).
Demo is available: http://www.secdev.org/projects/scapy/demo.html
我想不出任何例子。但是您应该能够向您喜欢的任何 IP 地址打开 UDP 套接字并开始向其写入数据。确保它是 UDP,否则将无法工作。
I can't think of any examples. But you should just be able to open up a UDP socket to any IP address you like and start writing data to it. Make sure its UDP or this will not work.
我发现这里有一个很好的 C 示例 Security-Freak,为了灵活性只需要一点修改。我希望有更多其他语言的答案。
I found that there's a good C example here at Security-Freak, which only needed a little modification for flexibility. I'm hoping there are more answers in other languages.