我们可以为第3层ICMP数据包使用srp()函数吗?我看到,当我们创建一个ICMP echo请求包并使用sr()发送/接收时,我们没有看到它从接口发送出去,因此没有来自目的地的响应。但同样的包如果我们使用srp()函数,我们会看到响应。什么时候应该使用sr()和srp()?在文档中,它声明sr()用于L3数据包,srp()用于L2?但在我的例子中,我不确定sr()为什么不适用于ICMP数据包?一些专家能帮我理解吗?
也可以有人让我知道,如果“iface”的论点总是需要的。如果没有这个,scapy怎么知道它应该通过哪个接口发送数据包呢?
案例1:sr()函数,iface作为参数:
sr(icmp,iface="eth0")
开始发射:
WARNING: Mac address to reach destination not found. Using broadcast.
Finished to send 1 packets.
^C
Received 0 packets, got 0 answers, remaining 1 packets
(<Results: TCP:0 UDP:0 ICMP:0 Other:0>, <Unanswered: TCP:0 UDP:0 ICMP:1 Other:0>)
上面我没有看到来自IP 192.168.25.1的任何ICMP响应
第2种情况:sr()函数,不带iface:
sr(icmp)
.Begin emission:
......WARNING: Mac address to reach destination not found. Using broadcast.
.Finished to send 1 packets.
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................^C
Received 887 packets, got 0 answers, remaining 1 packets
(<Results: TCP:0 UDP:0 ICMP:0 Other:0>, <Unanswered: TCP:0 UDP:0 ICMP:1 Other:0>)
如果你看到上面收到的包更多,但我没有看到任何ICMP响应。
情况3:用srp()而不是sr()发送ICMP数据包:
srp(icmp,iface="eth0")
Begin emission:
Finished to send 1 packets.
*
Received 1 packets, got 1 answers, remaining 0 packets
(<Results: TCP:0 UDP:0 ICMP:1 Other:0>, <Unanswered: TCP:0 UDP:0 ICMP:0 Other:0>)
这里我使用srp()函数而不是sr()函数,现在我看到ICMP echo请求已正确发送,我也收到了响应。
>>> icmp.show2()
###[ Ethernet ]###
dst: 02:00:00:11:01:03
src: 02:00:20:ee:64:01
type: 0x800
###[ IP ]###
version: 4L
ihl: 5L
tos: 0x0
len: 28
id: 1
flags:
frag: 0L
ttl: 64
proto: icmp
chksum: 0xc78c
src: 192.168.25.2
dst: 192.168.25.1
\options\
###[ ICMP ]###
type: echo-request
code: 0
chksum: 0xf7ff
id: 0x0
seq: 0x0
>>>
每个official API documentation的
sr
函数:srp
函数:由于
ICMP
包的第2层字段也已填充,如ICMP.show2()
的输出所示,因此应该使用srp
函数。如果像在this tutorial中那样,让它们保持原样,就可以使用sr
函数。现在,关于
ICMP
分类为第2层协议或第3层协议的问题。许多人认为这是一个第三层协议,比如here,因为它使用IP
头并“坐”在头上。然而,其他人认为它是第2层协议,如here。This is a question在这个问题上给出了一些很好的答案,但是请注意,它们引用了OSI
模型,因此分层方案编号有点不同。这是我在here找到的最好的:编辑-我刚遇到this link,觉得值得一提:
RFC 792也非常明确:
还有RFC 1122:
关于显式指定接口的最后一个问题,请参见^{}'s tutorial :
官方API文档更详细一些:
具体来说,
iface
参数用于设置输入接口(但如果不使用iface_hint
,则还设置输出接口):对于
output
接口上的提示,请对第2层函数使用iface_hint
:相关问题 更多 >
编程相关推荐