fortrace.utility.console_applications package
Subpackages
- fortrace.utility.console_applications.text_editor package
Submodules
fortrace.utility.console_applications.console_application module
- class fortrace.utility.console_applications.console_application.GenericConsoleApplication(pty: REPLWrapper, name: str)[source]
Bases:
ABCClass to interact with console applications opened through a VirshConsole.
Warning
It is NOT intended to be used in a GUI
- abstractmethod close()[source]
Close a console application.
Call this method to return to the command line. Sometimes it might be necessary to clean the buffer by calling self._pty.run_command(“clear”).
Notes
After a call to close refrain from using the object again
- property name
- class fortrace.utility.console_applications.console_application.KeyCodes(*values)[source]
Bases:
StrEnumKeyCodes determined with pexpect_getch.py script (see utils/scripts)
- A = '97'
- ALT = '27'
- ARROW_DOWN = '27,91,66'
- ARROW_LEFT = '27,91,68'
- ARROW_RIGHT = '27,91,67'
- ARROW_UP = '27,91,65'
- CTRL_C = '3'
- DEL = '27,91,51,126'
- ESC = '27'
- F1 = '27,79,80'
- F2 = '27,79,81'
- F3 = '27,79,82'
- G = '103'
- R = '114'
- RET = '13'
- TAB = '9'
fortrace.utility.console_applications.console_application_factory module
- fortrace.utility.console_applications.console_application_factory.get_console_application(name: str, pty: REPLWrapper) GenericConsoleApplication[source]
Factory for construction of console applications.
- Parameters:
name – name of the application (must be matched in this function
pty – handle to pty (used if there is a new prompt in the console application)
- Returns:
opened console application
fortrace.utility.console_applications.metasploit_console module
- class fortrace.utility.console_applications.metasploit_console.MetasploitConsole(pty: REPLWrapper)[source]
Bases:
GenericConsoleApplicationClass to handle a MetasploitConsole opened in a VirshConsole session.
- close()[source]
Close a console application.
Call this method to return to the command line. Sometimes it might be necessary to clean the buffer by calling self._pty.run_command(“clear”).
Notes
After a call to close refrain from using the object again
- edit(file: PathLike) GenericConsoleTextEditor[source]
Open/Create a file with the VIM editor from within the Metasploit console
- Parameters:
file – path to the file
- Returns:
handle to console text editor
- open_meterpreter_session(session_id: int) MeterpreterSession[source]
Start a Meterpreter session.
- Parameters:
session_id – ID of already created Meterpreter session
- Returns:
opened Meterpreter session
- open_shell() ShellSession[source]
Open a shell in MetasploitConsole.
Use this method if the metasploit run command opens a shell without a prompt.
- Returns:
ShellSession object
- run_command(command: str, timeout: int | None = None) str | list[str][source]
Run a command in the metasploit console.
- Parameters:
command – command to be run
timeout – optional timeout (useful if command takes longer)
- Returns:
If the output is a single line a string is returned, else a list of strings or an empty list
- class fortrace.utility.console_applications.metasploit_console.MeterpreterSession(pty: REPLWrapper, session_id: id)[source]
Bases:
GenericConsoleApplicationClass to handle an opened Meterpreter session.
- PROMPT = '\x1b[4mmeterpreter\x1b[0m > '
- edit(file: PathLike) GenericConsoleTextEditor[source]
Edit a file in the Meterpreter.
- Parameters:
file – file to be edited
- Returns:
handle to opened text editor
- open_shell() ShellSession[source]
Open a Shell from within MeterpreterSession.
- Returns:
handle to opened shell
- class fortrace.utility.console_applications.metasploit_console.ShellSession(pty: REPLWrapper)[source]
Bases:
GenericConsoleApplicationClass to be used when dealing with an opened shell session without a prompt.
- run_command(command: str, sleep: int | None = None, expect: str | None = None) str | list[str][source]
Run a command in a shell opened from within a Meterpreter session.
There is no prompt, so we need to read everything or need to know what to expect.
- Parameters:
command – the command to run
sleep – an estimate by the user how long the command will take. None, if the result is there immediately
expect – Some string to expect, if the command has finished. None to read until timeout exception
- Returns:
a list of strings for multiline outputs, a single string for single line output, an empty list for no output