-
Notifications
You must be signed in to change notification settings - Fork 4
/
hashcat_maskprocessor_extension.py
173 lines (135 loc) · 4.87 KB
/
hashcat_maskprocessor_extension.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
from burp import IBurpExtender
from burp import IIntruderPayloadGeneratorFactory
from burp import IIntruderPayloadGenerator
from burp import IIntruderPayloadProcessor
''' Lines 8 up to 120 Credits to the original coder https://github.com/Xvezda/python-maskprocessor edited a little bit code to fit Burp Extension '''
import sys
import string
from itertools import product
charset_l = string.ascii_lowercase
charset_u = string.ascii_uppercase
charset_d = string.digits
charset_s = ' ' + string.punctuation
charset_a = charset_l + charset_u + charset_d + charset_s
charset_b = ''.join([chr(v) for v in range(0x00, 0xff+1)])
charset_1 = ''
charset_2 = ''
charset_3 = ''
charset_4 = ''
def expand(mask):
if not mask:
return []
charsets = []
it = iter(mask)
while True:
try:
c = next(it)
except StopIteration:
break
if c == '?':
try:
c2 = next(it)
except StopIteration:
break
if c2 == 'l':
charsets += [charset_l]
elif c2 == 'u':
charsets += [charset_u]
elif c2 == 'd':
charsets += [charset_d]
elif c2 == 's':
charsets += [charset_s]
elif c2 == 'a':
charsets += [charset_a]
elif c2 == 'b':
charsets += [charset_b]
elif c2 == '1':
charsets += [charset_1]
elif c2 == '2':
charsets += [charset_2]
elif c2 == '3':
charsets += [charset_3]
elif c2 == '4':
charsets += [charset_4]
elif c2 == '?':
charsets += ['?']
else:
raise SyntaxError("invalid character '%s'" % (c2,))
else:
charsets += [c]
return charsets
def maskprocessor(mask,
custom_charset1=None,
custom_charset2=None,
custom_charset3=None,
custom_charset4=None):
charsets = []
global charset_1, charset_2, charset_3, charset_4
charset_1 = ''.join(expand(custom_charset1))
charset_2 = ''.join(expand(custom_charset2))
charset_3 = ''.join(expand(custom_charset3))
charset_4 = ''.join(expand(custom_charset4))
charsets = expand(mask)
for result in product(*charsets):
yield ''.join(result)
def mask_main(arg1):
import argparse
from textwrap import dedent
spl1 = arg1.split()
spl1.insert(0, '')
sys.argv= spl1
parser = argparse.ArgumentParser(
'maskprocessor',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=dedent(""),
epilog=dedent(""))
parser.add_argument('mask', type=str)
custom_charset_group = parser.add_argument_group()
custom_charset_group.add_argument('--custom-charset1', '-1', type=str, metavar='CS')
custom_charset_group.add_argument('--custom-charset2', '-2', type=str, metavar='CS')
custom_charset_group.add_argument('--custom-charset3', '-3', type=str, metavar='CS')
custom_charset_group.add_argument('--custom-charset4', '-4', type=str, metavar='CS')
args = parser.parse_args()
global i
i = maskprocessor(args.mask,
custom_charset1=args.custom_charset1,
custom_charset2=args.custom_charset2,
custom_charset3=args.custom_charset3,
custom_charset4=args.custom_charset4)
class BurpExtender(IBurpExtender, IIntruderPayloadGeneratorFactory, IIntruderPayloadProcessor):
def registerExtenderCallbacks(self, callbacks):
# obtain an extension helpers object
self._helpers = callbacks.getHelpers()
# set our extension name
callbacks.setExtensionName("Hashcat Maskprocessor")
# register ourselves as an Intruder payload generator
callbacks.registerIntruderPayloadGeneratorFactory(self)
# register ourselves as an Intruder payload processor
callbacks.registerIntruderPayloadProcessor(self)
def getGeneratorName(self):
return "hashcat maskprocessor"
def createNewInstance(self, attack):
return IntruderPayloadGenerator()
def getProcessorName(self):
return "Not Implemented"
def processPayload(self, currentPayload, originalPayload, baseValue):
print "ProcessPayload Not Implemented"
pass
class IntruderPayloadGenerator(IIntruderPayloadGenerator):
def __init__(self):
global x
x = 0
pass
def hasMorePayloads(self):
return True
def getNextPayload(self, baseValue):
global x
if x == 0:
mask_main(str(bytearray(baseValue)))
x = x + 1
try:
return (next(i))
except StopIteration:
return
def reset(self):
return