Python 发送数据包并更改其源 IP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27448905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Send packet and change its source IP
提问by Jay
Lets say I have an application written in python to send a ping or e-mail. How can I change the source IP address of the sent packet to a fake one, using, e.g., Scapy?
假设我有一个用 python 编写的应用程序来发送 ping 或电子邮件。如何使用例如 Scapy 将发送数据包的源 IP 地址更改为伪造的 IP 地址?
Consider that that the IP address assigned to my eth0 is 192.168.0.100. My e-mail application will send messages using this IP. However, I want to manipulate this packet, as soon as it is ready to be sent, so its source IP is not 192.168.0.100 but 192.168.0.101 instead.
考虑分配给我的 eth0 的 IP 地址是 192.168.0.100。我的电子邮件应用程序将使用此 IP 发送消息。但是,我想操纵这个数据包,一旦它准备好发送,所以它的源 IP 不是 192.168.0.100 而是 192.168.0.101。
I'd like to do this without having to implement a MITM.
我想这样做而不必实施 MITM。
回答by Yoel
You can do the following:
您可以执行以下操作:
from scapy.all import *
A = '192.168.0.101' # spoofed source IP address
B = '192.168.0.102' # destination IP address
C = 10000 # source port
D = 20000 # destination port
payload = "yada yada yada" # packet payload
spoofed_packet = IP(src=A, dst=B) / TCP(sport=C, dport=D) / payload
send(spoofed_packet)
For some more interesting examples, you may refer to this tutorial.
对于一些更有趣的例子,你可以参考这个教程。
回答by Yoel
You basically want to spoof your ip address.Well I suggest you to read Networking and ip header packets.This can be possible through python but you won't be able to see result as you have spoofed your ip.To be able to do this you will need to predict the sequence numbers.
你基本上想欺骗你的 ip 地址。我建议你阅读网络和 ip 头数据包。这可以通过 python 实现,但你将无法看到结果,因为你欺骗了你的 ip。为了能够做到这一点您将需要预测序列号。