1

我已经嗅探了一个 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 忽略了我的标头并创建了自己的标头。我该如何解决?

4

3 回答 3

6

由于 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)
于 2014-03-06T16:16:32.140 回答
2

好吧,据我了解,这样做的唯一方法是以这样的方式使用 scapy:

from scapy.all import *
a=Ether(import_hexcap())
<some dumped hex>
sendp(a)
于 2010-12-03T09:00:19.123 回答
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)
于 2010-12-01T18:58:51.413 回答