-
Notifications
You must be signed in to change notification settings - Fork 710
Cross-compile Windows binaries on Linux #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I'll sort the conflicts out in a sec. DOH! |
|
Actually, I will resolve the conflicts when the other PRs have landed :) |
|
I love your work @OJ <3, but aren't file bigger in size in this particular mode ? |
|
Yes file size is an issue. However, the point is to give people more
options and to provide another means to easily change the signature of the
resulting filles.
Using more recent toolsets with VS also results in a larger file size.
…On Sun, 7 Jun 2020, 19:19 Benjamin DELPY, ***@***.***> wrote:
I love your work @OJ <https://github.com/OJ> <3, but aren't file bigger
in size in this particular mode ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#405 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAHBYB6KJKWPDTSRLU3WD3RVNLTXANCNFSM4NSEX6NA>
.
|
|
Deliberately marking this as delayed while we merge all the other stuff first. When they're done, I'll make sure this gets updated/rebased/etc onto 6.x so that the merge is clean. |
|
Awesome stuff, thanks !!! AV vendors will hate this... :-) |
|
I'll sort out the conflicts on this as soon as #401 has been sorted. |
|
I was able to run "make docker-container" without any issues, I did see some red when building the image though... @OJ , this is what I get when running "make docker": |
|
Make sure you 'git submodule update'
…On Sun, 21 Jun 2020, 08:02 pussinboots1992, ***@***.***> wrote:
I was able to run "make docker-container" without any issues, I did see
some red when building the image though...
@OJ <https://github.com/OJ> , this is what I get when running "make
docker":
***@***.***:~/dev/metasploit-payloads/c/meterpreter# make docker
-- Build Type not specified, defaulting to 'Release'.
-- Configuring done
-- Generating done
-- Build files have been written to: /meterpreter/workspace/build/mingw-x86
make[1]: Entering directory '/meterpreter/workspace/build/mingw-x86'
make[2]: Entering directory '/meterpreter/workspace/build/mingw-x86'
make[3]: Entering directory '/meterpreter/workspace/build/mingw-x86'
make[3]: Leaving directory '/meterpreter/workspace/build/mingw-x86'
[ 26%] Built target jpeg
make[3]: Entering directory '/meterpreter/workspace/build/mingw-x86'
make[3]: Leaving directory '/meterpreter/workspace/build/mingw-x86'
make[3]: Entering directory '/meterpreter/workspace/build/mingw-x86'
[ 27%] Building C object metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/base.c.obj
In file included from /meterpreter/source/metsrv/base.c:5:
/meterpreter/source/metsrv/metsrv.h:21:10: fatal error: ../ReflectiveDLLInjection/inject/src/GetProcAddressR.h: No such file or directory
21 | #include "../ReflectiveDLLInjection/inject/src/GetProcAddressR.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[3]: *** [metsrv/CMakeFiles/metsrv.dir/build.make:64: metsrv/CMakeFiles/metsrv.dir/meterpreter/source/metsrv/base.c.obj] 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:27: meterpreter-x86-build] Error 2
make: *** [Makefile:312: docker] Error 2
***@***.***:~/dev/metasploit-payloads/c/meterpreter#
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#405 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAHBYDBYY7BV5VLUIFJUMDRXUWXLANCNFSM4NSEX6NA>
.
|
|
@OJ, sorry, I suck...it worked, had to create the output directory manually. |
|
Ah yes. I forgot about that. I'm going to adjust the build script to create
that if it doesn't exist already. Thanks!
…On Mon, 22 Jun 2020, 06:26 pussinboots1992, ***@***.***> wrote:
@OJ <https://github.com/OJ>, sorry, I suck...it worked, had to create the
output directory manually.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#405 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAHBYFKXQXFSB33ZR3AH4LRXZUFVANCNFSM4NSEX6NA>
.
|
Add support for loading RDI-related stuff using ordinals instead of function names. Remove exports from the extensions/etc. This is another step in the direction to make the DLLs less obvious. Extensions no longer have their own name in the library metadata. They're all "extension.dll". Metsrv is now "server.dll" and the two non-extensions are "plugin.dll". I was going for something a little less obvious. This required changes to the RDI functionality.
|
OK did a rather gross rebase dance, but I think we're good now. |
|
Native build results from msbuild are showing an error with |
|
Even with a submodule update'?
…On Thu, 25 Jun 2020, 22:47 Jeffrey Martin, ***@***.***> wrote:
Native build results from msbuild are showing an error with
ext_server_kiwi:
22:28:44 ..\..\source\extensions\kiwi\mimikatz\mimikatz\modules\kuhl_m_standard.c(131): error C2308: concatenating mismatched strings [C:\Users\vagrant\metasploit-payloads\c\meterpreter\workspace\ext_server_kiwi\ext_server_kiwi.vcxproj]
22:28:44
22:28:44 14 Warning(s)
22:28:44 1 Error(s)
22:28:44
22:28:44 Time Elapsed 00:00:57.44
22:28:44 Finished 2020-06-25 03:28:43.088
22:28:44 Copying: ../c/meterpreter/output/elevator.x86.dll -> ./data/meterpreter/elevator.x86.dll
22:28:44 Copying: ../c/meterpreter/output/ext_server_extapi.x86.dll -> ./data/meterpreter/ext_server_extapi.x86.dll
22:28:44 Copying: ../c/meterpreter/output/ext_server_incognito.x86.dll -> ./data/meterpreter/ext_server_incognito.x86.dll
22:28:44 Copying: ../c/meterpreter/output/ext_server_lanattacks.x86.dll -> ./data/meterpreter/ext_server_lanattacks.x86.dll
22:28:44 Copying: ../c/meterpreter/output/ext_server_peinjector.x86.dll -> ./data/meterpreter/ext_server_peinjector.x86.dll
22:28:44 Copying: ../c/meterpreter/output/ext_server_powershell.x86.dll -> ./data/meterpreter/ext_server_powershell.x86.dll
22:28:44 Copying: ../c/meterpreter/output/ext_server_priv.x86.dll -> ./data/meterpreter/ext_server_priv.x86.dll
22:28:44 Copying: ../c/meterpreter/output/ext_server_python.x86.dll -> ./data/meterpreter/ext_server_python.x86.dll
22:28:44 Copying: ../c/meterpreter/output/ext_server_sniffer.x86.dll -> ./data/meterpreter/ext_server_sniffer.x86.dll
22:28:44 Copying: ../c/meterpreter/output/ext_server_unhook.x86.dll -> ./data/meterpreter/ext_server_unhook.x86.dll
22:28:44 Copying: ../c/meterpreter/output/ext_server_winpmem.x86.dll -> ./data/meterpreter/ext_server_winpmem.x86.dll
22:28:44 Copying: ../c/meterpreter/output/metsrv.x86.dll -> ./data/meterpreter/metsrv.x86.dll
`
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#405 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAHBYF4HJGMK2W4SP5HJZDRYNBOBANCNFSM4NSEX6NA>
.
|
|
Oh this might be VS 2013 specific! |
|
Builds clean in VS2017 and VS2019, but breaks in VS2013. Could be the platform toolset. Will fix. |
|
Yeah it's a platform toolset issue. |
|
Thanks for checking. Test automation compile starts from a clean checkout with submodule init. Compile done on VS2013 edition env used when enabling compile on newer VS platforms. |
|
To be honest, this shouldn't be something tied to the toolset version. VS2019 should have broken as well! Anyways, fix incoming in the mimikatz repo on the |
|
OK should be good to go. Thanks @jmartin-r7 ! |
|
Confirmed: |
|
While running Docker Error Message |
|
@smcintyre-r7 That's odd, because @timwr's PR to include the updated alternatives should have fixed that. Tim, would you mind helping here please mate? |
|
@smcintyre-r7 @OJ OJ#13 was the fix for that issue but I think the change got lost in the rebase. |
|
Thank you Tim! |
|
Alright that commit fixed the Java error for me in docker, so thank you for that. With that fix in place (and a manually created I validated both build bat scripts mentioned in the PR still build correctly without any errors. I also build and tested the binaries using docker. My tests involved building them, copying them as noted in the PR and before opening a Meterpreter session with PSexec and using the test script listed below. I tried both x86 and x64 on Windows 7 SP1 and x64 on Windows 10. Everything appeared to function correctly. Meterpreter Test Script |
|
Manually created output?
Dammit was the fix for that lost the too?
I hate rebasing.
Let me add that to the build again.
…On Sat, 27 Jun 2020, 07:01 Spencer McIntyre, ***@***.***> wrote:
Alright that commit fixed the Java error for me in docker, so thank you
for that.
With that fix in place (and a manually
<#405 (comment)>
created output) everything began to build correctly.
I validated both build bat scripts mentioned in the PR still build
correctly without any errors. I also build and tested the binaries using
docker. My tests involved building them, copying them as noted in the PR
and before opening a Meterpreter session with PSexec and using the test
script listed below. I tried both x86 and x64 on Windows 7 SP1 and x64 on
Windows 10. Everything appeared to function correctly.
Meterpreter Test Script
load espia
load extapi
load incognito
load kiwi
load lanattacks
load peinjector
load powershell
load python
load sniffer
load unhook
load winpmem
# Stdapi
run post/test/meterpreter
run post/test/file
# Espia
screengrab
# Extapi
window_enum
service_enum
clipboard_get_data
# Incognito
list_tokens -u
# Kiwi
creds_all
creds_wdigest
wifi_list
# Lanattacks
dhcp_start
dhcp_stop
# Sniffer
sniffer_interfaces
# Python
python_execute "print('Hello World')"
python_reset
# Powershell
powershell_execute "Write-Host 'Hello World'"
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#405 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAHBYEEX3BGEXQWDVAC3H3RYUEA5ANCNFSM4NSEX6NA>
.
|
|
Should be good now @smcintyre-r7 ! |
|
After talking to @jmartin-r7, for now I'm going to land this as is without pushing the new container publicly. The new container ID, once pushed however will be I also verified that commit 9f859fe fixed the missing With that sorted, I'm going to go ahead and get this landed now. Thanks @OJ! |
|
New container published to |
|
Awesome thank you lads!
I'll PR the new container name change this morning.
…On Tue, 30 Jun 2020, 00:23 Jeffrey Martin, ***@***.***> wrote:
New container published to rapid7/msf-ubuntu-x64-meterpreter:latest see
#417 <#417>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#405 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAHBYEAEDPRQQOUSOQIJATRZCPUNANCNFSM4NSEX6NA>
.
|
|
oops, looks like I sent it to |
|
Ah cool! Thanks Jeffrey. |


This PR requires the following to be merged before landing:
Description
This PR contains changes to the CMake build that allow for most of the Meterpreter DLLs to be built from Linux. The only two things that I can't get working with the mingw-w64 compiler are
ext_server_pythonandext_server_powershell. I think that with these two we're hitting limitations of the toolsets, so I'm not sure how to proceed from here. COM related stuff is a pain, which is needed for Powershell, and there's a few assembly quirks that are killing it for Python.So the full list of things that do build fine is everything apart from the above... even
kiwibuilds!I made heavy use of @plowsec's work as a reference point for getting this going. While I didn't directly pull in any of his code from his PRs (mostly because the structure I already had in place from doing CMake builds on Windows), his efforts were invaluable in getting me going. So .. thank you!
The builds on Linux aren't clean. There are a lot of warnings and I don't think it's necessary at this point to go through each and try to remove them. This is something that can and should be done over time, rather than a large up-front activity.
This also contains changes to the
Dockerfilethat's used for building payloads. More information on that below.Building
From my experience, this is not as simple as I was hoping and varies across Linux distros. I had a completely sh!tfight trying to get it working on Fedora. I learned (the hard way) that Fedora doesn't have the right compilers available through
dnf. To make it work you'd have to build the compilers and install them manually.The primary issue here is that threading-related stuff in C++ code ends up with a dependency on threading libraries. By default, if the standard compiler (such as the one on Fedora) is used, then you end up with a dependency on the winpthread library. Given that this library can't be statically linked, it results in binaries that have a hard-dependency on a DLL that almost certainly doesn't exist on the target machine. Hence, they crash when loaded.
The
win32versions of the compiler result in the C++ threading functionality being tied to Windows threads, which means the winpthread library dependency goes away. This is the default compiler that is available on Ubuntu. While doing the initial work on this PR, I had intended to build a docker container that could be used to build things easily so long as Docker is installed. After discovering this issue with linking against winpthread, I switched to the Docker option immediately.I had to update the base Ubuntu version in the Dockerfile so that the appropriate tooling was available, this might have caused issues with the Java build based on what I saw while trying to build Java. I'd like to make sure I haven't done anything stupid here, so if I could please get @timwr and @jmartin-r7 to validate this I'd appreciate it.
Even if you run a distro with everything set up properly, I would recommend building directly out of the docker container.
Docker container changes
Makefile and CMakeLists
The CMakeLists.txt and Makefile have had a bunch of options now that allow for compilation if specific entities. I have not yet ported this to the Windows side.
These commands exist and result in building using the toolset installed on the host itself (not the container)
make meterpreter- builds all meterpreter binaries.make meterpreter-x64- builds all x64 meterpreter binaries.make meterpreter-x86- builds all x64 meterpreter binaries.make meterpreter-metsrv- builds x86 and x64 metsrv binaries.make meterpreter-metsrv-x64- builds x64 metsrv binary.make meterpreter-ext-stdapi-x64- builds x64 stdapi binary.make meterpreter-plugin-screenshot- builds x86 and x64 screenshot binaries.All of the above commands have docker-based equivalents.
make docker-container- builds the docker container from the Dockerfile.make docker*- this is the same as invokingmake meterpreter*from inside the docker container and should work with all the examples shown above.The commands that are prefixed with
docker(other thandocker-container) all mount the current folder into the container so that the container can build the current version of the source. The ID of the current user is passed to Docker and that's the context that is used when compiling. This means that the binaries that are generated on the file system are owned by the current user.Sample run
Kicking off...

Finishing up...

Verification
From the
c/meterpreterfolder ...make-cmake.batbuilds on Windows still works without any issues/warnings.make.batbuilds on Windows still works without any issues/warnings.make docker-container.make dockeroutputfolder to thedata/meterpreterfolder ready for testing (make installdoes this if you have the projects checked out side by side).Obviously it'd be ideal to get a full regression test done on this, but I'm not sure that's going to be possible.
Before landing
Dockerfileand make sure that's pushed up to the Docker hub.Makefileso that theDOCKER_CONTAINERvalue is updated to point back torapid7:build:meterpreterFuture work
Thanks
Cheers again to @ccondon-r7, @bcook-r7, @adfoster-r7 and @jmartin-r7 for the help/support behind the scenes. Huge shout out t @plowsec for breaking the ground on this.