Skip to content

Adds debug compilation for Mingw - #809

Merged
dledda-r7 merged 3 commits into
rapid7:masterfrom
msutovsky-r7:feat/mingw/adds_debug_compilation
Aug 11, 2026
Merged

Adds debug compilation for Mingw#809
dledda-r7 merged 3 commits into
rapid7:masterfrom
msutovsky-r7:feat/mingw/adds_debug_compilation

Conversation

@msutovsky-r7

@msutovsky-r7 msutovsky-r7 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Adds compilation variables DBGTRACE and DBGTRACE_VERBOSE that allow Mingw to compile debug payloads.

DEBUG=1 make docker-metsrv-x64

or

make docker-metsrv-x64-debug

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 enables MinGW debug-tracing builds for Meterpreter by ensuring the debug logging implementation is compiled into each DLL target and by emitting debug-suffixed output artifacts when debug tracing is enabled.

Changes:

  • Adds ../../source/logging/logging.c to the source list for metsrv, plugins, and extension DLL targets so DEBUGTRACE builds link successfully under MinGW.
  • Updates the copyoutput CMake helper to copy debug-trace builds into output/ using a *.debug.dll naming convention.
  • Extends the c/meterpreter/Makefile to pass DBGTRACE/DBGTRACE_VERBOSE through to CMake and docker build targets.

Impact Analysis:

  • Blast radius: medium — affects all Windows Meterpreter DLL build targets produced via the CMake workspace (metsrv, extensions, plugins) and the MinGW build workflows driven by c/meterpreter/Makefile.
  • Data and contract effects: build artifact naming changes when DBGTRACE/DBGTRACE_VERBOSE is enabled (outputs copied as *.debug.dll), which can affect any downstream tooling expecting non-debug filenames from output/.
  • Rollback and test focus: rollback is straightforward (revert CMake/Makefile changes); validation should focus on MinGW builds with DBGTRACE=ON and DBGTRACE_VERBOSE=ON, confirming successful linking and that expected *.debug.dll outputs are produced in c/meterpreter/output/ for metsrv + key extensions (e.g., priv/dump_sam resource path expectations).

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
c/meterpreter/workspace/screenshot/CMakeLists.txt Includes debug logging source in the screenshot plugin build.
c/meterpreter/workspace/metsrv/CMakeLists.txt Includes debug logging source in the core metsrv DLL build.
c/meterpreter/workspace/ext_server_winpmem/CMakeLists.txt Includes debug logging source in the winpmem extension build.
c/meterpreter/workspace/ext_server_unhook/CMakeLists.txt Includes debug logging source in the unhook extension build.
c/meterpreter/workspace/ext_server_stdapi/CMakeLists.txt Includes debug logging source in the stdapi umbrella extension build.
c/meterpreter/workspace/ext_server_stdapi_webcam/CMakeLists.txt Includes debug logging source in the stdapi_webcam extension build.
c/meterpreter/workspace/ext_server_stdapi_ui/CMakeLists.txt Includes debug logging source in the stdapi_ui extension build.
c/meterpreter/workspace/ext_server_stdapi_sys/CMakeLists.txt Includes debug logging source in the stdapi_sys extension build.
c/meterpreter/workspace/ext_server_stdapi_railgun/CMakeLists.txt Includes debug logging source in the stdapi_railgun extension build.
c/meterpreter/workspace/ext_server_stdapi_net/CMakeLists.txt Includes debug logging source in the stdapi_net extension build.
c/meterpreter/workspace/ext_server_stdapi_fs/CMakeLists.txt Includes debug logging source in the stdapi_fs extension build.
c/meterpreter/workspace/ext_server_stdapi_audio/CMakeLists.txt Includes debug logging source in the stdapi_audio extension build.
c/meterpreter/workspace/ext_server_sniffer/CMakeLists.txt Includes debug logging source in the sniffer extension build.
c/meterpreter/workspace/ext_server_python/CMakeLists.txt Includes debug logging source in the python extension build.
c/meterpreter/workspace/ext_server_priv/CMakeLists.txt Includes debug logging source in the priv extension build (supports dump_sam debug resource expectations).
c/meterpreter/workspace/ext_server_powershell/CMakeLists.txt Includes debug logging source in the powershell extension build.
c/meterpreter/workspace/ext_server_peinjector/CMakeLists.txt Includes debug logging source in the peinjector extension build.
c/meterpreter/workspace/ext_server_lanattacks/CMakeLists.txt Includes debug logging source in the lanattacks extension build.
c/meterpreter/workspace/ext_server_kiwi/CMakeLists.txt Includes debug logging source in the kiwi extension build.
c/meterpreter/workspace/ext_server_incognito/CMakeLists.txt Includes debug logging source in the incognito extension build.
c/meterpreter/workspace/ext_server_extapi/CMakeLists.txt Includes debug logging source in the extapi extension build.
c/meterpreter/workspace/ext_server_espia/CMakeLists.txt Includes debug logging source in the espia extension build.
c/meterpreter/workspace/ext_server_bofloader/CMakeLists.txt Includes debug logging source in the bofloader extension build.
c/meterpreter/workspace/elevator/CMakeLists.txt Includes debug logging source in the elevator plugin build.
c/meterpreter/workspace/dump_sam/CMakeLists.txt Includes debug logging source in the dump_sam plugin build to generate debug-named DLLs.
c/meterpreter/workspace/CMakeListsFuncs.txt Changes copyoutput() to emit *.debug.dll copies when debug tracing is enabled.
c/meterpreter/Makefile Adds/propagates DBGTRACE and DBGTRACE_VERBOSE CMake options (including docker targets).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread c/meterpreter/workspace/ext_server_extapi/CMakeLists.txt Outdated
Comment thread c/meterpreter/Makefile Outdated
@msutovsky-r7
msutovsky-r7 marked this pull request as ready for review August 10, 2026 15:11
@dledda-r7 dledda-r7 self-assigned this Aug 11, 2026
@dledda-r7 dledda-r7 moved this from Todo to In Progress in Metasploit Kanban Aug 11, 2026
@dledda-r7
dledda-r7 requested a balanced review from Copilot August 11, 2026 07:21

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

Copilot reviewed 27 out of 27 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

c/meterpreter/Makefile:15

  • Important: Problem: these options are passed only when DEBUG is defined, so CMake keeps them ON in the reused workspace/build/mingw-* caches after a debug build. Impact: a subsequent ordinary build still compiles verbose tracing and emits .debug.dll artifacts until cleaned; Fix: explicitly pass both options as OFF in the non-debug branch.
ifdef DEBUG
COMMON_GEN += -DDBGTRACE=ON
COMMON_GEN += -DDBGTRACE_VERBOSE=ON
endif

Comment thread c/meterpreter/workspace/CMakeListsFuncs.txt
@dledda-r7

Copy link
Copy Markdown
Contributor
┌──(kali㉿kali)-[~/…/metasploit-payloads.worktrees/pr-mingw-debug-symbol/c/meterpreter]
└─$ DEBUG=1 make docker-metsrv-x64     
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
-- The C compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Build Type not specified, defaulting to 'Release'.
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/x86_64-w64-mingw32-as
CMAKE_GENERATOR_PLATFORM=""
-- Configuring done
-- Generating done
-- Build files have been written to: /meterpreter/workspace/build/mingw-x64-metsrv
make[1]: Entering directory '/meterpreter/workspace/build/mingw-x64-metsrv'
make[2]: Entering directory '/meterpreter/workspace/build/mingw-x64-metsrv'
make[3]: Entering directory '/meterpreter/workspace/build/mingw-x64-metsrv'
Scanning dependencies of target ReflectiveDLLInjection
make[3]: Leaving directory '/meterpreter/workspace/build/mingw-x64-metsrv'
make[3]: Entering directory '/meterpreter/workspace/build/mingw-x64-metsrv'
[  2%] Building ASM object ReflectiveDLLInjection/CMakeFiles/ReflectiveDLLInjection.dir/meterpreter/source/ReflectiveDLLInjection/dll/src/GateTrampoline64.s.obj
/meterpreter/source/ReflectiveDLLInjection/dll/src/GateTrampoline64.s: Assembler messages:
/meterpreter/source/ReflectiveDLLInjection/dll/src/GateTrampoline64.s: Warning: end of file not at end of a line; newline inserted
[  5%] Linking ASM static library libReflectiveDLLInjection.a
make[3]: Leaving directory '/meterpreter/workspace/build/mingw-x64-metsrv'
[  5%] Built target ReflectiveDLLInjection
make[3]: Entering directory '/meterpreter/workspace/build/mingw-x64-metsrv'
Scanning dependencies of target metsrv
make[3]: Leaving directory '/meterpreter/workspace/build/mingw-x64-metsrv'
make[3]: Entering directory '/meterpreter/workspace/build/mingw-x64-metsrv'
[  8%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/base.c.obj
[ 11%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/base_dispatch.c.obj
[ 14%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/base_inject.c.obj
[ 17%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/channel.c.obj
[ 20%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/core.c.obj
[ 23%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/libloader.c.obj
[ 26%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/list.c.obj
[ 29%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/metapi.c.obj
[ 32%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/metsrv.c.obj
[ 35%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/packet_encryption.c.obj
[ 38%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/pivot_packet_dispatch.c.obj
[ 41%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/pivot_tree.c.obj
[ 44%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/pool_party.c.obj
[ 47%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/rc4.c.obj
[ 50%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/remote.c.obj
[ 52%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/remote_dispatch.c.obj
[ 55%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/remote_thread.c.obj
[ 58%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/scheduler.c.obj
[ 61%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/server_http_utils.c.obj
[ 64%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/server_pivot.c.obj
[ 67%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/server_pivot_named_pipe.c.obj
[ 70%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/server_setup.c.obj
[ 73%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/server_transport_named_pipe.c.obj
[ 76%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/server_transport_tcp.c.obj
[ 79%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/server_transport_winhttp.c.obj
[ 82%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/server_transport_wininet.c.obj
[ 85%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/thread.c.obj
[ 88%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/unicode.c.obj
[ 91%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/winapi.c.obj
[ 94%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/zlib.c.obj
[ 97%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/logging/logging.c.obj
[100%] Linking C shared library metsrv.x64.dll
make[3]: Leaving directory '/meterpreter/workspace/build/mingw-x64-metsrv'
[100%] Built target metsrv
make[2]: Leaving directory '/meterpreter/workspace/build/mingw-x64-metsrv'
make[1]: Leaving directory '/meterpreter/workspace/build/mingw-x64-metsrv'
                                                                                                                                                                                         
┌──(kali㉿kali)-[~/…/metasploit-payloads.worktrees/pr-mingw-debug-symbol/c/meterpreter]
└─$ ls output 
metsrv.x64.debug.dll
                                                                                                                                                                                         
┌──(kali㉿kali)-[~/…/metasploit-payloads.worktrees/pr-mingw-debug-symbol/c/meterpreter]
└─$ 
 0xEF 0xDD] [0x2A 0xB4 0xEF 0x54]"
DebugString: "[125c] [PKT FIND] Looking for type 131073"
DebugString: "[125c] [PKT FIND] TLV header length: 12"
DebugString: "[125c] [PKT FIND] TLV header type: 131073"
DebugString: "[125c] [PKT FIND] Found!"
DebugString: "[125c] [PACKET] Sending packet to remote, length: 160, command id: 2"
DebugString: "[125c] [PACKET] Packet sent!"
DebugString: "[125c] [PKT FIND] Looking for type 131073"
DebugString: "[125c] [PKT FIND] TLV header length: 12"
DebugString: "[125c] [PKT FIND] TLV header type: 131073"
DebugString: "[125c] [PKT FIND] Found!"
DebugString: "[125c] [PACKET] Sent packet to remote, length: 160, command id: 2, result: 0"
DebugString: "[125c] [COMMAND] Calling completion handlers..."
DebugString: "[125c] [PKT FIND] Looking for type 65538"
DebugString: "[125c] [PKT FIND] TLV header length: 12"
DebugString: "[125c] [PKT FIND] TLV header type: 131073"
DebugString: "[125c] [PKT FIND] Types don't match, skipping."
DebugString: "[125c] [PKT FIND] TLV header length: 41"
DebugString: "[125c] [PKT FIND] TLV header type: 65538"
DebugString: "[125c] [PKT FIND] Found!"
DebugString: "[125c] [COMMAND] Completion handlers finished for 2."
DebugString: "[125c] [COMMAND] Packet is not local, destroying"
DebugString: "[125c] [COMMAND] Packet destroyed"
DebugString: "[125c] [COMMAND] Command processing finishing. Returning: TRUE"
DebugString: "[125c] [COMMAND] Executed inline -> Command: 0000000000963EC0"
DebugString: "[125c] [WINAPI][winapi_kernel32_CloseHandle] Calling CloseHandle @ 00007FFB7D826EC0"
DebugString: "[125c] [WINAPI][winapi_kernel32_CloseHandle] Calling CloseHandle @ 00007FFB7D826EC0"

@dledda-r7
dledda-r7 merged commit 298e84a into rapid7:master Aug 11, 2026
30 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Metasploit Kanban Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants