2018-07-23 08:55:15 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2019-03-11 20:46:55 +00:00
|
|
|
import zlib, argparse, os, re, datetime, time, base64, string, random, codecs, glob
|
|
|
|
from Config import HTTPResponses, POSHDIR, PayloadsDirectory
|
2019-03-10 17:11:22 +00:00
|
|
|
from Utils import randomuri
|
2019-03-11 20:46:55 +00:00
|
|
|
from TabComplete import readline, tabCompleter
|
|
|
|
from Help import COMMANDS
|
2018-07-23 08:55:15 +00:00
|
|
|
|
|
|
|
def default_response():
|
|
|
|
return (random.choice(HTTPResponses)).replace("#RANDOMDATA#",randomuri())
|
|
|
|
|
|
|
|
def load_module(module_name):
|
|
|
|
file = codecs.open(("%sModules/%s" % (POSHDIR,module_name)), 'r', encoding='utf-8-sig')
|
|
|
|
return file.read()
|
|
|
|
|
2018-12-27 12:10:46 +00:00
|
|
|
def load_module_sharp(module_name):
|
|
|
|
file = open(("%sModules/%s" % (POSHDIR,module_name)), 'r+b')
|
|
|
|
return base64.b64encode(file.read())
|
|
|
|
|
2018-07-23 08:55:15 +00:00
|
|
|
def get_images():
|
|
|
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
rootimagedir = "%s/Images/" % dir_path
|
|
|
|
images = ""
|
|
|
|
for root, dirs, filenames in os.walk(rootimagedir):
|
|
|
|
count = 1
|
2018-12-27 12:10:46 +00:00
|
|
|
for f in filenames:
|
2018-07-23 08:55:15 +00:00
|
|
|
if count == 5:
|
|
|
|
with open(rootimagedir+f, "rb") as image_file:
|
|
|
|
image = image_file.read()
|
|
|
|
if len(image) < 1500:
|
|
|
|
images += "\"%s\"" % (base64.b64encode(image))
|
|
|
|
if count < 5:
|
|
|
|
with open(rootimagedir+f, "rb") as image_file:
|
|
|
|
image = image_file.read()
|
|
|
|
if len(image) < 1500:
|
|
|
|
images += "\"%s\"," % (base64.b64encode(image))
|
|
|
|
count += 1
|
|
|
|
return images
|
|
|
|
|
2018-12-27 12:10:46 +00:00
|
|
|
# Decrypt a string from base64 encoding
|
2018-07-23 08:55:15 +00:00
|
|
|
def get_encryption( key, iv='0123456789ABCDEF' ):
|
|
|
|
from Crypto.Cipher import AES
|
2018-09-02 19:08:53 +00:00
|
|
|
iv = os.urandom(AES.block_size)
|
2018-07-23 08:55:15 +00:00
|
|
|
aes = AES.new( base64.b64decode(key), AES.MODE_CBC, iv )
|
|
|
|
return aes
|
|
|
|
|
2018-12-27 12:10:46 +00:00
|
|
|
# Decrypt a string from base64 encoding
|
2018-07-23 08:55:15 +00:00
|
|
|
def decrypt( key, data ):
|
|
|
|
iv = data[0:16]
|
|
|
|
aes = get_encryption(key, iv)
|
|
|
|
data = aes.decrypt( base64.b64decode(data) )
|
|
|
|
return data[16:]
|
|
|
|
|
2018-12-27 12:10:46 +00:00
|
|
|
# Decrypt a string from base64 encoding
|
2018-07-23 08:55:15 +00:00
|
|
|
def decrypt_bytes_gzip( key, data):
|
|
|
|
iv = data[0:16]
|
|
|
|
aes = get_encryption(key, iv)
|
|
|
|
data = aes.decrypt( data )
|
|
|
|
import StringIO
|
|
|
|
import gzip
|
|
|
|
infile = StringIO.StringIO(data[16:])
|
|
|
|
with gzip.GzipFile(fileobj=infile, mode="r") as f:
|
|
|
|
data = f.read()
|
|
|
|
return data
|
|
|
|
|
|
|
|
# Encrypt a string and base64 encode it
|
|
|
|
def encrypt( key, data, gzip=False ):
|
|
|
|
if gzip:
|
|
|
|
print 'Gzipping data - pre-zipped len, ' + str(len(data))
|
|
|
|
import StringIO
|
|
|
|
import gzip
|
|
|
|
out = StringIO.StringIO()
|
|
|
|
with gzip.GzipFile(fileobj=out, mode="w") as f:
|
|
|
|
f.write(data)
|
2018-12-27 12:10:46 +00:00
|
|
|
data = out.getvalue()
|
2018-07-23 08:55:15 +00:00
|
|
|
|
|
|
|
# Pad with zeros
|
|
|
|
mod = len(data) % 16
|
|
|
|
if mod != 0:
|
|
|
|
newlen = len(data) + (16-mod)
|
|
|
|
data = data.ljust( newlen, '\0' )
|
2018-09-02 19:08:53 +00:00
|
|
|
aes = get_encryption(key, os.urandom(16))
|
2018-07-23 08:55:15 +00:00
|
|
|
data = aes.IV + aes.encrypt( data )
|
|
|
|
if not gzip:
|
|
|
|
data = base64.b64encode( data )
|
2018-12-27 12:10:46 +00:00
|
|
|
return data
|
2019-03-11 20:46:55 +00:00
|
|
|
|
|
|
|
def filecomplete(text, state):
|
|
|
|
os.chdir(PayloadsDirectory)
|
|
|
|
return (glob.glob(text+'*')+[None])[state]
|
|
|
|
|
|
|
|
def readfile_with_completion(message):
|
|
|
|
readline.set_completer(filecomplete)
|
|
|
|
path = raw_input(message)
|
|
|
|
t = tabCompleter()
|
|
|
|
t.createListCompleter(COMMANDS)
|
|
|
|
readline.set_completer(t.listCompleter)
|
|
|
|
return path
|