-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.py
133 lines (112 loc) · 3.92 KB
/
config.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
"""This file contains runtime configurations"""
from common import RunningStyle, PasswordPolicyConf
from copy import deepcopy
from sys import platform
# possible jtr names
john_nick_names = [
'j', 'jtr', 'JTR', 'JtR', 'John', 'john', 'J', 'John The Ripper', 'Jtr'
]
# possible hc names
hc_nick_names = ['h', 'hc', 'HC', 'hashcat', 'H', 'Hashcat', 'Hc']
# For detailed information about what each field means, please refer to readme.md
# jtr's default configuration
jtr_default_config = {
'running_style':
RunningStyle.JTR,
'max_password_length':
127, # input/output greater than this are ignored
'min_cut_length':
128, # max_password_length + 1
'm_threshold':
2,
'executable_path':
"../JohnTheRipper/run/john"
if platform != "win32" else "../JohnTheRipper/run/john.exe",
'password_policy':
PasswordPolicyConf(),
'preprocess_path':
'../data/preprocess/',
'enable_regex':
False,
'debug':
False,
'binary_search_file_executable': # pointing to the executable for binary searching a sorted file
'look',
'lookup_threshold':
131073, #2^17 + 1
}
# hc's default configuration
hc_default_config = {
'running_style':
RunningStyle.HC,
'max_password_length':
255, # input/output greater than this are ignored
'min_cut_length':
256, # max_password_length + 1
'm_threshold':
2,
'executable_path':
"../HashcatRulesEngine/hcre"
if platform != "win32" else "../HashcatRulesEngine/hcre.exe",
'password_policy':
PasswordPolicyConf(),
'preprocess_path':
'../data/preprocess/',
'enable_regex':
False,
'debug':
False,
'binary_search_file_executable': # pointing to the executable for binary searching a sorted file
'look',
'lookup_threshold':
131073, #2^17 + 1
'batch_size_of_words':
1024 * 1024,
'batch_size_of_rules':
'auto', # either an int or auto
}
# caution, unix default look only supports look up on file < 2GB
class Configuration():
""" Contains the running config, it constructs a dictioanry """
def __init__(self, running_style=RunningStyle.JTR, **kwargs):
""" Initialize a configuration dict.
Args:
running_style: either JTR/HC
kwargs: optional args, set specific field in the dictionary.
"""
self.config = deepcopy(
hc_default_config
) if running_style == RunningStyle.HC else deepcopy(jtr_default_config)
for k, v in kwargs.items():
self.config[k] = v
def __setitem__(self, key, item):
self.config[key] = item
def __getitem__(self, key):
return self.config[key]
def reset_to_hc(self, **kwargs):
""" reset configuration to HC default, also support setting specific field """
self.config = deepcopy(hc_default_config)
for k, v in kwargs.items():
self.config[k] = v
def reset_to_jtr(self, **kwargs):
""" reset configuration to JTR default, also support setting specific field """
self.config = deepcopy(jtr_default_config)
for k, v in kwargs.items():
self.config[k] = v
def is_jtr(self):
""" return True if running on JTR mode """
return self.config['running_style'] == RunningStyle.JTR
def is_hc(self):
""" return True if running on HC mode """
return self.config['running_style'] == RunningStyle.HC
def short_config_string(self):
""" get quick info of configuration """
return "{}(WL) {}(RL) {}(Testset) {}".format(
self['wordlist_path']['name'], self['rulelist_path']['name'],
self['pwlist_path']['name'], self['running_style'])
def get_log_addr(self):
""" get log file addr"""
return "../results/demo_file-{}-{}-{}.log".format(
self['wordlist_path']['name'], self['rulelist_path']['name'],
self['pwlist_path']['name'])
RUNTIME_CONFIG = Configuration()