简体   繁体   English

Scapy是否绕过Dummynet?

[英]Does Scapy bypass Dummynet?

Does Scapy bypass Dummynet (IPFW in general)? Scapy是否绕过Dummynet (通常为IPFW)?

It really looks like it does. 看起来确实如此。 I'm adding a large extra delay to each outgoing and incoming packet, and everything slows down apart from packets sent with Scapy. 我给每个传入和传出的数据包增加了一个额外的延迟,除了通过Scapy发送的数据包之外,其他所有东西都变慢了。

$ ipfw add pipe 1 from any to any
$ ipfw pipe 1 config delay 500ms
$ ping www.google.com
PING www.l.google.com (173.194.34.18) 56(84) bytes of data.
64 bytes from par03s02-in-f18.1e100.net (173.194.34.18): icmp_req=1 ttl=54 time=1011 ms
64 bytes from par03s02-in-f18.1e100.net (173.194.34.18): icmp_req=2 ttl=54 time=1010 ms

So it seems OK. 这样看来还可以。 But as soon as I send packets with Scapy, here's what happens: 但是,一旦我使用Scapy发送数据包,就会发生以下情况:

>>> from scapy.all import *
>>> p = IP(dst="www.google.com", ttl=1) / TCP(sport=222, dport=2999)
>>> ans,unans = sr(p*3)
>>> ans[0][1].time - ans[0][0].sent_time
0.0002701282501220703  #usual value for such RTT

Is there any way to force it to pass through dummynet? 有什么方法可以迫使它通过虚拟网络?

EDIT If only I had another machine at my disposal, I could use dummynet there and direct all my traffic to it, before it gets into the Internet. 编辑如果只有我可以使用的另一台计算机,则可以在其中使用虚拟网并将所有流量定向到该虚拟机,然后再进入Internet。 I would prefer to do everything locally, though. 不过,我希望在本地进行所有操作。

The author of Scapy replied to me in Scapy's mailing list: Scapy的作者在Scapy的邮件列表中回复了我:

Try the same solution as for this question: http://trac.secdev.org/scapy/wiki/FAQ#Icantping127.0.0.1.Scapydoesnotworkwith127.0.0.1orontheloopbackinterface (using raw sockets) 尝试使用与此问题相同的解决方案: http : //trac.secdev.org/scapy/wiki/FAQ#Icantping127.0.0.1.Scapydoesnotworkwith127.0.0.1或在loopback接口上使用原始套接字

It worked! 有效! Here's the paragraph from the above link : 这是上面链接的段落:

I can't ping 127.0.0.1. 我无法ping 127.0.0.1。 Scapy does not work with 127.0.0.1 or on theloopback interface Scapy不适用于127.0.0.1或在Loopback接口上

The loopback interface is a very special interface. 回送接口是一个非常特殊的接口。 Packets going through it are not really assembled and dissassembled. 经过它的数据包并没有真正组装和拆卸。 The kernel routes the packet to its destination while it is still stored an internal structure. 内核将数据包路由到其目的地,同时仍将其存储为内部结构。 What you see with tcpdump -i lo is only a fake to make you think everything is normal. 使用tcpdump -i lo看到的内容只是一个伪造品,使您认为一切正常。 The kernel is not aware of what Scapy is doing behind his back, so what you see on the loopback interface is also a fake. 内核不知道Scapy在背后做了什么,因此在环回接口上看到的内容也是假的。 Except this one did not come from a local structure. 除了这一点,它不是来自本地结构。 Thus the kernel will never receive it. 因此内核将永远不会收到它。

In order to speak to local applications, you need to build your packets one layer upper, using a PF_INET/SOCK_RAW socket instead of a PF_PACKET/SOCK_RAW (or its equivalent on other systems than Linux) : 为了与本地应用程序对话,您需要使用PF_INET / SOCK_RAW套接字而不是PF_PACKET / SOCK_RAW(或Linux以外的其他系统上的等效项),在上一层上构建数据包:

>>> conf.L3socket
<class __main__.L3PacketSocket at 0xb7bdf5fc>
>>> conf.L3socket=L3RawSocket
>>> sr1(IP(dst="127.0.0.1")/ICMP())
<IP  version=4L ihl=5L tos=0x0 len=28 id=40953 flags= frag=0L ttl=64 proto=ICMP chksum=0xdce5 src=127.0.0.1 dst=127.0.0.1 options='' |<ICMP  type=echo-reply code=0 chksum=0xffff id=0x0 seq=0x0 |>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM