2013-02-14 15:32:17 +04: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
|
|
|
|
2017-01-02 16:19:18 +03:00
|
|
|
Copyright (c) 2006-2017 sqlmap developers (http://sqlmap.org/)
|
2010-10-15 03:18:29 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
2010-01-27 16:56:26 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
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
|
|
|
|
|
|
|
|
def hideAscii(data):
|
|
|
|
retVal = ""
|
|
|
|
for i in xrange(len(data)):
|
|
|
|
if ord(data[i]) < 128:
|
|
|
|
retVal += chr(ord(data[i]) ^ 127)
|
|
|
|
else:
|
|
|
|
retVal += data[i]
|
2010-07-30 16:49:25 +04:00
|
|
|
|
2010-01-27 16:56:26 +03:00
|
|
|
return retVal
|
|
|
|
|
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
|
|
|
|
2015-08-31 15:27:47 +03:00
|
|
|
return hideAscii(zlib.compress(data))
|
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:
|
2015-08-31 15:27:47 +03:00
|
|
|
data = zlib.decompress(hideAscii(data))
|
2015-08-31 15:50:51 +03:00
|
|
|
except:
|
2011-04-15 16:58:56 +04:00
|
|
|
print 'ERROR: the provided input file \'%s\' does not contain valid cloaked content' % inputFile
|
|
|
|
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]
|
2011-04-30 17:20:05 +04:00
|
|
|
parser = OptionParser(usage=usage, version='0.1')
|
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')
|
|
|
|
|
|
|
|
except (OptionError, TypeError), e:
|
|
|
|
parser.error(e)
|
2010-11-03 13:08:27 +03:00
|
|
|
|
2010-01-27 17:27:11 +03:00
|
|
|
if not os.path.isfile(args.inputFile):
|
2011-04-15 16:58:56 +04: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()
|