fortrace.utility.console_applications package

Subpackages

Submodules

fortrace.utility.console_applications.console_application module

class fortrace.utility.console_applications.console_application.GenericConsoleApplication(pty: REPLWrapper, name: str)[source]

Bases: ABC

Class 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
send_key_combination(key_combination: KeyCodes | str)[source]

Send a key combination to the console.

Multiple KeyCodes might be chained with ‘+’

Parameters:

key_combination – one or more KeyCodes to be sent

send_text(text: str, new_line: bool = False)[source]

Send regular text to the console application, e.g. type a line in a text editor.

Parameters:
  • text – text to be sent

  • new_line – should a new line symbol be appended?

class fortrace.utility.console_applications.console_application.KeyCodes(*values)[source]

Bases: StrEnum

KeyCodes 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'
class fortrace.utility.console_applications.console_application.Prompt(prompt: str, continuation_prompt: str | None)[source]

Bases: object

Small wrapper for a prompt shell

continuation_prompt: str | None
prompt: str

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: GenericConsoleApplication

Class 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: GenericConsoleApplication

Class to handle an opened Meterpreter session.

PROMPT = '\x1b[4mmeterpreter\x1b[0m > '
close()[source]

Close the Meterpreter session.

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

run_command(command: str, timeout: int | None = None) str | list[str][source]

Run a command inside the Meterpreter.

Parameters:
  • command – command to be run

  • timeout – maximum time to wait for output

Returns:

The output without the entered command.

suspend()[source]

Suspend the Meterpreter session to the background.

Can be opened again later with the same ID.

class fortrace.utility.console_applications.metasploit_console.ShellSession(pty: REPLWrapper)[source]

Bases: GenericConsoleApplication

Class to be used when dealing with an opened shell session without a prompt.

background()[source]

Background the shell session, so it can be used again later.

close()[source]

Close the Shell session

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

Module contents