forked from nccgroup/hashcrack
-
Notifications
You must be signed in to change notification settings - Fork 6
/
hashcrack.py
executable file
·1506 lines (1150 loc) · 54.6 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/python
#
# Released as open source by NCC Group Plc - http://www.nccgroup.com/
#
# Originally developed by Jamie Riden while at NCC Group.
#
# Now forked to http://www.github.com/blacktraffic/hashcrack as I no longer work
# at NCC so active dev is continuing here.
#
#
#
# This software is licensed under AGPL v3 - see LICENSE.txt
#
# v 1.8 'Ethics Gradient'
#
# this badly needs refactoring. it's a helper script that got out of hand
#how to:
#
# get mssql hashes:
# SELECT name + ':' + master.sys.fn_varbintohexstr(password_hash) from master.sys.sql_logins ;
# get AD hashes via NTDSUTIL
#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 as -t ifm -i ifm.zip. This needs impacket to unpack
#ancient
# jamie@zealot:~/dev/hashcrack$ hcxhash2cap --hccapx=tests/hashcat.hccapx
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 urllib3, datetime
import array
# 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
#check if a file exists and is non empty
def is_non_zero_file_or_dir(fpath):
return (os.path.isfile(fpath) and os.path.getsize(fpath) > 0) or os.path.isdir(fpath)
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',
'wpa':'2500',
'wpa-pmk':'2501',
'wpa-pmkid':'16800',
'gen':'99999'
}
t = fmap.get(name, 'auto')
return t
#pick some sensible defaults for the given hashtype
def selectparams( hashtype, 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"
# 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')
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",file=sys.stderr)
if not dict_exists(bigdict,dicthome):
print("Big dict "+bigdict+" doesn't seem to exist - could cause problems. Check config file hashcat.cfg",file=sys.stderr)
if not dict_exists(smalldict,dicthome):
print("Small dict "+smalldict+" doesn't seem to exist - could cause problems. Check config file hashcat.cfg",file=sys.stderr)
if not rules_exist(hugerules,ruleshome):
print("Huge rules file "+hugerules+" doesn't seem to exist - could cause problems. Check config file hashcat.cfg",file=sys.stderr)
if not rules_exist(bigrules,ruleshome):
print("Big rules file "+bigrules+" doesn't seem to exist - could cause problems. Check config file hashcat.cfg",file=sys.stderr)
if not rules_exist(smallrules,ruleshome):
print("Small rules file "+smallrules+" doesn't seem to exist - could cause problems. Check config file hashcat.cfg",file=sys.stderr)
#open quickmap.cfg
with open("quickmap.cfg") as f:
for line in f:
if line[0]!='#':
try:
(key, val) = line.split(':')
if key == hashtype:
(dict,rules,inc,hr)=val.split(',')
#print('Found '+key)
except:
print(line)
try:
dict=eval(dict)
except:
dict=smalldict
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:
if cfgline[0]!='#':
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, dryrun=0 ):
if not show:
print('RUN:'+sexec)
if dryrun == 0:
os.system(sexec)
#run a shell command
def btexeccwd(command,scwd,show=0,dryrun=0):
if not show:
print("CWD: "+scwd)
print("RUN: "+command)
if not dryrun:
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, ruleshome, pathsep, exe, crib, username, potfile, noinc, show, skip, restore, force, remove, statusfile, dryrun):
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
print(d)
if not is_non_zero_file_or_dir(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,show,dryrun)
else:
btexec(jtrbin+' --format='+hashtype+' '+pwdfile+' '+rules+' --wordlist='+d,show,dryrun)
#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, ruleshome, pathsep, exe, crib, username, potfile, noinc, show, skip, restore, force, remove, statusfile, leet, prince, princemin, princemax, purplerain, dryrun, xrules, debugfile):
if pathsep=='/':
hcbin='./hashcat.bin'
else:
hcbin='hashcat.exe'
crackeddict='cracked-passwords.txt'
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_or_dir(r):
r='rules'+pathsep+r
else:
if not re.search('^/',rules):
r=ruleshome+pathsep+rules
if xrules:
x=xrules
if not is_non_zero_file_or_dir(r):
xr='rules'+pathsep+r
else:
if not re.search('^/',rules):
xr=ruleshome+pathsep+rules
if dictoverride:
d=dictoverride
if not is_non_zero_file_or_dir(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,show,dryrun)
return
else:
restore=''
if remove:
remove=' --remove '
trailer=trailer+' '+remove
else:
remove=''
if force:
force=' --force '
trailer=trailer+' '+force
else:
force=''
if statusfile is not None:
trailer=trailer+' --status >> '+statusfile
if hashtype=="99999":
d=pwdfile
pwdfile='--stdout'
if show:
trailer=' '+potfile+' '+username
btexeccwd(hcbin+' -m '+hashtype+' '+pwdfile+' --show --quiet '+trailer, hashcathome, 1, dryrun)
return
if crib:
print("Processing crib file...")
tmpcrib=crib+'.tmp'
btexeccwd(hcbin+' --stdout '+crib+' -r '+ruleshome+pathsep+'leet2.rule -o '+tmpcrib,hashcathome,dryrun)
btexeccwd(hcbin+' -a0 -m '+hashtype+' '+pwdfile+' '+tmpcrib+' -r '+ruleshome+pathsep+'best84581.rule --loopback '+trailer,hashcathome,show,dryrun)
return
#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,show,dryrun)
else:
if rmask or mask:
if mask:
print("Using specified mask "+mask)
if re.match(r'\?',mask):
btexeccwd(hcbin+' -a3 -m '+hashtype+' '+pwdfile+' '+mask+' -i '+trailer+skip,hashcathome,show,dryrun)
else:
if mask!='default':
#assume it's a file
btexeccwd(hcbin+' -a3 -m '+hashtype+' '+pwdfile+' '+mask+' '+trailer+skip,hashcathome,show,dryrun)
else:
#use the default ?1?2 ... ?2?3 mask with -i
btexeccwd(hcbin+' -a3 -m '+hashtype+' '+pwdfile+' -i '+trailer+skip,hashcathome,show,dryrun)
if rmask:
print("Using specified dict + right mask: "+rmask)
btexeccwd(hcbin+' -a6 -m '+hashtype+' '+pwdfile+' '+d+' -i '+rmask+' '+trailer+skip,hashcathome,show,dryrun)
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,show,dryrun)
else:
#otherwise, "normal" dict + rules run
print("Using dict and rules")
# purple rain
if purplerain==1:
#todo shuf
if pathsep=='/':
btexeccwd('../princeprocessor/pp64.bin --pw-min='+princemin+' '+d+' | '+hcbin+' -a0 -m '+hashtype+' '+pwdfile+' -g 300000 '+trailer,hashcathome,show,dryrun)
else:
btexeccwd('..\\princeprocessor\\pp64.exe --pw-min='+princemin+' '+d+' | '+hcbin+' -a0 -m '+hashtype+' '+pwdfile+' -g 300000 '+trailer,hashcathome,show,dryrun)
if leet:
btexeccwd('python3 ../scripts/leetify.py '+d+' | '+hcbin+' -a0 -m '+hashtype+' '+pwdfile+' -r '+r+' --loopback '+trailer+skip,hashcathome,d)
if prince:
if princemax!='999':
princeargs='--pw-min='+princemin+' --pw-max='+princemax+' --case-permute'
else:
princeargs='--pw-min='+princemin+' --case-permute'
if pathsep=='/':
btexeccwd('../princeprocessor/pp64.bin '+princeargs+' '+d+' | '+hcbin+' -a0 -m '+hashtype+' '+pwdfile+' -r '+r+' --loopback '+trailer+skip,hashcathome,d)
else:
btexeccwd('..\\princeprocessor\\pp64.exe '+princeargs+' '+d+' | '+hcbin+' -a0 -m '+hashtype+' '+pwdfile+' -r '+r+' --loopback '+trailer+skip,hashcathome,d)
else:
if xrules is not None:
btexeccwd(hcbin+' -a0 -m '+hashtype+' '+pwdfile+' '+d+' -r '+r+' -r '+x+' --loopback '+trailer+skip,hashcathome,show,dryrun)
else:
btexeccwd(hcbin+' -a0 -m '+hashtype+' '+pwdfile+' '+d+' -r '+r+' --loopback '+trailer+skip,hashcathome,show,dryrun)
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,show,dryrun)
else:
print("Skipping inc (--noinc)")
#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 - trying as latin1")
try:
with open(file,encoding='latin1') as f:
first_line = f.readline().strip()
except:
print("Couldn't parse first line of file - giving up.")
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():
#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'
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
rules='best64.rule'
colon=''
pathstyle=''
pathsep='/'
fhash=''
crib=''
omenfile=''
prince=''
princemin='8'
princemax='999'
crackopts=" -O "
uname=''
loc=''
cygwin=0
inc=0
remove=''
incr=''
unix=0
parser = argparse.ArgumentParser(description='Helps to crack passwords')
parser.add_argument('-i','--input', help='Input file' )
parser.add_argument('--status', help='Status 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, e.g. ?a?a?a, literal "default" to use hashcat default')
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('-x','--xrules', help='Extra rules override')
parser.add_argument('--potfile', help='Potfile override')
parser.add_argument('-P','--prince', action="store_true", help='Use PRINCE preprocessor on the input dictionary')
parser.add_argument('-R','--rain', action="store_true", help='Use purple rain attack; shuf | pp64 | hashcat -g 300000')
parser.add_argument('--princemin', help='PRINCE min')
parser.add_argument('--princemax', help='PRINCE max')
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('--restore', action="store_true", help='Restore to last session')
parser.add_argument('-s','--show', action="store_true", help='Just show stuff')
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('--noinc', action="store_true", help='Do not use increment')
parser.add_argument('-u','--username', action="store_true", help='Override username flag')
parser.add_argument('-3','--leet', action="store_true", help='Use CPU leetification - slower, but does one char at a time')
parser.add_argument('-Z','--dryrun', action="store_true", help='Do not do anything, just show commands')
parser.add_argument('--debug', help='debug log file')
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
statusfile=args.status
debugfile=args.debug
show=args.show
inhash=args.hash
crib=args.crib
mask=args.mask
if infile is not None:
infile=os.path.abspath(infile)
if crib is not None:
crib=os.path.abspath(crib)
# mask can be an hcmask file
if mask is not None:
if is_non_zero_file(mask):
mask=os.path.abspath(mask)
username=args.username
skip=args.skip
dryrun=args.dryrun
leet=args.leet
restore=args.restore
remove=args.remove
force=args.force
stype=args.type
rightdict=args.rightdict
mininc=args.mininc
maxinc=args.maxinc
prince=args.prince
purplerain=args.rain
if args.princemin is not None:
princemin=args.princemin
if args.princemax is not None:
princemax=args.princemax
# todo
# omen=args.omen
p_os=platform.system()
if re.match(r'Linux',p_os):
pathstyle='unix'
unix=1
crackopts=crackopts+" -w4 "
hashcathome='./hashcat-6.2.6'
ruleshome='./hashcat-6.2.6/rules'
exe='.bin'
else:
if re.match(r'Windows',p_os):
if not show:
print("Running under win32")
exe='.exe'
hashcathome='hashcat-6.2.6' #relative path issues with 4.10
pathstyle='win32'
pathsep=r'\\'
ruleshome='hashcat-6.2.6\\rules'
crackopts=crackopts+" -w1 "
else:
print("Unknown platform")
exit
if pathsep=='/':
hcbin='./hashcat.bin'
else:
hcbin='hashcat.exe'
trailer=crackopts+' --session hc'
if debugfile is not None:
trailer=trailer+' --debug-mode=4 --debug-file='+debugfile
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_or_dir(dictoverride):
print("Can't find dictionary file/dir "+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_or_dir(rulesoverride):
print("Can't find rules file/dir "+rulesoverride)
sys.exit(1)
xrules=args.xrules
if xrules is not None:
xrules=os.path.abspath(xrules)
if not is_non_zero_file_or_dir(xrules):
print("Can't find rules file/dir "+xrules)
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-6.2.6')
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)
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'
if re.search(r'\.pfx$',infile):
hashtype='pfx'
stype='pfx'
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)
#jwt base64 decode
try:
firstdot=line.find('.')
try:
decodedBytes = base64.b64decode(line[0:firstdot])
except:
try:
decodedBytes = base64.b64decode(line[0:firstdot]+'=')
except:
try:
decodedBytes = base64.b64decode(line[0:firstdot]+'==')
except:
print("Doesn't look like base64 - no base64 decode possible")
decodedStr = str(decodedBytes[:firstdot], "ascii")
print(decodedStr)
if re.search(r'"alg"',decodedStr):
print('base64 decode suggests JWT...')
if re.search(r'"HS(256|512)"',decodedStr):
print('base64 decode suggests HMAC-based JWT, so can try to crack')
hashtype='16500'
else:
print('doesn\'t look like a crackable JWT')
except:
print("Doesn't look like a JWT")
if hashtype=='pwdump':
stype='pwdump'
if hashtype=='oracle':
stype='oracle'
print(hashtype)
# how many colons we're expecting by hash type
colonmap={ '10':1,
'11':1,
'12':1,
'20':3,
'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,
'99999':0 }
colons=line.count(':')
expectedcolons=colonmap.get(hashtype,0)
#if we've got more colons than that, need --username flag
if colons>expectedcolons:
username=1
#preprocess some types
if hashtype=='shadow':