-
Notifications
You must be signed in to change notification settings - Fork 29
/
hashcrack.py
1432 lines (1109 loc) · 48.3 KB
/
hashcrack.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
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
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
#
#Released as open source by NCC Group Plc - http://www.nccgroup.com/
#
#Developed by Jamie Riden, [email protected]
#
#http://www.github.com/nccgroup/hashcrack
#
#This software is licensed under AGPL v3 - see LICENSE.txt
#
# v 1.01 'Kill the Power'
#
# thanks to Woody for beta testing
#
# todo fix relative paths for crib file, among others?
import re
import base64
import os
import subprocess
import sys
import shutil
import argparse
import sqlite3
import urllib
import zipfile
import tempfile
import time
import stat
import configparser
import platform
import requests, urllib3, datetime, bs4
pcsubmit = 1
# strip out the given regexp from ifile and stick it in ofile - unique strips out dupes if True
def getregexpfromfile(pattern, ifile, ofile,unique):
inpfile = open(ifile, 'r', encoding="utf-8")
outfile = open(ofile, 'w', encoding="utf-8")
seen={}
for l in inpfile:
m = re.search(pattern, l)
if unique:
try:
ans=m.group(1)
if re.match(r'\$HEX\[',ans):
m = re.search(r'\$HEX\[([0-9a-f]+)\]',ans)
if m.group(1):
ans=m.group(1)
ans=bytearray.fromhex(ans).decode('latin_1')
if not ans in seen:
seen[ans]=1
outfile.write(ans)
except:
print("no match ("+pattern+") line " + l)
else:
try:
ans=m.group(1)
outfile.write(ans)
except:
print("no match ("+pattern+") line " + l)
inpfile.close()
outfile.close()
def file_age_in_seconds(pathname):
return time.time() - os.stat(pathname)[stat.ST_MTIME]
#check if a file exists and is non empty
def is_non_zero_file(fpath):
return os.path.isfile(fpath) and os.path.getsize(fpath) > 0
def rules_exist(fpath,ruleshome):
if os.path.isfile(fpath) and os.path.getsize(fpath) > 0:
return True
if os.path.isfile(ruleshome+'/'+fpath) and os.path.getsize(ruleshome+'/'+fpath) > 0:
return True
return False
def dict_exists(fpath,dicthome):
if os.path.isfile(fpath) and os.path.getsize(fpath) > 0:
return True
if os.path.isfile(dicthome+'/'+fpath) and os.path.getsize(dicthome+'/'+fpath) > 0:
return True
return False
#halt with message
def die( message ):
print(message)
sys.exit( message )
#map names to types
def friendlymap( name ):
fmap={'md5':'0',
'sha1':'100',
'ntlm':'1000',
'vbulletin':'2611',
'ipb':'2811',
'mysql':'300',
'lm':'3000',
'sha256':'1400',
'sha512':'1700',
'oracle7':'3100',
'oracle-h':'3100',
'oracle11':'112',
'oracle-s':'112',
'oracle12':'12300',
'oracle-t':'12300',
'md5crypt':'500',
'descrypt':'1500',
'netlmv1':'5500',
'netlmv2':'5600',
'7z':'11600',
'apache':'1600',
'dcc':'1100',
'dcc2':'2100',
'mscache':'1100',
'mscache2':'2100',
'mscash':'1100',
'mscash2':'2100',
'drupal':'7900',
'netscaler':'8100',
'wpa':'2500',
'phps':'2612',
'sha3':'5000',
'sha384':'10800',
'zip':'13600'
}
t = fmap.get(name, 'auto')
return t
#pick some sensible defaults for the given hashtype
def selectparams( hashtype, sink, ruleshome, dicthome ):
# default these, but then see if they're in the config fiile
# dictionaries
massivedict="Top2Billion-probable.txt"
hugedict="breachcompilation.txt"
bigdict="Top258Million-probable.txt"
smalldict="Top95Thousand-probable.txt"
dumbdict="words.txt"
# rules
hugerules="rules/l33tnsa.rule"
bigrules="rules/l33tpasspro.rule"
smallrules="rules/l33t64.rule"
nullrules="rules/null.rule"
try:
config = configparser.ConfigParser()
config.read("hashcrack.cfg")
massivedict = config.get('dicts', 'massivedict')
hugedict = config.get('dicts', 'hugedict')
bigdict = config.get('dicts', 'bigdict')
smalldict = config.get('dicts', 'smalldict')
dumbdict = config.get('dicts', 'dumbdict')
hugerules = config.get('rules', 'hugerules')
bigrules = config.get('rules', 'bigrules')
smallrules = config.get('rules', 'smallrules')
nullrulres = config.get('rules', 'nullrules')
except:
print("Error reading config files, so going with default dicts and rules")
if not dict_exists(massivedict,dicthome):
print("Massive dict "+massivedict+" doesn't seem to exist - could cause problems. Check config file hashcat.cfg")
if not dict_exists(bigdict,dicthome):
print("Big dict "+bigdict+" doesn't seem to exist - could cause problems. Check config file hashcat.cfg")
if not dict_exists(smalldict,dicthome):
print("Small dict "+smalldict+" doesn't seem to exist - could cause problems. Check config file hashcat.cfg")
if not rules_exist(hugerules,ruleshome):
print("Huge rules file "+hugerules+" doesn't seem to exist - could cause problems. Check config file hashcat.cfg")
if not rules_exist(bigrules,ruleshome):
print("Big rules file "+bigrules+" doesn't seem to exist - could cause problems. Check config file hashcat.cfg")
if not rules_exist(smallrules,ruleshome):
print("Small rules file "+smallrules+" doesn't seem to exist - could cause problems. Check config file hashcat.cfg")
if sink:
#unhelpful naming, sorry
#open map.cfg
with open("map.cfg") as f:
for line in f:
try:
(key, val) = line.split(':')
if key == hashtype:
(dict,rules,inc,hr)=val.split(',')
print('Found '+key)
except:
print(line)
else:
#open quickmap.cfg
with open("quickmap.cfg") as f:
for line in f:
try:
(key, val) = line.split(':')
if key == hashtype:
(dict,rules,inc,hr)=val.split(',')
print('Found '+key)
except:
print(line)
dict=eval(dict)
if not re.search('opencl',hashtype):
try:
rules=eval(rules)
except:
rules=bigrules
inc=0
tp=(dict,rules,int(inc))
return tp
def autodetect( line ):
with open("regmap.cfg") as f:
for cfgline in f:
try:
(regexp, type, hr) = cfgline.split('!')
if re.search(regexp,line):
print('Autodetected '+ hr)
return type
except:
print("Couldn't interpret " + cfgline)
if re.search(r'(^|:)[A-fa-f0-9]{32}$',line):
print('Autodetected NTLM. Probably - or, it might be MD5 (100)x')
ans=input('Ambigious input; could be NTLM, MD5 or MySQL5. Please specify on command line with -t md5 or -t ntlm. For now, enter "ntlm" (default), "md5" : ')
if (re.search(r'md5',ans, re.IGNORECASE)):
return '0'
return '1000'
return ''
def btexec( sexec, show=0 ):
if not show:
print('RUN: '+sexec)
os.system(sexec)
#run a shell command
def btexeccwd(command,scwd,show=0):
if not show:
print("cwd "+scwd)
print("RUN: "+command)
if scwd is not None:
p = subprocess.Popen(command, shell=True,
cwd=scwd,
stderr=subprocess.STDOUT)
junk = p.communicate()
#jtr - experimental
def runjtr( hashcathome, pwdfile, hashtype, dict, rules, inc, trailer, dicthome, dictoverride, rightdictoverride, rulesoverride, mask, lmask, rmask, dolast, ruleshome, words, pathsep, exe, crib, phrases, username, sink, found, potfile, noinc, show, skip, restore, force, remove):
if pathsep=='/':
jtrbin='./john/run/john'
else:
jtrbin='john\\run\\john.exe'
try:
config = configparser.ConfigParser()
config.read("hashcrack.cfg")
dicthome = config.get('paths', 'dict')
crackeddict = config.get('dicts', 'cracked')
except:
print("Failed to read config file\n")
if dictoverride:
d=dictoverride
if not is_non_zero_file(d):
d='dict'+pathsep+d
else:
if not re.search('^/',dict):
d=dicthome+pathsep+dict
if mask is not None:
print("Using specified mask "+mask)
btexec(jtrbin+' --format='+hashtype+' '+pwdfile+' --mask='+mask)
else:
btexec(jtrbin+' --format='+hashtype+' '+pwdfile+' '+rules+' --wordlist='+dicthome+pathsep+dict)
#actually do the hashcat runs
#this can get somewhat complex depending on what it's been asked to do
def runhc( hashcathome, pwdfile, hashtype, dict, rules, inc, trailer, dicthome, dictoverride, rightdictoverride, rulesoverride, mask, lmask, rmask, dolast, ruleshome, words, pathsep, exe, crib, phrases, username, sink, found, potfile, noinc, show, skip, restore, force, remove):
global pcsubmit
if pathsep=='/':
hcbin='./hashcat64.bin'
else:
hcbin='hashcat64.exe'
crackeddict='cracked-passwords.txt'
try:
if pcsubmit == 0 :
print("Attempting to submit job to passcrack")
pconfig = configparser.ConfigParser()
pconfig.read("hashcrack.cfg")
pcurl = ''
try:
pcurl = pconfig.get('passcrack', 'pcurl')
except:
print("Can't find passcrack URL - check hashcrack.cfg, section [passcrack]")
pcemail = pconfig.get('passcrack', 'pcemail')
pcuser = pconfig.get('passcrack', 'pcname')
f = open(pwdfile, "r")
pccontents = f.read()
#open map.cfg
with open("passcrack.cfg") as f:
for line in f:
(key, val) = line.split('!')
if key == hashtype:
pcalg=val
proxies = {
'http': 'http://127.0.0.1:8080',
'https': 'http://127.0.0.1:8080'
}
urllib3.disable_warnings()
resp = requests.post(
pcurl,
headers={
'Connection': 'close',
'Cache-Control': 'max-age=0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Referer': pcurl,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8',
'Content-Type': 'application/x-www-form-urlencoded',
},
data={
'user': pcuser,
'algorithm': pcalg,
'email': pcemail,
'includeInWordlist': '1',
'hashes': pccontents
},
verify=False #, proxies=proxies
)
pcsubmit=1
#debug only
#print(resp.content)
m = re.search('href="./index.php\?key=([a-f0-9]+)"', resp.content.decode('utf-8'))
ans=m.group(1)
if ans:
print("Successfully submitted as job " + ans)
else:
print("Something went wrong submitting job")
except Exception as e:
print("Failed to talk to passcrack")
print(e)
try:
config = configparser.ConfigParser()
config.read("hashcrack.cfg")
dicthome = config.get('paths', 'dict')
crackeddict = config.get('dicts', 'cracked')
except:
print("Failed to read config file\n")
if rulesoverride:
r=rulesoverride
if not is_non_zero_file(r):
r='rules'+pathsep+r
else:
if not re.search('^/',rules):
r=ruleshome+pathsep+rules
if dictoverride:
d=dictoverride
if not is_non_zero_file(d):
d='dict'+pathsep+d
else:
if not re.search('^/',dict):
d=dicthome+pathsep+dict
if rightdictoverride:
if not is_non_zero_file(rightdictoverride):
if not re.search('^/',rightdictoverride):
rightdictoverride='dict'+pathsep+rightdictoverride
if username:
username='--username'
else:
username=''
if potfile:
potfile="--potfile-path "+potfile
else:
potfile=''
trailer=trailer+' '+potfile+' '+username
if skip:
skip=' --skip '+skip
else:
skip=''
if restore:
restore=' --restore'
if not show:
btexeccwd(hcbin+' '+ trailer + restore,hashcathome)
return
else:
restore=''
if remove:
remove=' --remove '
trailer=trailer+' '+remove
else:
remove=''
if force:
force=' --force '
trailer=trailer+' '+force
else:
force=''
if sink:
found=1
if show:
trailer=' '+potfile+' '+username
btexeccwd(hcbin+' -m '+hashtype+' '+pwdfile+' --show --quiet '+trailer, hashcathome)
return
if crib:
print("Processing crib file...")
tmpcrib=crib+'.tmp'
btexeccwd(hcbin+' --stdout '+crib+' -r '+ruleshome+pathsep+'leet2.rule -o '+tmpcrib,hashcathome)
btexeccwd(hcbin+' -a0 -m '+hashtype+' '+pwdfile+' '+tmpcrib+' -r '+ruleshome+pathsep+'best64.rule --loopback '+trailer,hashcathome)
if not noinc:
if inc>0:
if not mask:
print("Incremental run up to "+str(inc))
btexeccwd(hcbin+' -a3 -m '+hashtype+' '+pwdfile+' -i --increment-max='+str(inc)+' '+trailer,hashcathome)
else:
print("Skipping inc (inc " + str(inc) + ")")
else:
print("Skipping inc (--noinc)")
if found:
print("Using previous found list with variations")
#run list of found passwords against the new ones, various combinations
btexeccwd(hcbin+' -a6 -m '+hashtype+' '+pwdfile+' found.txt ?a?a -i '+trailer,hashcathome)
btexeccwd(hcbin+' -a0 -m '+hashtype+' '+pwdfile+' found.txt -r '+ruleshome+pathsep+'best64.rule --loopback '+trailer,hashcathome)
btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' found.txt '+dicthome+'/last3.txt '+trailer,hashcathome)
if is_non_zero_file('dict/found.txt'):
btexeccwd(hcbin+' -a6 -m '+hashtype+' '+pwdfile+' dict/found.txt ?a?a -i '+trailer,hashcathome)
btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' dict/found.txt '+dicthome+'/last3.txt '+trailer,hashcathome)
if dolast==1:
btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+dicthome+'/found.txt '+dicthome+'/last4.txt '+trailer,hashcathome)
if dolast==1 or sink:
btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' found.txt '+dicthome+'/last4.txt '+trailer,hashcathome)
if words:
print("Using bog standard dictionary words with variations")
btexeccwd(hcbin+' -a6 -m '+hashtype+' '+pwdfile+' '+dicthome+'/words.txt ?a?a -i '+trailer,hashcathome)
btexeccwd(hcbin+' -a0 -m '+hashtype+' '+pwdfile+' '+dicthome+'/words.txt -r '+ruleshome+pathsep+'best64.rule --loopback '+trailer,hashcathome)
btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+dicthome+'/words.txt '+dicthome+'/last3.txt '+trailer,hashcathome)
if dolast==1 or sink:
btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+dicthome+'/words.txt '+dicthome+'/last4.txt '+trailer,hashcathome)
if phrases:
print("Using phrases with variations")
btexeccwd(hcbin+' -a6 -m '+hashtype+' '+pwdfile+' '+dicthome+'/phrases.txt ?a?a -i '+trailer,hashcathome)
btexeccwd(hcbin+' -a0 -m '+hashtype+' '+pwdfile+' '+dicthome+'/phrases.txt -r '+ruleshome+pathsep+'best64.rule --loopback '+trailer,hashcathome)
btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+dicthome+'/phrases.txt '+dicthome+'/last3.txt '+trailer,hashcathome)
if dolast==1 or sink:
btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+dicthome+'/phrases.txt '+dicthome+'/last4.txt '+trailer,hashcathome)
#if we've got a dict + mask specified, they probably want this
if dictoverride and mask:
rmask=mask
if lmask:
print("Using specified left mask and dict: "+lmask)
btexeccwd(hcbin+' -a7 -m '+hashtype+' '+pwdfile+' '+lmask+' '+d+' -i '+trailer+skip,hashcathome)
else:
if rmask or mask:
if mask:
print("Using specified mask "+mask)
if re.match('\?',mask):
btexeccwd(hcbin+' -a3 -m '+hashtype+' '+pwdfile+' '+mask+' -i '+trailer+skip,hashcathome)
else:
btexeccwd(hcbin+' -a3 -m '+hashtype+' '+pwdfile+' '+mask+' '+trailer+skip,hashcathome)
if rmask:
print("Using specified dict + right mask: "+rmask)
btexeccwd(hcbin+' -a6 -m '+hashtype+' '+pwdfile+' '+d+' -i '+rmask+' '+trailer+skip,hashcathome)
else:
if rightdictoverride:
#if we've got right dict override, this is a cross product (-a1)
print("Using specified left and right dictionaries")
btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+d+' '+rightdictoverride+' '+trailer+skip,hashcathome)
else:
#otherwise, "normal" dict + rules run
print("Using dict and rules")
btexeccwd(hcbin+' -a0 -m '+hashtype+' '+pwdfile+' '+d+' -r '+r+' --loopback '+trailer+skip,hashcathome)
if dolast==1 or sink:
btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+d+' '+dicthome+'/last3.txt '+trailer,hashcathome)
if sink:
btexeccwd(hcbin+' -a1 -m '+hashtype+' '+pwdfile+' '+d+' '+dicthome+'/last4.txt '+trailer,hashcathome)
#get first line
def getfirstline( file ):
first_line = ''
try:
with open(file,encoding='utf-8') as f:
first_line = f.readline().strip()
except:
print("Couldn't parse first line of file")
return first_line
#run a shell command
def run_command(command):
p = subprocess.Popen(command.split(' '),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return iter(p.stdout.readline, b'')
#main - read the options and do the set up for the cracking
def main():
global pcsubmit
#needs to be run with python3
if sys.version_info < (3,0):
print("*** Needs python3 for utf-8 / encoding support")
assert sys.version_info >= (3,0)
#declarations
exe='.bin' # default to Linux for the moment
minlength=1 # min length for -a3 attacks
status=''
cachetime=3600
maskattack=0
# setup my defaults
hashtype = 'auto' # autodetect
hashcathome='hashcat-5.1.0'
dicthome='dict'
ruleshome='rules'
print("Loading config")
try:
config = configparser.ConfigParser()
config.read("hashcrack.cfg")
hashcathome = config.get('paths', 'hc')
ruleshome = config.get('paths', 'rules')
dicthome = config.get('paths', 'dict')
#print("Ruleshome "+ruleshome)
#print("Dicthome "+dicthome)
#print("HChome "+hashcathome)
except:
print("Error reading config files, so going with default dicts and rules")
# declarations
trailer=''
dict=''
inc=0
mininc=1
sink=''
dolast=0
rules='best64.rule'
colon=''
pathstyle=''
pathsep='/'
fhash=''
crib=''
omenfile=''
prince=''
princemin='8'
princemax='28'
# for hashcat4
#crackopts=" -O --quiet "
crackopts=" -O --bitmap-max=26 "
uname=''
loc=''
cygwin=0
inc=0
remove=''
incr=''
unix=0
parser = argparse.ArgumentParser(description='Description of your program')
parser.add_argument('-i','--input', help='Input file' )
parser.add_argument('--hash', help='Input hash' )
parser.add_argument('-c','--crib', help='Crib file - keep it short')
parser.add_argument('-m','--mask', help='Mask to use')
parser.add_argument('--rmask', help='Right hand mask to use with dict')
parser.add_argument('--lmask', help='Left hand mask to use with dict')
parser.add_argument('-t','--type', help='Hash type')
parser.add_argument('-d','--dict', help='Dictionary override')
parser.add_argument('-e','--rightdict', help='Second dictionary override')
parser.add_argument('-r','--rules', help='Rules override')
parser.add_argument('--potfile', help='Potfile override')
parser.add_argument('-tf','--thisfound', help='Use this instead of found.txt')
parser.add_argument('-P','--prince', help='Use PRINCE preprocessor')
parser.add_argument('-O','--omen', help='Use OMEN preprocessor')
parser.add_argument('-C','--chunk', help='Use this chunk size')
parser.add_argument('-a','--mininc', help='Min increment')
parser.add_argument('-z','--maxinc', help='Max increment')
parser.add_argument('--skip', help='Skip argument to hashcat')
parser.add_argument('--pc', action="store_true", help='Submit job to passcrack as well as local crack')
parser.add_argument('--restore', action="store_true", help='Restore to last session')
parser.add_argument('-s','--show', action="store_true", help='Just show stuff')
parser.add_argument('-l','--last', action="store_true", help='Use last3 file together with the given or default dictionary')
parser.add_argument('-f','--found', action="store_true", help='Update found list')
parser.add_argument('--force', action="store_true", help='Run with CPU as well. Gets you up to 8% percent extra oomph, depending on hash type')
parser.add_argument('--remove', action="store_true", help='Remove found hashes from input file')
parser.add_argument('-w','--words', action="store_true", help='Use words file')
parser.add_argument('--noinc', action="store_true", help='Don not use increment')
parser.add_argument('-p','--phrases', action="store_true", help='Use phrases file')
parser.add_argument('-u','--username', action="store_true", help='Override username flag')
parser.add_argument('-n','--sink', action="store_true", help='Do more; throw the kitchen sink at it')
args = parser.parse_args()
if not args.input and not args.hash:
die("Please specify [--input|-i] <input file> or --hash <input hash>")
infile=args.input
show=args.show
inhash=args.hash
crib=args.crib
if infile is not None:
infile=os.path.abspath(infile)
if crib is not None:
crib=os.path.abspath(crib)
#clear "have submitted to passcrack" flag if we've been asked to submit
if args.pc:
pcsubmit=0
words=args.words
phrases=args.phrases
mask=args.mask
username=args.username
dolast=args.last
sink=args.sink
skip=args.skip
restore=args.restore
remove=args.remove
force=args.force
stype=args.type
rightdict=args.rightdict
mininc=args.mininc
maxinc=args.maxinc
#todo
thisfound=args.found
chunk=args.chunk
prince=args.prince
omen=args.omen
p_os=platform.system()
if re.match(r'Linux',p_os):
pathstyle='unix'
unix=1
crackopts=crackopts+" -w4 "
hashcathome='./hashcat-5.1.0'
ruleshome='./hashcat-5.1.0/rules'
exe='.bin'
else:
if re.match(r'Windows',p_os):
if not show:
print("Running under win32")
exe='.exe'
hashcathome='hashcat-5.1.0' #relative path issues with 4.10
pathstyle='win32'
pathsep=r'\\'
ruleshome='hashcat-5.1.0\\rules'
crackopts=crackopts+" -w3 "
else:
print("Unknown platform")
exit
trailer=crackopts+' --session hc'
if maxinc is not None:
maxinc=int(maxinc)
if mininc is not None:
mininc=int(mininc)
else:
mininc=0
if rightdict is not None:
if not is_non_zero_file(rightdict):
print("Can't find dictionary file "+rightdict)
sys.exit(1)
dictoverride=args.dict
if dictoverride is not None:
dictoverride=os.path.abspath(dictoverride)
if not is_non_zero_file(dictoverride):
print("Can't find dictionary file "+dictoverride)
sys.exit(1)
if rightdict is not None:
rightdict=os.path.abspath(rightdict)
if not is_non_zero_file(rightdict):
print("Can't find dictionary file "+rightdict)
sys.exit(1)
rulesoverride=args.rules
if rulesoverride is not None:
rulesoverride=os.path.abspath(rulesoverride)
if not is_non_zero_file(rulesoverride):
print("Can't find rules file "+rulesoverride)
sys.exit(1)
potfile=args.potfile
rmask=args.rmask
lmask=args.lmask
noinc=args.noinc
if infile:
infile=os.path.abspath(infile)
tmpfile=infile+'.tmp'
tmpfile2=infile+'.tmp2'
else:
infile=tempfile.gettempdir()+pathsep+next(tempfile._get_candidate_names())+'.hash.tmp'
tmpfile=tempfile.gettempdir()+pathsep+next(tempfile._get_candidate_names())+'.tmp'
tmpfile2=tempfile.gettempdir()+pathsep+next(tempfile._get_candidate_names())+'.tmp2'
outfile = open(infile,'w')
outfile.write(inhash)
outfile.close()
try:
config = configparser.ConfigParser()
config.read("hashcrack.cfg")
javapath = config.get('paths', 'javapath')
python2path = config.get('paths', 'python2path')
python3path = config.get('paths', 'python3path')
perlpath = config.get('paths', 'perlpath')
hashcathome = config.get('paths', 'hc')
ruleshome = config.get('paths', 'rules')
dicthome = config.get('paths', 'dict')
except:
javapath='java'
python2path='python'
perlpath='perl'
hcpath=os.path.abspath('hashcat-5.1.0')
hashtype=args.type
if not hashtype:
hashtype='auto'
else:
#remap friendly name to numeric if need be
if re.match('^[a-zA-Z][a-zA-z0-9]+$',hashtype):
hashtype=friendlymap(hashtype)
found=args.found
#grab a crib from previously found passwords
if found:
if not is_non_zero_file('found.txt'):
if potfile:
getregexpfromfile(':([^:]+)$',potfile,'found.txt',True)
else:
getregexpfromfile(':([^:]+)$',hashcathome+pathsep+'hashcat.potfile','found.txt',True)
else:
if file_age_in_seconds('found.txt')>3600:
if potfile and is_non_zero_file(potfile):
getregexpfromfile(':([^:]+)$',potfile,'found.txt',True)
else:
getregexpfromfile(':([^:]+)$',hashcathome+pathsep+'hashcat.potfile','found.txt',True)
if infile:
if not show:
print("Reading file: "+infile)
if re.search(r'\.db$',infile):
hashtype='responder'
stype='responder'
if re.search(r'\.jks$',infile):
hashtype='jks'
stype='jks'
if re.search(r'\.7z$',infile):
hashtype='7z'
username=1
stype='7z'
if re.search(r'\.pdf$',infile):
hashtype='pdf'
stype='pdf'
if re.search(r'\.(xls|doc)x?$',infile):
hashtype='msoffice'
stype='msoffice'
if stype!='ifm' and stype!='reg':
if re.search(r'\.zip$',infile):
hashtype='zip'
stype='zip'
if re.search(r'\.gpg$',infile):
hashtype='gpg'
stype='gpg'
#ifm support
#C:\>ntdsutil
#ntdsutil: activate instance ntds
#ntdsutil: ifm
#ifm: create full c:\temp\ifm
#ifm: quit
#ntdsutil: quit
#Then zip c:\temp\ifm and submit this.
if infile:
line=getfirstline(infile)
else:
line=inhash
if hashtype=='auto':
if stype is not None:
if stype!='oracle':
hashtype=autodetect(line)
else:
hashtype=autodetect(line)
if hashtype=='pwdump':
stype='pwdump'
if hashtype=='oracle':
stype='oracle'
# how many colons we're expecting by hash type
colonmap={ '10':1,
'11':1,
'12':1,
'20':1,
'21':1,
'22':1,
'23':1,
'30':1,
'40':1,
'50':1,
'60':1,
'110':1,
'112':1,
'120':1,
'121':1,
'130':1,
'140':1,
'150':1,
'160':1,
'1100':1,
'1410':1,
'1420':1,
'1430':1,
'1440':1,
'1450':1,
'1460':1,
'1710':1,
'1720':1,
'1730':1,
'1740':1,
'1750':1,
'1760':1,
'2410':1,
'2611':1,
'2711':1,
'2811':1,
'3100':1,
'3710':1,
'3800':1,
'3910':1,
'4010':1,
'4110':1,
'4520':1,
'4521':1,
'4522':1,
'4800':2,
'4900':1,
'5300':8,
'5400':8,
'5500':5,
'5600':5,
'5800':1,
'6600':2,
'6800':2,
'7300':1,
'8200':3,
'8300':3,
'8400':1,
'8900':5,
'9720':1,
'9820':1,
'10100':3,
'10420':1,
'10900':3,
'11000':1,
'11500':1,
'11900':3,
'12000':3,
'12100':3,
'12600':1,
'13100':1,
'13500':1,
'13800':1,
'13900':1,
'14000':1,
'14100':1,
'14400':1,
'14900':1,
'15000':1,
'18200':1 }
colons=line.count(':')
expectedcolons=colonmap.get(hashtype,0)
#if we've got more colons than that, need --username flag
if colons>expectedcolons: