The binary initializes some seccomp rules, and then just reads a huge string, so it’s another simple rop challenge :)
So, we can send a ropchain with length 0x70, we just have to make sure not to hit any blacklisted syscalls.
Let’s take a list at the seccomp rules in place:
This means, we’re allowed to use read, write, open, mprotect, alarm and exit syscalls. With open, read, write we have everything ready to create a ropchain, to open, read and write the flag :)
The only problem here is, that the binary only contains functions to read input, no gadget to set rax or to do a syscall at all:
So, we have to change this, but for the start, let’s just read in another (bigger) ropchain to be a little bit more flexible on ropping through this.
We’ll just reuse the existing readStr function for this:
Since we now have more place for putting additional ropchains, we can get a little bit wasteful on our space and use ret_csuinit for additional calls.
Still, we can only read but having access to libc gadgets would make this even easier (you might do it without with setting rax via consecutive calls to read, but having a pop rax will make the exploit nicer).
So, we need a syscall gadget, which the binary doesn’t contains. But it has a call to alarm, which is just
Thus, we can now just use readStr agin to read 1 byte into the got of alarm and overwrite the LSB of the alarm address, letting it point to 0x7ffff7ac8845. After this, a call to alarm will just trigger syscall, exactly what we need :)
Now having a syscall gadget, we’re able to do a write syscall for a libc leak. But still, we need to set rax to 1 for this. No pop rax available yet, but read will set rax to the number of bytes read ,so let’s just read a single byte
The following call to alarm will then call syscall and since we set rax to 1 via the read, it will be write spitting out the got entry of setbuf.
We’ll just add another read ropchain after the syscall, so we can read another ropchain to continue with after the leak
The next ropchain will be put exactly behind the last call of this ropchain, so it will directly continue with that one after the readStr call has finished.
Now just leak setbuf and calculate libc and gadget addresses:
Now we have every gadget to open the flag file, read it to bss and then write it back to us, so let’s finish this up