11import sys
22import os
33import time
4+ from datetime import datetime
45from threading import Thread , Lock
56from PyQt5 .QtWidgets import *
67from PyQt5 .QtGui import *
258259 ]),
259260]
260261
261- orangeText = '<p style=\" color:orange;white-space:pre\" >[+] {} </p>'
262- redText = '<p style=\" color:red;white-space:pre\" >[+] {} </p>'
263-
264262
265263#
266264# Consoles Tab Implementation
@@ -380,14 +378,29 @@ def event(self, event):
380378 return True
381379 return super ().event (event )
382380
381+ def printInTerminal (self , cmdSent , cmdReived , result ):
382+ now = datetime .now ()
383+ sendFormater = '<p style="white-space:pre">' + '<span style="color:blue;">[' + now .strftime ("%Y:%m:%d %H:%M:%S" ).rstrip ()+ ']</span>' + '<span style="color:orange;"> [>>] </span>' + '<span style="color:orange;">{}</span>' + '</p>'
384+ receiveFormater = '<p style="white-space:pre">' + '<span style="color:blue;">[' + now .strftime ("%Y:%m:%d %H:%M:%S" ).rstrip ()+ ']</span>' + '<span style="color:red;"> [<<] </span>' + '<span style="color:red;">{}</span>' + '</p>'
385+
386+ if cmdSent :
387+ self .editorOutput .appendHtml (sendFormater .format (cmdSent ))
388+ self .editorOutput .insertPlainText ("\n " )
389+ elif cmdReived :
390+ self .editorOutput .appendHtml (receiveFormater .format (cmdReived ))
391+ self .editorOutput .insertPlainText ("\n " )
392+ if result :
393+ self .editorOutput .insertPlainText (result )
394+ self .editorOutput .insertPlainText ("\n " )
395+
383396 def runCommand (self ):
384397 commandLine = self .commandEditor .displayText ()
385398 self .commandEditor .clearLine ()
386399 self .setCursorEditorAtEnd ()
387400
388401 if commandLine == "" :
389- line = ' \n ' ;
390- self . editorOutput . insertPlainText ( line )
402+ self . printInTerminal ( "" , "" , "" )
403+
391404 else :
392405 cmdHistoryFile = open (CmdHistoryFileName , 'a' )
393406 cmdHistoryFile .write (commandLine )
@@ -402,34 +415,26 @@ def runCommand(self):
402415 self .commandEditor .setCmdHistory ()
403416 instructions = commandLine .split ()
404417 if instructions [0 ]== HelpInstruction :
405- command = TeamServerApi_pb2 .Command (
406- cmd = commandLine )
418+ command = TeamServerApi_pb2 .Command (cmd = commandLine )
407419 response = self .grpcClient .getHelp (command )
408- self .editorOutput . appendHtml ( orangeText . format ( response .cmd ) )
409- line = ' \n ' + response .response .decode (encoding = "latin1" , errors = "ignore" ) + ' \n ' ;
410- self . editorOutput . insertPlainText ( line )
420+ self .printInTerminal ( response .cmd , "" , "" )
421+ self . printInTerminal ( "" , response . cmd , response .response .decode (encoding = "latin1" , errors = "ignore" ))
422+
411423 else :
412- self .editorOutput .appendHtml (orangeText .format (commandLine ))
413- line = '\n ' ;
414- self .editorOutput .insertPlainText (line )
415- command = TeamServerApi_pb2 .Command (
416- beaconHash = self .beaconHash ,
417- listenerHash = self .listenerHash ,
418- cmd = commandLine )
424+ self .printInTerminal (commandLine , "" , "" )
425+ command = TeamServerApi_pb2 .Command (beaconHash = self .beaconHash , listenerHash = self .listenerHash , cmd = commandLine )
419426 result = self .grpcClient .sendCmdToSession (command )
420427 if result .message :
421- line = result .message .decode (encoding = "latin1" , errors = "ignore" ) + ' \n ' ;
422- self . editorOutput . insertPlainText ( line )
428+ self . printInTerminal ( "" , commandLine , result .message .decode (encoding = "latin1" , errors = "ignore" ))
429+
423430 self .setCursorEditorAtEnd ()
424431
425432 def displayResponse (self ):
426433 session = TeamServerApi_pb2 .Session (beaconHash = self .beaconHash )
427434 responses = self .grpcClient .getResponseFromSession (session )
428435 for response in responses :
429436 self .setCursorEditorAtEnd ()
430- self .editorOutput .appendHtml (redText .format (response .instruction + " " + response .cmd ))
431- line = '\n ' + response .response .decode (encoding = "latin1" , errors = "ignore" ) + '\n '
432- self .editorOutput .insertPlainText (line )
437+ self .printInTerminal ("" , response .instruction + " " + response .cmd , response .response .decode (encoding = "latin1" , errors = "ignore" ))
433438 self .setCursorEditorAtEnd ()
434439
435440 logFile = open ("./logs/" + self .logFileName , 'a' )
0 commit comments