2019-03-28 18:04:38 +03:00
|
|
|
#!/usr/bin/env python
|
2010-01-27 16:56:26 +03:00
|
|
|
|
|
|
|
"""
|
2010-01-27 17:27:11 +03:00
|
|
|
cloak.py - Simple file encryption/compression utility
|
2010-10-14 18:41:14 +04:00
|
|
|
|
2020-01-01 15:25:15 +03:00
|
|
|
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2010-01-27 16:56:26 +03:00
|
|
|
"""
|
|
|
|
|
2019-01-22 03:20:27 +03:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2010-01-27 16:56:26 +03:00
|
|
|
import os
|
2019-03-28 18:04:38 +03:00
|
|
|
import struct
|
2010-01-27 16:56:26 +03:00
|
|
|
import sys
|
2013-10-02 22:32:18 +04:00
|
|
|
import zlib
|
2010-01-27 16:56:26 +03:00
|
|
|
|
|
|
|
from optparse import OptionError
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
2019-03-29 00:54:05 +03:00
|
|
|
if sys.version_info >= (3, 0):
|
2019-03-28 17:14:16 +03:00
|
|
|
xrange = range
|
2020-06-14 22:23:55 +03:00
|
|
|
ord = lambda _: _
|
2019-03-28 17:14:16 +03:00
|
|
|
|
2020-12-18 13:57:13 +03:00
|
|
|
KEY = b"cwRAopWDYixMeqs3"
|
2010-07-30 16:49:25 +04:00
|
|
|
|
2020-06-14 22:23:55 +03:00
|
|
|
def xor(message, key):
|
|
|
|
return b"".join(struct.pack('B', ord(message[i]) ^ ord(key[i % len(key)])) for i in range(len(message)))
|
2010-01-27 16:56:26 +03:00
|
|
|
|
2015-08-31 15:27:47 +03:00
|
|
|
def cloak(inputFile=None, data=None):
|
|
|
|
if data is None:
|
|
|
|
with open(inputFile, "rb") as f:
|
|
|
|
data = f.read()
|
2010-07-30 16:49:25 +04:00
|
|
|
|
2020-06-14 22:23:55 +03:00
|
|
|
return xor(zlib.compress(data), KEY)
|
2010-07-30 16:49:25 +04:00
|
|
|
|
2015-08-31 15:27:47 +03:00
|
|
|
def decloak(inputFile=None, data=None):
|
|
|
|
if data is None:
|
|
|
|
with open(inputFile, "rb") as f:
|
|
|
|
data = f.read()
|
2011-04-15 16:58:56 +04:00
|
|
|
try:
|
2020-06-14 22:23:55 +03:00
|
|
|
data = zlib.decompress(xor(data, KEY))
|
2019-03-28 18:04:38 +03:00
|
|
|
except Exception as ex:
|
|
|
|
print(ex)
|
2019-01-22 03:20:27 +03:00
|
|
|
print('ERROR: the provided input file \'%s\' does not contain valid cloaked content' % inputFile)
|
2011-04-15 16:58:56 +04:00
|
|
|
sys.exit(1)
|
|
|
|
finally:
|
|
|
|
f.close()
|
2010-07-30 16:49:25 +04:00
|
|
|
|
2010-01-27 16:56:26 +03:00
|
|
|
return data
|
|
|
|
|
|
|
|
def main():
|
|
|
|
usage = '%s [-d] -i <input file> [-o <output file>]' % sys.argv[0]
|
2020-06-14 22:23:55 +03:00
|
|
|
parser = OptionParser(usage=usage, version='0.2')
|
2010-01-27 16:56:26 +03:00
|
|
|
|
|
|
|
try:
|
|
|
|
parser.add_option('-d', dest='decrypt', action="store_true", help='Decrypt')
|
|
|
|
parser.add_option('-i', dest='inputFile', help='Input file')
|
|
|
|
parser.add_option('-o', dest='outputFile', help='Output file')
|
|
|
|
|
|
|
|
(args, _) = parser.parse_args()
|
|
|
|
|
|
|
|
if not args.inputFile:
|
|
|
|
parser.error('Missing the input file, -h for help')
|
|
|
|
|
2019-01-22 16:09:13 +03:00
|
|
|
except (OptionError, TypeError) as ex:
|
|
|
|
parser.error(ex)
|
2010-11-03 13:08:27 +03:00
|
|
|
|
2010-01-27 17:27:11 +03:00
|
|
|
if not os.path.isfile(args.inputFile):
|
2019-01-22 03:20:27 +03:00
|
|
|
print('ERROR: the provided input file \'%s\' is non existent' % args.inputFile)
|
2010-01-27 16:56:26 +03:00
|
|
|
sys.exit(1)
|
2010-07-30 16:49:25 +04:00
|
|
|
|
2010-01-27 16:56:26 +03:00
|
|
|
if not args.decrypt:
|
|
|
|
data = cloak(args.inputFile)
|
|
|
|
else:
|
|
|
|
data = decloak(args.inputFile)
|
|
|
|
|
|
|
|
if not args.outputFile:
|
|
|
|
if not args.decrypt:
|
|
|
|
args.outputFile = args.inputFile + '_'
|
|
|
|
else:
|
|
|
|
args.outputFile = args.inputFile[:-1]
|
2010-07-30 16:49:25 +04:00
|
|
|
|
2011-04-15 16:58:56 +04:00
|
|
|
f = open(args.outputFile, 'wb')
|
|
|
|
f.write(data)
|
|
|
|
f.close()
|
2010-01-27 16:56:26 +03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2010-06-10 01:43:22 +04:00
|
|
|
main()
|