-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshencode.py
277 lines (250 loc) · 10.1 KB
/
shencode.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
import os
from utils.args import parse_arguments
from utils.helper import nstate as nstate
from utils.helper import FileCheck
import utils.hashes as hashes
import utils.header
## Migrate Mods
import modules.aes as aes
import modules.bytebert as bytebert
import modules.byteswap as byteswap
import modules.extract as extract
import modules.feed as feed
import modules.formatout as formatout
import utils.helper
if os.name == 'nt':
import modules.injection as injection
import modules.meterpreter as meterpreter
import modules.msfvenom as msf
import modules.output as output
import modules.qrcode as qrcode
if os.name == 'nt':
import modules.rolhash as rolhash
import modules.sliver as sliver
import modules.uuid as uuid
import modules.xor as xor
import modules.xorpoly as xorpoly
Version = '0.7.1'
banner = 0
print(f"{nstate.HEADER}")
print(f'{utils.header.get_header(banner)}')
print(f'Version {Version} by psycore8 -{nstate.ENDC} {nstate.TextLink('https://www.nosociety.de')}\n')
arguments = parse_arguments()
# make sure your metasploit binary folder is in your PATH variable
if os.name == 'nt':
msfvenom_path = "msfvenom.bat"
tpl_path = 'tpl\\'
elif os.name == 'posix':
msfvenom_path = 'msfvenom'
tpl_path = 'tpl/'
def main(command_line=None):
# print(f"{nstate.HEADER}")
# print(f'{utils.header.get_header()}')
# print(f'Version {Version} by psycore8 -{nstate.ENDC} {nstate.TextLink('https://www.nosociety.de')}')
if arguments.command == 'msfvenom':
print(f"{nstate.OKBLUE} create payload")
cs = msf.msfvenom(arguments.cmd)
cs.CreateShellcodeEx(msfvenom_path)
if arguments.command == 'output':
mod = output.format_shellcode(arguments.input, arguments.syntax, arguments.bytes_per_row, arguments.decimal, arguments.lines, arguments.no_line_break, arguments.output)
print(f'Input file: {mod.input_file}')
filecheck, outstrings = FileCheck.CheckSourceFile(mod.input_file, 'MOD-OUT')
for string in outstrings:
print(f'{string}')
if filecheck:
print(f"{nstate.OKBLUE} processing shellcode format... NoLineBreak: {mod.no_line_break}\n")
print(F'{mod.process()}')
else:
exit()
if mod.cFile:
print(f'Output file: {mod.output_file}')
filecheck, outstrings = FileCheck.CheckWrittenFile(mod.output_file, 'XOR-POLY')
for string in outstrings:
print(f'{string}')
print(f"{nstate.OKGREEN} DONE!")
elif arguments.command == 'meterpreter':
stager = meterpreter.stage(arguments.remote_host, arguments.port, arguments.timeout, arguments.arch, arguments.sleep)
stager.process()
elif arguments.command == 'sliver':
stager = sliver.stage(arguments.remote_host, arguments.port)
stager.process()
elif arguments.command == 'bytebert':
bb = bytebert.bb_encoder(arguments.input, arguments.output, arguments.variable_padding)
bb.process()
elif arguments.command == 'xorpoly':
poly = xorpoly.xor(arguments.input, arguments.output, b'', b'', f'{tpl_path}xor-stub.tpl', arguments.key)
xor_enc = xor.xor_encoder('', '', 0)
filecheck, outstrings = FileCheck.CheckSourceFile(poly.input_file, 'XOR-POLY')
for string in outstrings:
print(f'{string}')
if filecheck:
with open(poly.input_file, "rb") as file:
shellcode = file.read()
else:
exit()
poly.xored_shellcode = xor_enc.xor_crypt_bytes(shellcode, int(poly.xor_key))
poly.process()
filecheck, outstrings = FileCheck.CheckWrittenFile(poly.output_file, 'XOR-POLY')
for string in outstrings:
print(f'{string}')
elif arguments.command == 'byteswap':
swapper = byteswap.xor(arguments.input, arguments.output, f'{tpl_path}byteswap-short.tpl', arguments.key)
filecheck, outstrings = FileCheck.CheckSourceFile(swapper.input_file, 'XOR-SWAP')
for string in outstrings:
print(f'{string}')
if filecheck:
with open(swapper.input_file, "rb") as file:
shellcode = file.read()
else:
exit()
swapper.process()
filecheck, outstrings = FileCheck.CheckWrittenFile(swapper.output_file, 'XOR-SWAP')
for string in outstrings:
print(f'{string}')
elif arguments.command == 'aes':
aes_enc = aes.aes_encoder(arguments.mode, arguments.input, arguments.output, arguments.key, b'')
print(f'{nstate.OKBLUE} [AES] Module')
aes_enc.key = aes_enc.key.encode('utf-8')
if aes_enc.mode == 'encode':
print(f'{nstate.OKBLUE} [AES] ENCRYPT')
filecheck, outstrings = FileCheck.CheckSourceFile(aes_enc.input_file, 'AES-ENC')
for string in outstrings:
print(f'{string}')
if filecheck:
aes_enc.encode()
filecheck, outstrings = FileCheck.CheckWrittenFile(aes_enc.output_file, 'AES-ENC')
for string in outstrings:
print(f'{string}')
else:
exit()
elif aes_enc.mode == 'decode':
print(f'{nstate.OKBLUE} [AES] DECRYPT')
filecheck, outstrings = FileCheck.CheckSourceFile(aes_enc.input_file, 'AES-DEC')
for string in outstrings:
print(f'{string}')
if filecheck:
aes_enc.decode()
filecheck, outstrings = FileCheck.CheckWrittenFile(aes_enc.output_file, 'AES-DEC')
for string in outstrings:
print(f'{string}')
else:
exit()
elif arguments.command == 'uuid':
short_fn = os.path.basename(arguments.input)
uuid_obf = uuid.uuid_obfuscator(arguments.input, '', '', 0)
print(f"{nstate.OKBLUE} try to open file")
if uuid_obf.open_file(uuid_obf.input_file):
print(f"{nstate.OKGREEN} reading {short_fn} successful!")
else:
print(f"{nstate.FAIL} file not found, exit")
print(f"{nstate.OKBLUE} try to generate UUIDs")
print(uuid_obf.CreateVar())
elif arguments.command == 'feed':
feed_obf = feed.feed_obfuscator(arguments.input, arguments.output, arguments.uri)
if feed_obf.uri:
feed_obf.reassemble_shellcode()
filecheck, outstrings = FileCheck.CheckSourceFile(feed_obf.output_file, 'OBF-RSS')
for string in outstrings:
print(string)
exit()
filecheck, outstrings = FileCheck.CheckSourceFile(feed_obf.input_file, 'OBF-RSS')
for string in outstrings:
print(string)
if filecheck:
feed_obf.open_file()
feed_obf.convert_bytes_to_fake_id()
feed_obf.generate_feed()
else:
exit()
filecheck, outstrings = FileCheck.CheckSourceFile(feed_obf.output_file, 'OBF-RSS')
for string in outstrings:
print(string)
elif arguments.command == 'qrcode':
qr = qrcode.qrcode_obfuscator(arguments.input, arguments.output, '')
filecheck, outstrings = FileCheck.CheckSourceFile(qr.input_file, 'OBF-QRC')
for string in outstrings:
print(f'{string}')
if filecheck:
qr.open_file()
qr.process()
else:
exit()
filecheck, outstrings = FileCheck.CheckWrittenFile(qr.output_file, 'OBF-QRC')
for string in outstrings:
print(f'{string}')
elif arguments.command == 'formatout':
fout = formatout.format(arguments.input, arguments.syntax, arguments.lines, arguments.no_break, arguments.write, arguments.bytes_per_row)
print(fout.input_file)
print(f"{nstate.OKBLUE} processing shellcode format... NoLineBreak: {fout.no_break}")
scFormat = fout.process()
print(scFormat)
if arguments.write:
fout.WriteToTemplate(fout.write_out, scFormat)
print(f"{nstate.OKGREEN} Output written in buf {fout.write_out}")
print(f"{nstate.OKGREEN} DONE!")
elif arguments.command == 'rolhash':
r2l = rolhash.ror2rol_obfuscator(arguments.input, arguments.output, arguments.key)
filecheck, outstrings = FileCheck.CheckSourceFile(r2l.input_file, 'ROR2ROL')
for string in outstrings:
print(f'{string}')
if filecheck:
ror_key = int(r2l.key)
if (ror_key < 32) or (ror_key > 255):
print(f"{nstate.FAIL} Key must be between 33 and 255")
exit()
r2l.process()
else:
exit()
filecheck, outstrings = FileCheck.CheckWrittenFile(r2l.output_file, 'ROR2ROL')
for string in outstrings:
print(f'{string}')
elif arguments.command == 'xor':
xor_encoder = xor.xor_encoder(arguments.input, arguments.output, arguments.key)
print(f"{nstate.OKBLUE} Reading shellcode")
filecheck, outstrings = FileCheck.CheckSourceFile(xor_encoder.input_file, 'XOR-ENC')
for strings in outstrings:
print(f'{strings}')
if filecheck:
with open(arguments.input, "rb") as file:
shellcode = file.read()
else:
exit()
modified_shellcode = xor_encoder.xor_crypt_bytes(shellcode, int(xor_encoder.xor_key))
with open(xor_encoder.output_file, 'wb') as file:
file.write(modified_shellcode)
filecheck, outstrings = FileCheck.CheckWrittenFile(xor_encoder.output_file, 'XOR-ENC')
for strings in outstrings:
print(f'{strings}')
if not filecheck:
exit()
elif arguments.command == 'injection':
code_injection = injection.inject(arguments.input, arguments.start, arguments.process, '', arguments.resume_thread, arguments.virtual_protect)
print(f"{nstate.OKBLUE} Reading shellcode")
filecheck, outstrings = FileCheck.CheckSourceFile(code_injection.input_file, 'iNJECT')
for strings in outstrings:
print(f'{strings}')
if filecheck:
with open(code_injection.input_file, "rb") as file:
code_injection.shellcode = file.read()
code_injection.start_injection()
elif arguments.command == 'extract':
ext = extract.extract_shellcode(arguments.input, arguments.output, arguments.start_offset, arguments.end_offset)
filecheck, outstrings = FileCheck.CheckSourceFile(ext.input_file, 'XTRACT')
for string in outstrings:
print(f'{string}')
if filecheck:
ext.process()
else:
exit()
filecheck, outstrings = FileCheck.CheckSourceFile(ext.output_file, 'XTRACT')
for string in outstrings:
print(f'{string}')
elif arguments.version:
print(f'ShenCode {Version}')
if __name__ == "__main__":
# if arguments.banner > 0:
# print(f'{arguments.banner}')
# banner = arguments.banner
#utils.helper.FirstRun.CheckFirstRunState()
#print(args)
main()