Send packet and change its source IP

2020-07-11 06:50发布

问题:

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?

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.

I'd like to do this without having to implement a MITM.

回答1:

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.



回答2:

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.