Oh it’s really baby as the title said, and we can notice gets(buf) in the end –> buffer overflow.
Check the security protections and properties of the binary:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ file baby_boi baby_boi: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=065da8fff74608a5758babd74e18e7e046054d84, not stripped
$ checksec --verbose --file=baby_boi RELRO : Partial RELRO Stack Canary : No NX : Enabled PIE : No PIE RPATH : No RPATH RUNPATH : No RUNPATH Symbols : 64 Fortify : No Fortified : 0 Fortifiable : 2
How to pwn ?
We can easily compute the base address of the libc substracting from the printf-address (given by the program’s output) the symbols of printf contained in the libc-2.27.so.
After that we can use one_gadget to execute /bin/sh.
1 2 3 4 5 6 7 8 9 10 11 12
$ one_gadget ./libc-2.27.so 0x4f2c5 execve("/bin/sh", rsp+0x40, environ) # Let's try this one constraints: rcx == NULL