rapid7 / metasploit-payloads

Unified repository for different Metasploit Framework payloads
Other
1.75k stars 673 forks source link

Add support for MinGW debug builds #690

Open cdelafuente-r7 opened 11 months ago

cdelafuente-r7 commented 11 months ago

The Makefile used to compile Meterpreter with MinGW has no support to Debug builds. This can be achieved by passing some flags to cmake.

However, doing so will break the build:

...
[ 97%] Building C object ext_server_kiwi/CMakeFiles/ext_server_kiwi.dir/meterpreter/source/extensions/kiwi/mimikatz/modules/sqlite3.c.obj
[ 97%] Linking C shared library ext_server_kiwi.x86.dll
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/ext_server_kiwi.dir/objects.a(kuhl_m_crypto_pki.c.obj): in function `kuhl_m_crypto_c_sc_auth':
/meterpreter/source/extensions/kiwi/mimikatz/mimikatz/modules/crypto/kuhl_m_crypto_pki.c:641: undefined reference to `kuhl_m_crypto_c_sc_auth_Ext_Free'
/usr/bin/i686-w64-mingw32-ld: /meterpreter/source/extensions/kiwi/mimikatz/mimikatz/modules/crypto/kuhl_m_crypto_pki.c:642: undefined reference to `kuhl_m_crypto_c_sc_auth_Ext_Free'
/usr/bin/i686-w64-mingw32-ld: /meterpreter/source/extensions/kiwi/mimikatz/mimikatz/modules/crypto/kuhl_m_crypto_pki.c:645: undefined reference to `kuhl_m_crypto_c_sc_auth_Ext_Free'
collect2: error: ld returned 1 exit status
make[3]: *** [ext_server_kiwi/CMakeFiles/ext_server_kiwi.dir/build.make:1907: ext_server_kiwi/ext_server_kiwi.x86.dll] Error 1
make[3]: Leaving directory '/meterpreter/workspace/build/mingw-x86'
make[2]: *** [CMakeFiles/Makefile2:664: ext_server_kiwi/CMakeFiles/ext_server_kiwi.dir/all] Error 2
make[2]: Leaving directory '/meterpreter/workspace/build/mingw-x86'
make[1]: *** [Makefile:84: all] Error 2
make[1]: Leaving directory '/meterpreter/workspace/build/mingw-x86'
make: *** [Makefile:29: meterpreter-x86-build] Error 2
make: *** [docker] Error 2

This will also break the build:

...
[ 26%] Linking C shared library metsrv.x86.dll
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(base.c.obj):base.c:(.text+0xdb): undefined reference to `log_to_file'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(base_dispatch.c.obj):base_dispatch.c:(.text+0xcb): undefined reference to `log_to_file'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(base_inject.c.obj):base_inject.c:(.text+0xcb): undefined reference to `log_to_file'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(channel.c.obj):channel.c:(.text+0xcb): undefined reference to `log_to_file'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(core.c.obj):core.c:(.text+0xcb): undefined reference to `log_to_file'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(metapi.c.obj):metapi.c:(.data+0x1d8): undefined reference to `get_logging_context'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(metapi.c.obj):metapi.c:(.data+0x1dc): undefined reference to `get_lock'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(metsrv.c.obj):metsrv.c:(.text+0xcb): undefined reference to `log_to_file'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(metsrv.c.obj):metsrv.c:(.text+0xe40): undefined reference to `init_logging'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(packet_encryption.c.obj):packet_encryption.c:(.text+0xcb): undefined reference to `log_to_file'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(pivot_packet_dispatch.c.obj):pivot_packet_dispatch.c:(.text+0xcb): undefined reference to `log_to_file'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(pivot_tree.c.obj):pivot_tree.c:(.text+0xcb): undefined reference to `log_to_file'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(remote.c.obj):remote.c:(.text+0xc8): undefined reference to `log_to_file'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(remote_dispatch.c.obj):remote_dispatch.c:(.text+0xcb): undefined reference to `log_to_file'
/usr/bin/i686-w64-mingw32-ld: CMakeFiles/metsrv.dir/objects.a(remote_thread.c.obj):remote_thread.c:(.text+0xcb): more undefined references to `log_to_file' follow
collect2: error: ld returned 1 exit status
make[3]: *** [metsrv/CMakeFiles/metsrv.dir/build.make:488: metsrv/metsrv.x86.dll] Error 1
make[3]: Leaving directory '/meterpreter/workspace/build/mingw-x86'
make[2]: *** [CMakeFiles/Makefile2:394: metsrv/CMakeFiles/metsrv.dir/all] Error 2
make[2]: Leaving directory '/meterpreter/workspace/build/mingw-x86'
make[1]: *** [Makefile:84: all] Error 2
make[1]: Leaving directory '/meterpreter/workspace/build/mingw-x86'
make: *** [Makefile:29: meterpreter-x86-build] Error 2
make: *** [docker] Error 2

The source/logging/logging.* source code seems to be missing.

This also breaks the builds the same way than with DBGTRACE.