) handler = MyHandler( recv, send, orch) # Instantiate the Handler Object using the network wrappers def serveForever(): global client global client_addr while True: # Make it listen `hard` client_new, client_addr = server_socket.accept() client = client_new server_thread = Thread(target=serveForever) server_thread.daemon = True server_thread.start() #========================================================================== #============================== Shell Design part ======================== shell = ExtendableShell( handler, ignore_messages=set(['X']) # It is also the default argument in BaseShell ) shell.start() #========================================================================== # Magic!
print( "Accepting" ) client, client_addr = s.accept() # Blocking the main thread print( "Accepted" ) def recv () : # Create wrappers for networking return client.recv( 50 ) def send( raw ) : # Create wrappers for networking return client.send( raw ) class MyHandler( BaseHandler ) : def onChunk( self, stream, message ) : pass def onMessage( self, stream, message ) : # print( message ) pass def onNotRecognised( self ) : print( "Got Garbage!" ) global s s.close() handler = MyHandler( recv, send, orch ) shell = ExtendableShell(handler, prompt = "(%s:%d)> " % client_addr ) shell.start()
agent = ExtendableShellHandler(dummy_receive1, dummy_send1, orch1) class MyHandler(BaseHandler): def onMessage(self, stream, message): global chunks_sent print("Handler: Chunks Received: %d" % chunks_sent) chunks_sent = 0 # print( message ) pass def onChunk(self, stream, message): global chunks_sent if chunks_sent == 0: print # chunks_sent += 1logname # print( "Handler: <Chunk>" ) pass def onNotRecognised(self, stream, message): # print( "Handler: <Unrecognised>" ) pass handler = MyHandler(dummy_receive2, dummy_send2, orch2) # shell = ExtendableShell(handler, output = '/tmp/covertutils_out') shell = ExtendableShell(handler, ) shell.start()
def recv () : # Create wrappers for networking return client.recv( 20 ) def send( raw ) : # Create wrappers for networking return client.send( raw ) from covertutils.handlers import BaseHandler class MyHandler_Handler( BaseHandler ) : """ This class tries hard to be self-explanatory """ def __init__(self, recv, send, orch, **kw) : super( MyHandler_Handler, self ).__init__( recv, send, orch, **kw ) print ( "[!] Handler with Orchestrator ID: '{}' started!".format( orch.getIdentity() ) ) def onMessage( self, stream, message ) : pass def onChunk( self, stream, message ) : pass def onNotRecognised(self) : pass handler_obj = MyHandler_Handler(recv, send, orch_obj) from covertutils.shells.impl import ExtendableShell shell = ExtendableShell(handler_obj, prompt = "[MyFirst '{package}' Shell] > ") shell.start()
class MyHandler(BaseHandler): def onMessage(self, stream, message): # global chunks_sent # print( "Handler: Chunks Received: %d" % chunks_sent ) chunks_sent = 0 # print( message ) pass def onChunk(self, stream, message): # global chunks_sent # if chunks_sent == 0 : # print # chunks_sent += 1logname # print( "Handler: <Chunk>" ) pass def onNotRecognised(self, stream, message): # print( "Handler: <Unrecognised>" ) pass handler = MyHandler(dummy_receive2, dummy_send2, orch2) # shell = ExtendableShell(handler, output = '/tmp/covertutils_out') # shell = ExtendableShell(handler, output='/tmp/covertutils_session1') shell = ExtendableShell(handler, output=True) shell.start(False)
#========================================================================== # #=============================Handler Creation============================= orchestrator = SimpleOrchestrator( passphrase, # Encryption keys generated from the passphrase tag_length = 2, # The tag length in bytes out_length = 16, # The absolute output byte length (with tags) in_length = 35, # The absolute input byte length (with tags) # streams = ['heartbeat'], # Stream 'control' will be automatically added as failsafe mechanism reverse = True ) # Reverse the encryption channels - Agent has `reverse = False` handler = Handler( recv, send, orchestrator, request_data = 'X' ) # Instantiate the Handler object. Finally! #========================================================================== #============================== Shell Design part ======================== shell = ExtendableShell( handler, ignore_messages = 'X' ) # 'X' is used for polling shell.start( False ) import os os._exit(-1) udp_server.stop_thread() #========================================================================== # Magic!