ISITDTU CTF 2018 Finals - babytrace
nc 10.7.3.94 31337
Attachment: babytrace babytrace.py xpl.py
This one was a bit tricky :)
On the remote server a babytrace.py
script is running, which let’s us enter shellcode and then executes it via the babytrace
binary.
The downside here is, that the script ptrace
s all syscalls in the binary and drops with an error message, if we try to open /home/babytrace/flag
:
It also contains a list of syscalls, which which will be blacklisted. The script will also break, if we access one of those syscalls. Thus, we cannot just pop a shell, since execve
is blacklisted, so where to go from here?
Well, since the machine, the binary is running on is 64 bit, we can switch between x86
and amd64
mode in our shellcode with
and getting back into x86
mode via
We can abuse this, to switch to amd64
mode and use open
there, to open the flag file. The ptrace
script won’t catch it, since it’s looking for x86
syscalls.
Our payload now contains x86
and amd64
shellcode at once :)
When call 0x33:0x804a100
from the first shellcode gets executed, it will switch to amd64
mode and jump into our second shellcode SC2
, where we can now just use amd64
syscalls to open and read the flag.
But still a big problem remains: We have no access to any file descriptor from the running python script. It only reads input from us once, sends it to the binary and from then on, we’ll only be able to receive the logging output from the python script.
How can we now exfiltrate the flag from the remote server without being able to do a write whatever
.
Remember the first issue with the binary trying to hinder us on opening a file, that contains the word flag
?
Well, it just killed itself with this :)
When reading the content of the flag file, we’ll just read it directly behind the flag filename itself. Then we can switch back to x86
mode with retf
, and now we’ll just try to open this file from x86
mode again.
Since we’re back in x86
now, the python script will watch over our syscalls again and see that we’re trying to open the flag file and tells us that this won’t be possible (and exfiltrate the flag itself for us in this way)