-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Fix Linux Stageless Payload to be Shellcodes #19799
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 Linux Stageless Payload to be Shellcodes #19799
Conversation
b3f3b8c to
128ac84
Compare
|
This makes a lot of sense- my only complaint is that we need to comment the asm a lot more, especially when you're doing shenanigans. 😆 |
|
Also, what are you using to test this? Do you have a elf that supports injection, or are you only testing by creating an elf stager from the shellcode? |
I generated ELF file using |
modules/payloads/singles/linux/aarch64/meterpreter_reverse_http.rb
Outdated
Show resolved
Hide resolved
2025792 to
56c4506
Compare
bwatters-r7
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor cheat sheet additions
x64 |
AARCH64 |
ARMLE |
MIPSLEThis fails with segfault. I'm running it on a router, so I cannot get GDB installed, but gdb server works. Linux version: EDIT |
5192b65 to
0407bb7
Compare
It's causing segfault on this instruction: So the issue is with Meterpreter itself - on qemu, it seems to be working though. UPDATE: |
Co-authored-by: Brendan <[email protected]>
fix aarch64 packing
c0eb5b9 to
b42fc2e
Compare
| <% if platform.downcase == 'linux' && !['armbe', 'ppc64le', 'ppc', 'ppce500v2'].include?(arch.downcase) %>include Msf::Payload::Linux::<%= arch.capitalize %>::ElfLoader<% end %> | ||
| <% if platform.downcase == 'linux' %>include Msf::Payload::Linux::<%= arch.capitalize %>::Prepends<% end %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <% if platform.downcase == 'linux' && !['armbe', 'ppc64le', 'ppc', 'ppce500v2'].include?(arch.downcase) %>include Msf::Payload::Linux::<%= arch.capitalize %>::ElfLoader<% end %> | |
| <% if platform.downcase == 'linux' %>include Msf::Payload::Linux::<%= arch.capitalize %>::Prepends<% end %> | |
| <% if platform.downcase == 'linux' && !['armbe', 'ppc64le', 'ppc', 'ppce500v2', 's390x'].include?(arch.downcase) %>include Msf::Payload::Linux::<%= arch.capitalize %>::ElfLoader<% end %> | |
| <% if platform.downcase == 'linux' %>include Msf::Payload::Linux::<%= arch.capitalize %>::Prepends<% end %> |
| include Msf::Payload::Single | ||
| include Msf::Sessions::MeterpreterOptions::Linux | ||
| include Msf::Sessions::MettleConfig | ||
| include Msf::Payload::Linux::Zarch::Prepends |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but since zarch is not going to get the in-memory execution, should we remove this include? The prepends file is empty, so it does not effectively do anything now, but even if it were populated, it would not work, right? (same thing for the other zarch single paloads)
smcintyre-r7
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything that should be working at this point has been tested. Everything that wasn't working has been removed. The tests that are failing are unrelated. At this point I think this is ready for landing.
Release NotesThis updates stageless payloads for multiple architecture on Linux to be executable shellcode. The updates involve using an in-memory loader that requires Linux kernel version 3.17 or later in order to function. This means fixes stageless payloads for Linux to work in contexts where shellcode is expected. |
This PR Fixes the issue of linux stageless meterpreter.
Issue: #19670
Issue Description
The stageless linux meterpreters are ELF files that cannot be used as standard stageless shellcode payload.
Staged vs Stageless Linux Meterpreter
Staged
The Linux staged meterpreter is divided in 3 component
e_entryof the ELFThis version of the ELF is generated when we build mettle using the following tool: elf2bin
Stageless
The stageless mettle payload is the ELF file (standard elf) with the patched args.
Code Handling Staged vs Stageless
Mettle main.c
Solution
For each architecture, a shellcode implementing this technique was made.
NOTE: This technique works only with Kernel >= 3.17
Instead of delivering the ELF only, the raw shellcode will be composed by the
in-memory-loaderarch specific shellcode and the elf file at the end of it.Super thanks to @msutovsky-r7
What architectures fix this pr:
linux/x86linux/x64linux/armlelinux/aarch64linux/mipslinux/mipsellinux/mips64What is inside the PR and How to test it
<arch>/in_memory_loader.rbinclude the architecture specific shellcode to be prepended to the ELF binary.<arch>/prepends.rbmixin for the missing architectures.2.6or to3.17kernels.2.6.meterpreter_reverse.erbtemplate for payload generation.What to test
MeterpreterLinuxMinKernelis2.6+is the same as beforeMeterpreterLinuxMinKernelis3.17is using the correct ELF template and is executed on a compatible target.MeterpreterLinuxMinKernelis3.17otherwise a warning is showed.