import cmd
import re
from covertutils.shells.subshells import SimpleSubShell
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
[docs]def show( mixed_shellcode ) :
print( "Pasted lines:" )
print( mixed_shellcode )
print( "" )
try :
pure_shellcode = format_shellcode( mixed_shellcode )
print( "Length of %d bytes" % len(pure_shellcode) )
print( "" )
print( "Shellcode in HEX :" )
print( pure_shellcode.encode('hex') )
print( "" )
print( "Shellcode in BINARY :" )
print( pure_shellcode )
except TypeError:
print( "Shellcode buffer could not be formatted" )
print( "Pasted half a line?" )
[docs]class ShellcodeSubShell ( SimpleSubShell ) :
intro = '''This shell will properly format shellcode
pasted from sources like "exploit-db.com" and "msfvenom"'''
fire_word = 'GO'
[docs] def __init__( self, stream, handler, queue_dict, base_shell, ignore_messages = set(['X']), prompt_templ = "[{stream}]> ") :
# print( ShellcodeSubShell )
SimpleSubShell.__init__( self, stream, handler, queue_dict, base_shell, ignore_messages, prompt_templ )
self.shellcode_buffer = ''
[docs] def default( self, line ) :
print( "" )
print( "Type '%s' when done pasting..." % self.fire_word )
if line.strip() == self.fire_word :
if not self.shellcode_buffer :
print( "No shellcode is pasted" )
return
pure_shellcode = format_shellcode( self.shellcode_buffer )
self.do_show('')
if not self.confirm() :
print( "Shellcode NOT sent..." )
print( "You can clear the buffer with 'clear'" )
return
self.handler.preferred_send( pure_shellcode, self.stream )
self.shellcode_buffer = ''
return
self.shellcode_buffer += line+'\n'
[docs] def confirm( self ) :
option = raw_input("Send the shellcode over? [y/N] ")
return option.lower() == 'y'
[docs] def do_clear( self, line ) :
self.shellcode_buffer = ''
print( "Buffer cleared!" )
[docs] def do_show( self, line ) :
print( self.ruler*20 )
show( self.shellcode_buffer )
print( self.ruler*20 )