-
Notifications
You must be signed in to change notification settings - Fork 1
/
decoder.py
361 lines (312 loc) · 13.4 KB
/
decoder.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#
# Author: SeTX[X] --<setx [at] s3tx [dot] ru>
# Purpose: Data decoder
# Created: 09/02/2013
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
#
"""
Tipical and most used combinations
-s "i>b" -> eval(gzinflate(base64_decode('Code')))
-s "i>r>b" -> eval(gzinflate(str_rot13(base64_decode('Code'))))
-s "i>b>r" -> eval(gzinflate(base64_decode(str_rot13('Code'))))
-s "i>b>b>r" -> eval(gzinflate(base64_decode(base64_decode(str_rot13('Code')))))
-s "u>b" -> eval(gzuncompress(base64_decode('Code')))
-s "u>r>b" -> eval(gzuncompress(str_rot13(base64_decode('Code'))))
-s "u>b>r" -> eval(gzuncompress(base64_decode(str_rot13('Code'))))
-b -> eval(base64_decode('Code'))
-s "r>i>b" -> eval(str_rot13(gzinflate(base64_decode('Code'))))
-s "i>b>t>r" -> eval(gzinflate(base64_decode(strrev(str_rot13('Code')))))
-s "i>b>t" -> eval(gzinflate(base64_decode(strrev('Code'))))
-s "i>b>r" -> eval(gzinflate(base64_decode(str_rot13('Code'))))
-s "i>b>r>t" -> eval(gzinflate(base64_decode(str_rot13(strrev('Code')))))
-s "b>u>b" -> eval(base64_decode(gzuncompress(base64_decode('Code'))))
-s "i>b>l" -> eval(gzinflate(base64_decode(rawurldecode('Code'))))
"""
from sys import argv, exit
import zlib
import argparse
from urllib import quote, unquote
#----------------------------------------------------------------------
def checkArgs():
""""""
if len(argv) < 2:
parser.print_help()
exit(-1)
########################################################################
class decoder:
""""""
#----------------------------------------------------------------------
def __init__(self, input_data = None, file = False):
"""Constructor"""
if file:
f = open(file, 'rb')
self.data = f.read()
f.close()
elif input_data:
self.data = input_data
else:
return None
#----------------------------------------------------------------------
def base64(self, data = None, encode = False):
"""Return the encoded or decoded in Base64, string or file data"""
try:
if not encode:
if data:
return data.decode("base64")
else:
return self.data.decode("base64")
else:
if data:
return data.encode("base64")
else:
return self.data.encode("base64")
except Exception, e:
return '[!] Error Base64: %s.' % e
#----------------------------------------------------------------------
def zlib_gzun(self, compress = False, data = None):
"""Return the compressed or decompressed with Zlib, string or file data"""
if not compress:
try:
if data:
return zlib.decompress(data)
else:
return zlib.decompress(self.data)
except Exception, e:
return '[!] Error Zlib decompress: %s.' % e
else:
try:
if data:
return zlib.compress(data)
else:
return zlib.compress(self.data)
except Exception, e:
return '[!] Error Zlib compress: %s.' % e
#----------------------------------------------------------------------
def zlib_gzin(self, compress = False, data = None):
"""Return the compressed or decompressed object with Zlib, string or file data"""
if not compress:
try:
if data:
return zlib.decompressobj().decompress('x\x9c' + data)
else:
return zlib.decompressobj().decompress('x\x9c' + self.data)
except Exception, e:
return '[!] Error Zlib inflate decompress: %s.' % e
else:
try:
if data:
return ((zlib.compress(data))[2:])[:-4]
else:
return ((zlib.compress(self.data))[2:])[:-4]
except Exception, e:
return '[!] Error Zlib inflate compress: %s.' % e
#----------------------------------------------------------------------
def hex(self, encode = False, data = None):
"""Return the encoded or decoded in Hex, string or file data"""
out = ""
if data:
if data.upper().startswith('0X'):
array = data.split('0x')
array = filter(None, array)
for char in array:
out += char
else:
out = data
else:
if self.data.upper().startswith('0X'):
array = self.data.split('0x')
array = filter(None, array)
for char in array:
out += char
else:
out = self.data
if not encode:
try:
return out.decode("hex")
except Exception, e:
return '[!] Error HEX decoding: %s.' % e
else:
try:
return out.encode("hex")
except Exception, e:
return '[!] Error HEX encoding: %s.' % e
#----------------------------------------------------------------------
def rot_13(self, data = None, encode = False):
"""Decodes and encodes rot_13 method"""
try:
if not encode:
if data:
return data.decode("rot_13")
else:
return self.data.decode("rot_13")
else:
if data:
return data.encode("rot_13")
else:
return self.data.encode("rot_13")
except Exception, e:
return '[!] Error Rot_13: %s.' % e
#----------------------------------------------------------------------
def strrev(self, data = None):
"""Returns reversed data"""
try:
if data:
return data[::-1]
else:
return self.data[::-1]
except Exception, e:
return '[!] Error strrev: %s.' % e
#----------------------------------------------------------------------
def rawurldecode(self, data = None, encode = False):
"""Encode or decode with rawurl method"""
try:
if not encode:
if data:
return unquote(data)
else:
return unquote(self.data)
else:
if data:
return quote(data)
else:
return quote(self.data)
except Exception, e:
return '[!] Error rawurldecode: %s.' % e
#----------------------------------------------------------------------
def output_Write(self, output_file, data):
"""Writes the parsed output to file"""
try:
f = open(output_file, 'wb')
f.write(data)
f.close
return '[*] Work Done! File "%s" has been saved.' % output_file
except Exception, e:
return '[!] Error Output Write: %s.' % e
#----------------------------------------------------------------------
def sequence(self, sequence, encode = False):
"""
Parses sequence of methods to be applied
e.g.
b>i>b
Base64(data) then Zlib_inflate(data) and then another Base64(date)
methods will be applied
"""
array = []
try:
out = self.data
array = filter(None, sequence.split('>'))
for method in array:
out = self.wrapper(method = method, data = out, encode = encode)
return out
except Exception, e:
return '[!] Error Sequence: %s.' % e
#----------------------------------------------------------------------
def wrapper(self, method, data = None, encode = False):
"""Returns the parsed data with the function according to the indicated method"""
if method == 'b':
return self.base64(data = data, encode = encode)
elif method == 'i':
return self.zlib_gzin(compress = encode, data = data)
elif method == 'u':
return self.zlib_gzun(compress = encode, data = data)
elif method == 'x':
return self.hex(encode = encode, data = data)
elif method == 'r':
return self.rot_13(encode = encode, data = data)
elif method == 't':
return self.strrev(data = data)
elif method == 'l':
return self.rot_13(encode = encode, data = data)
else:
return '[!] Error Sequence: No data recieved as method.'
#----------------------------------------------------------------------
def main(input_data, file, encode = False, xor = False, base64 = False, zlib_gzun = False, hex = False, output_file = None, zlib_gzin = False, sequence = False, rot_13 = False, strrev = False, rawurldecode = False):
"""Simple main function"""
out = ''
if input_data:
dec = decoder(input_data = input_data)
elif file:
dec = decoder(file = file)
else:
print '[!] Error Input Data: The data is not specified.'
exit(-1)
if xor:
print ' [!] Error: Not yet support.'
exit(0)
elif sequence:
out = dec.sequence(sequence, encode = encode)
elif base64:
if encode:
out = dec.base64(encode = True)
else:
out = dec.base64()
elif zlib_gzun:
if encode:
out = dec.zlib_gzun(encode = True)
else:
out = dec.zlib_gzun()
elif zlib_gzin:
if encode:
out = dec.zlib_gzin(encode = True)
else:
out = dec.zlib_gzin()
elif hex:
if encode:
out = dec.hex(encode = True)
else:
out = dec.hex()
elif rot_13:
if encode:
out = dec.rot_13(encode = True)
else:
out = dec.rot_13()
elif strrev:
out = dec.strrev()
elif rawurldecode:
if encode:
out = dec.rawurldecode(encode = True)
else:
out = dec.rawurldecode()
if output_file:
print dec.output_Write(output_file = output_file, data = out)
else:
print '[*] Decoder on work...'
print '*********************************'
print out
print '*********************************'
print '[*] Work Done!'
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Version - Decoder v0.4b', prog='Decoder.py', usage=' Main options \n- %(prog)s [-e] (-s/-b/-i/-u/-x) ( -i data / -f file ) [-o output_file]\n', epilog='Для получения любой информации обращайтесь всё тудаже')
gr1 = parser.add_argument_group('Main Options')
gr1.add_argument('-f', '--file=', action='store', dest='file', default=None, help='Text file with data to be decoded or encoded')
gr1.add_argument('-d', '--data=', action='store', dest='input_data', default=None, help='Input data')
gr1.add_argument('-o', '--output=', action='store', dest='output_file', default=None, help='Output file')
gr1.add_argument('-e', action='store_true', dest='encode', default=False, help='Encode/compress data, default action is decoding/decompressing')
gr1.add_argument('-b', action='store_true', dest='base64', default=False, help='Base64 encode/decode method')
gr1.add_argument('-u', action='store_true', dest='zlib_gzun', default=False, help='Zlib "gzuncompress" compress/decompress method')
gr1.add_argument('-i', action='store_true', dest='zlib_gzin', default=False, help='Zlib "gzinflate" compress/decompress method')
gr1.add_argument('-x', action='store_true', dest='hex', default=False, help='Hex encode/decode method')
gr1.add_argument('-r', action='store_true', dest='rot_13', default=False, help='rot_13 encode/decode method')
gr1.add_argument('-t', action='store_true', dest='strrev', default=False, help='strrev encode/decode method')
gr1.add_argument('-l', action='store_true', dest='rawurldecode', default=False, help='rawurldecode encode/decode method')
gr1.add_argument('-s', action='store', dest='sequence', default=None, help='Decoding sequence e.g.(-s "b>i>b")')
gr1.add_argument('-v', '--version', action='version', version='%(prog)s v0.4b')
checkArgs()
args = parser.parse_args()
xor = False
main(args.input_data, args.file, args.encode, xor, args.base64, args.zlib_gzun, args.hex, args.output_file, args.zlib_gzin, args.sequence, args.rot_13, args.strrev, args.rawurldecode)