This is just a Proof of Concept. It does:
- Decrypt shared object from disk
- Create a new memfd using memfd_create and write the shared object on it
- Forks and spawns /usr/bin/sleep in the child using execve with a masked name (here
/this/is/a/PoC
. The path to the memfd is passed via an env var - The parent reads sleep's /proc/PID/mem and search for gadgets.
Also it looks for the address that would return the nanosleep call inside /usr/bin/sleep, then search for this address in the stack- It uses
/proc/PID/syscall
to get the return address of nanosleep syscall - Craft a simple ROP chain to execute
dlopen(path-to-my-memfd, RTLD_NOW)
- Overwrite the return address in the stack