Add a log handler for external Python modules #9739
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a
LogHandler
andLogFormatter
class to themetasploit.module
Python module. This allows external modules written in Python to keep existing logging statements from their code or imported libraries and have the information properly relayed to the Metasploit Framework.Setup is simple, one of these two options should fit most of the use cases:
The
LogFormatter
class takes a prefix argument which is not a format string like typicallogging.Formatter
arguments are. This means we don't have to worry about escaping it or anything like that.Verification
~/.msf4/modules/auxiliary/test/scanner/python_logging.py
msfconsole
use auxiliary/test/scanner/python_logging
set RHOSTS 1.2.3.4
Testing Module
Example Output