Prompter¶
Exploit oriented cmd prompter, uses logger behind the scenes
Configurations¶
-
PrompterFormatter.
default_level_masking
¶ Default metasploit-style prefix for each logging level:
logging.DEBUG ==> '[$]' logging.INFO ==> '[+]' logging.WARN ==> '[*]' logging.ERROR ==> '[!]' logging.CRITICAL ==> '[!]'
Functions¶
-
Prompter.
__init__
(self, name='', log_file_names=[], min_log_level=logging.INFO, timestamp=Logger.default_timestamp, log_format=Logger.default_log_format)¶ Configures the newly built prompter instance
Parameters: - name – (str, optional): name of the logger instance (no name by default)
- log_files – (tuple of tuples, optional): tuple of log files we should use: (log file name, open mode (, min log level))
- min_log_level – (enum, optional): minimum log level. Value should be an enum option from the log level names (logging.INFO by default)
- timestamp – (str, optional): time format to be used in every log record (default_timestamp by default)
- log_format – (str, optional): overall format of the log records (default_log_format by default)
-
Prompter.
setPrefix
(self, log_level, prefix)¶ Updates the basic style for a specific logging level
Parameters: - log_level – (enum): logging level (from logging)
- prefix – (style): string prefix for the desired logging level
-
Prompter.
setColor
(self, log_level, style)¶ Updates the basic style for a specific logging level in the StreamHandler
Parameters: - log_level – (enum): logging level (from logging)
- style – (style): colorama style for the desired logging level
-
Prompter.
addIndent
(self)¶ Adds an indentation level to the following log records shown on the stdout
-
Prompter.
removeIndent
(self)¶ Removes an indentation level from the following log records shown on the stdout
-
Prompter.
input
(self, msg)¶ Prompts the user for a given input, using the same meta-sploit styled prefix
Parameters: msg – (str): message that would be shown to the user when asking for his input Returns: User input string, as returned by “raw_input”
Usage Examples¶
- Creating a basic prompter that prints to the screen:
logger = Prompter("Dummy Prompter") logger.debug("Debug message that no one will see") logger.info("Logging has began") logger.addIndent() logger.warning("You previous debug message went to /dev/null") logger.removeIndent() logger.error("This example just ended")
And the output will be:
[+] Logging has began
[*] You previous debug message went to /dev/null
[!] This example just ended
- Creating a complex logger with multiple files:
logger = Prompter("Complex Prompter", [('full_log.txt', 'w', logging.DEBUG)], min_log_level=logging.WARNING) logger.debug("Debug message that will be written to the log file") logger.info("Logging has began but you won't see it") logger.warning("The script is nearing it's end") logger.error("This example just ended")
And the output will be:
[*] The script is nearing it's end
[!] This example just ended
And the file log will be:
[14/03/2019 20:08:29] - Complex Prompter - DEBUG: Debug message that will be written to the log file
[14/03/2019 20:08:29] - Complex Prompter - INFO: Logging has began but you won't see it
[14/03/2019 20:08:29] - Complex Prompter - WARNING: The script is nearing it's end
[14/03/2019 20:08:30] - Complex Prompter - ERROR: This example just ended