-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Syscall execution method for fileless ELF execution #19990
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
Open
msutovsky-r7
wants to merge
20
commits into
rapid7:master
Choose a base branch
from
msutovsky-r7:feat/fetch_fileless_update
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Syscall execution method for fileless ELF execution #19990
msutovsky-r7
wants to merge
20
commits into
rapid7:master
from
msutovsky-r7:feat/fetch_fileless_update
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
885eeac
to
62cbb79
Compare
…code refactor; comments
Testingx64Options
NOTESO, using the fileless works good however due to the technique we are using, when we start our Meterpreter session we will get an error because the file results deleted:
This problem is fixed by changing directory to something else. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR solves the existing issue with fileless ELF execution option for fetch payloads. In certain conditions (i.e Docker enviroment, gui-less systems or any system with lack of existing anonymous handles) the original approach did not work, when it couldn't find existing anonymous file handle and there was no other option for user. There's PR in progress #19943, which adds Python option for fileless execution. This PR adds Bash alternative. The solution lies within
/proc/*/mem
file,procfs
andmemfd_create
syscall. The original PoC works in following way:The Poc will first change directory to
/proc/
directory for its PID. Then it will read fromsyscall
file and create file handle pointing tomem
file. Thesyscall
file will contain an address somewhere intoread
libc function. The idea is to overwrite that address with payload and achieve shellcode execution. This PoC will successfully spawn/bin/bash
shell. This introduces some issues:memfd_create
will not work right awayThe current solution works in two steps: first, copy shellcode into
vdso
section, then writemov rax, [vdso address]; jmp rax
into the address fromsyscall
file. This ensures thatdd
will not overwrite anything important. The shellcode itself will create file handle usingmemfd_create
, callftruncate
andpause
syscall to stop the process. This will create anonymous file handle, which can be later used. Next, the bash code will search for that file handle and copy the code as original approach. It should be noted that from shellcode perspective, it might be easier to do more stuff inside shellcode, however, this approach will make it more difficult to use existing structure for final payload delivery. Currently, thecurl
/wget
/.. use parameter$f
as destination where payload is saved. Creating anonymous file handle is a approach to keep and use this existing functionality.Architectures to implement
Other tasks: