So I heard all about these binary exploitation attacks involving libraries and libc, and that’s got me worried! I decided to statically compile all of my binaries to avoid those attack vectors. This means I don’t need to worry about mitigations, right?
Right??
nc static.chal.cyberjousting.com 1350
Challenge
Running the binary didn’t give much insight as it seems to just read input, so lets do some checks and get into decompiling it.
1 | Arch: amd64-64-little |
1 | void vuln(void) |
So again we have a very simple vuln function that has a simple buffer overflow. Now the only real differences on this guy here is that the binary is statically linked and has NX enabled. There is a stack canary but not one that we need to worry about, as shown in the vuln function decompilation.
This was my first time exploiting a statically linked binary like this. I spent a few minutes scratching my head because I knew what statically linked meant but I didn’t know how exactly to exploit it. My first thought was to look for system
in the binary, but it wasnt there. After some googling I quickly came across this technique. After a little bit of reading I came to an understanding that this was a pretty simple rop challenge that just used what the binary had to offer.
There were three things I needed to achieve: overflowing into the return address, getting /bin/sh
into writable memory, and then setting up registers for a syscall.
Using ROPgadget
I was able to pick out some gadgets that would fit my use. They weren’t perfect but we made do.
1 | from pwn import * |
The solve script does exactly that. It gets us into the return address, writes /bin/sh
into rdx, then movs [rdx] into rax, then fills the registers with our desired values in order to call execve
. And after calling we have achieved a shell on the server.
Flag
byuctf{glaD_you_c0uld_improvise_ROP_with_no_provided_gadgets!}