Skip to content

Fixes Python debug mode - #806

Merged
adfoster-r7 merged 1 commit into
rapid7:6.5from
cgranleese-r7:fixes-python-debugging
Jul 15, 2026
Merged

Fixes Python debug mode#806
adfoster-r7 merged 1 commit into
rapid7:6.5from
cgranleese-r7:fixes-python-debugging

Conversation

@cgranleese-r7

@cgranleese-r7 cgranleese-r7 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

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_print after DEBUGGING has been enabled. This ensures logging.basicConfig() and any file handler for DEBUGGING_LOG_FILE_PATH are set up at the right time regardless of when DEBUGGING gets set (build-time patch or runtime config block).

I verified PHP's debug works as expected

Verification

  • Build Python payloads to include this fix
  • Get a Python sessions with debug mode enabled
  • Verify debugging output works as expected

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_configured flag to ensure one-time logging initialization.
  • Move logging.basicConfig() and optional FileHandler setup from the config-parsing block into debug_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_log enabled, (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

@adfoster-r7 adfoster-r7 Jul 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread python/meterpreter/meterpreter.py Outdated
@cgranleese-r7
cgranleese-r7 force-pushed the fixes-python-debugging branch from 0454805 to 821b9e5 Compare July 15, 2026 11:31
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Metasploit Kanban Jul 15, 2026
@adfoster-r7
adfoster-r7 merged commit 1f0b7d7 into rapid7:6.5 Jul 15, 2026
23 of 52 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Metasploit Kanban Jul 15, 2026
adfoster-r7 pushed a commit to rapid7/metasploit-framework that referenced this pull request Jul 29, 2026
sfewer-r7 pushed a commit to sfewer-r7/metasploit-framework that referenced this pull request Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants