我已经嗅了一个IGMP数据包,现在我想在python的帮助下发送它。有没有办法像
一样发送数据包0x0000 01 00 5E 00 43 67 00 02-B3 C8 7F 44 81 00 00 DE ..^.Cg..іИD?..Ю
0x0010 08 00 46 00 00 20 00 01-00 00 01 02 36 4C C0 A8 ..F.. ......6LАЁ
0x0020 00 7B EA 00 43 67 94 04-00 00 16 00 BC 97 EA 00 .{к.Cg”.....ј—к.
0x0030 43 67 Cg
没有像impacket这样的数据包生成器?
UPD好的,我尝试使用原始套接字,如:
dst = '234.0.67.103'
# Open a raw socket.
s = socket.socket(socket.AF_INET, socket.SOCK_RAW,2)
res=''
temp='01 00 5E 00 43 67 00 02 B3 C8 7F 44 81 00 00 DE 08 00 46 00 00 20 00 01 00 00 01 02 36 4C C0 A8 00 7B EA 00 43 67 94 04 00 00 16 00 BC 97 EA 00 43 67'
for i in temp.split(' '):
res+=chr(int(i, 16))
print res
s.sendto(res, (dst, 0))
一切都很好,除了一件小事...... 如果我嗅到那个数据包,它看起来像是:
0x0000 01 00 5E 00 43 67 00 02-B3 C8 7F 44 08 00 45 00 ..^.Cg..іИD..E.
0x0010 00 46 07 06 00 00 01 02-C4 25 C0 A8 00 7B EA 00 .F......Д%АЁ.{к.
0x0020 43 67 01 00 5E 00 43 67-00 02 B3 C8 7F 44 81 00 Cg..^.Cg..іИDЃ.
0x0030 00 DE 08 00 46 00 00 20-00 01 00 00 01 02 36 4C .Ю..F.. ......6L
0x0040 C0 A8 00 7B EA 00 43 67-94 04 00 00 16 00 BC 97 АЁ.{к.Cg”.....ј—
0x0050 EA 00 43 67 к.Cg
正如您所看到的,由于某种原因,python忽略了我的标题并创建了自己的标题。我该如何解决?
答案 0 :(得分:5)
由于Unix网络编程(第3版):
sockfd = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
# inform os about that program are compose ip header
sockfd.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, True)
答案 1 :(得分:2)
嗯,据我所知,唯一的办法就是以这样的方式使用scapy:
from scapy.all import *
a=Ether(import_hexcap())
<some dumped hex>
sendp(a)
答案 2 :(得分:1)
以下是修改将发送原始数据包的代码:
import socket
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0x8100)
s.bind(('eth0', 0x8100))
res=''
temp='01 00 5E 00 43 67 00 02 B3 C8 7F 44 81 00 00 DE 08 00 46 00 00 20 00 01 00 00 01 02 36 4C C0 A8 00 7B EA 00 43 67 94 04 00 00 16 00 BC 97 EA 00 43 67'
for i in temp.split(' '):
res+=chr(int(i, 16))
s.send(res)