Fixes Python debug mode - #806
Merged
Merged
Conversation
cgranleese-r7
force-pushed
the
fixes-python-debugging
branch
from
July 15, 2026 11:14
93c00b9 to
0454805
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes Python Meterpreter debug mode by deferring logging initialization until the first debug_print() call after DEBUGGING is enabled, matching the lazy configuration approach used in other implementations.
Changes:
- Add a module-level
_logging_configuredflag to ensure one-time logging initialization. - Move
logging.basicConfig()and optionalFileHandlersetup from the config-parsing block intodebug_print().
Impact Analysis:
- Blast radius: medium;
debug_print()is called broadly across the Python Meterpreter runtime, so the new initialization path affects any debug-enabled session. - Data and contract effects: none identified; no TLV/config schema changes, but logging side effects (handlers/outputs) now occur at first debug emission instead of at config parse time.
- Rollback and test focus: low rollback risk; validate (1) debug output appears with
debug_logenabled, (2) file logging works when path is writable, and (3) behavior is safe when the file path is invalid/unwritable.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+463
to
+468
| logging.basicConfig(level=logging.DEBUG) | ||
| if DEBUGGING_LOG_FILE_PATH: | ||
| file_handler = logging.FileHandler(DEBUGGING_LOG_FILE_PATH) | ||
| file_handler.setLevel(logging.DEBUG) | ||
| logging.getLogger().addHandler(file_handler) | ||
| _logging_configured = True |
Contributor
There was a problem hiding this comment.
Will omit; It's not been an issue thus far, and generally debugging mode is used by developers or when folk are raising issues - so logging being silently noop in the error scenario isn't good
adfoster-r7
reviewed
Jul 15, 2026
cgranleese-r7
force-pushed
the
fixes-python-debugging
branch
from
July 15, 2026 11:31
0454805 to
821b9e5
Compare
adfoster-r7
approved these changes
Jul 15, 2026
adfoster-r7
pushed a commit
to rapid7/metasploit-framework
that referenced
this pull request
Jul 29, 2026
Includes changes from: * rapid7/metasploit-payloads#806 * rapid7/metasploit-payloads#804
sfewer-r7
pushed a commit
to sfewer-r7/metasploit-framework
that referenced
this pull request
Aug 10, 2026
Includes changes from: * rapid7/metasploit-payloads#806 * rapid7/metasploit-payloads#804
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR fixes the Python Meterpreter's debug mode. #801 introduced some changes that caused Pythons debug mode to no longer return debug logs. This change aligns with how PHP is handled,
logging is now configured lazily on the first call to
debug_printafter DEBUGGING has been enabled. This ensureslogging.basicConfig()and any file handler forDEBUGGING_LOG_FILE_PATHare set up at the right time regardless of whenDEBUGGINGgets set (build-time patch or runtime config block).I verified PHP's debug works as expected
Verification