使用 Python 注入原始 TCP 数据包 [英] Injecting raw TCP packets with Python
问题描述
用 Python 注入原始 TCP 数据包的合适方法是什么?例如,我有一个由十六进制数字组成的有效负载,我想将该十六进制数字序列发送到网络守护程序:这样如果我选择发送abcdef",我也会在线路上看到abcdef".但不是6162636566",例如:
What would be a suitable way to inject a raw TCP packet with Python? For example, I have the payload consisting of hexadecimal numbers and I want to send that sequence of hexadecimal numbers to a network daemon: so that if I choose to send 'abcdef', I see 'abcdef' on the wire too. But not '6162636566' as in the case of:
new = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
new.connect(('127.0.0.1', 9999))
new.send('abcdef')
我可以为此使用 Python 的 SOCK_RAW 吗?如果是这样,你能给我一个用 SOCK_RAW 发送原始 TCP 数据包的例子吗(因为我自己没有让它工作)
Can I use Python's SOCK_RAW for this purpose? If so, can you give me an example of sending raw TCP packets with SOCK_RAW (since I did not get it working myself)
谢谢!
伊夫根尼
推荐答案
尝试 scapy,一个强大的交互式数据包操作程序.
Try scapy, a powerful interactive packet manipulation program.
示例:
%> sudo scapy
>>> packet1 = IP(dst='127.0.0.1')/TCP(dport=9999)
>>> packet1.payload = 'abcdef'
>>> send(packet1)
.
Sent 1 packets.
>>> packet1.show()
###[ IP ]###
version= 4
ihl= None
tos= 0x0
len= None
id= 1
flags=
frag= 0
ttl= 64
proto= ip
chksum= None
src= 127.0.0.1
dst= 127.0.0.1
\options\
###[ Raw ]###
load= 'abcdef'
>>>
这篇关于使用 Python 注入原始 TCP 数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!