Skip to content

Commit 1f0b7d7

Browse files
authored
Merge pull request #806 from cgranleese-r7/fixes-python-debugging
Fixes Python debug mode
2 parents cbe602e + 821b9e5 commit 1f0b7d7

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

python/meterpreter/meterpreter.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,9 @@
378378
)
379379
# ---------------------------------------------------------------
380380

381-
# Note: DEBUGGING is driven by the runtime config block, not a build-time
382-
# constant, so logging is configured where DEBUGGING is enabled (below).
381+
# Note: DEBUGGING is driven by either the runtime config block, or a build-time
382+
# constant, so logging is configured lazily on first use in debug_print.
383+
_logging_configured = False
383384

384385
if has_windll:
385386
class SYSTEM_INFO(ctypes.Structure):
@@ -457,6 +458,14 @@ def crc16(data):
457458
@export
458459
def debug_print(msg):
459460
if DEBUGGING:
461+
global _logging_configured
462+
if not _logging_configured:
463+
logging.basicConfig(level=logging.DEBUG)
464+
if DEBUGGING_LOG_FILE_PATH:
465+
file_handler = logging.FileHandler(DEBUGGING_LOG_FILE_PATH)
466+
file_handler.setLevel(logging.DEBUG)
467+
logging.getLogger().addHandler(file_handler)
468+
_logging_configured = True
460469
logging.debug(msg)
461470

462471
def debug_hexdump(label, data):
@@ -2298,11 +2307,6 @@ def encrypt(self, pt):
22982307
if config.get('debug_log'):
22992308
DEBUGGING = True
23002309
DEBUGGING_LOG_FILE_PATH = config['debug_log']
2301-
logging.basicConfig(level=logging.DEBUG)
2302-
if DEBUGGING_LOG_FILE_PATH:
2303-
_dbg_fh = logging.FileHandler(DEBUGGING_LOG_FILE_PATH)
2304-
_dbg_fh.setLevel(logging.DEBUG)
2305-
logging.getLogger().addHandler(_dbg_fh)
23062310
transport = config['transports'][0]
23072311
# PATCH-SETUP-STAGELESS-TCP-SOCKET #
23082312
# For staged/stageless TCP payloads where the socket `s` is already

0 commit comments

Comments
 (0)