2525from .ScriptPanel import Script
2626from .AssistantPanel import Assistant
2727from .TerminalModules .Credentials import credentials
28+ from .grpc_status import is_response_ok , response_message
2829
2930
3031#
@@ -598,8 +599,12 @@ def runCommand(self):
598599 command = commandLine ,
599600 )
600601 response = self .grpcClient .getCommandHelp (command )
601- self .printInTerminal (response .command , "" , "" )
602- self .printInTerminal ("" , response .command , response .help )
602+ command_text = getattr (response , "command" , commandLine ) or commandLine
603+ self .printInTerminal (command_text , "" , "" )
604+ if is_response_ok (response ):
605+ self .printInTerminal ("" , command_text , response .help )
606+ else :
607+ self .printInTerminal ("" , command_text , response_message (response , "No help available." ))
603608
604609 else :
605610 self .printInTerminal (commandLine , "" , "" )
@@ -614,10 +619,20 @@ def runCommand(self):
614619 )
615620 result = self .grpcClient .sendSessionCommand (command )
616621 command_id = getattr (result , "command_id" , command_id ) or command_id
622+ if not is_response_ok (result ):
623+ message = response_message (result , "Command was rejected by TeamServer." )
624+ self .printInTerminal ("" , commandLine , message )
625+ with open (os .path .join (logsDir , self .logFileName ), 'a' ) as logFile :
626+ logFile .write ('[+] rejected: \" ' + commandLine + '\" ' )
627+ logFile .write ('\n ' + message + '\n ' )
628+ self .setCursorEditorAtEnd ()
629+ return
630+
617631 context = "Host " + self .hostname + " - Username " + self .username
618632 self .consoleScriptSignal .emit ("send" , self .beaconHash , self .listenerHash , context , commandLine , "" , command_id )
619- if result .message :
620- self .printInTerminal ("" , commandLine , result .message )
633+ ack_message = response_message (result )
634+ if ack_message :
635+ self .printInTerminal ("" , commandLine , ack_message )
621636
622637 self .setCursorEditorAtEnd ()
623638
@@ -630,6 +645,8 @@ def displayResponse(self):
630645 listener_hash = response .session .listener_hash or self .listenerHash
631646 command_text = response .command or response .instruction
632647 decoded_response = response .output .decode ('utf-8' , 'replace' )
648+ if not is_response_ok (response ):
649+ decoded_response = response_message (response ) or decoded_response or "Command failed."
633650 self .consoleScriptSignal .emit ("receive" , self .beaconHash , listener_hash , context , command_text , decoded_response , command_id )
634651 self .setCursorEditorAtEnd ()
635652 # check the response for mimikatz and not the cmd line ???
0 commit comments