
ROPium(原ROPGenerator)是一个库/工具,用于简化ROP漏洞利用。它能自动从二进制文件中提取和分析gadget,并通过语义查询帮助您找到ROP链。ROPium支持X86和X64架构,即将扩展支持ARM。
主要特性:
rax=rbx+8,[rdi+0x20]=rax,rsi=[rbx+16],0x08040212(1, 2, rax),[0xdeadbeaf] = "/bin/sh\x00",sys_execve(0xdeadbeef, 0, 0),sys_0x1(0),...首先安装 Capstone 反汇编框架:
sudo apt-get install libcapstone-dev
您还需要最新的 ROPgadget 版本:
git clone https://github.com/JonathanSalwan/ROPgadget && cd ROPgadget
python setup.py install --user
若要使用CLI工具,请安装 prompt_toolkit:
pip3 install prompt_toolkit
最后安装 ROPium:
git clone https://github.com/Boyan-MILANOV/ropium && cd ropium
make
make test
sudo make install
借助命令行界面包装器,您可以交互式地使用ROPium快速构建ROP链:
需要将ROP链直接集成到您的脚本中吗?好消息,ROPium拥有Python API!
加载二进制文件并查找ROP链:
from ropium import *
rop = ROPium(ARCH.X64)
rop.load('/lib/x86_64-linux-gnu/libc-2.27.so')
chain = rop.compile('rbx = [rax + 0x20]')
以多种格式导出ROP链:
>>> print( chain.dump() )
0x000000000009a851 (sub rax, 0x10; ret)
0x0000000000130018 (mov rax, qword ptr [rax + 0x30]; ret)
0x0000000000052240 (push rax; pop rbx; ret)
>>> print(chain.dump('python'))
from struct import pack
off = 0x0
p = ''
p += pack('<Q', 0x000000000009a851+off) # sub rax, 0x10; ret
p += pack('<Q', 0x0000000000130018+off) # mov rax, qword ptr [rax + 0x30]; ret
p += pack('<Q', 0x0000000000052240+off) # push rax; pop rbx; ret
>>> print(chain.dump('raw'))
b'Q\xa8\t\x00\x00\x00\x00\x00\x18\x00\x13\x00\x00\x00\x00\x00@"\x05\x00\x00\x00\x00\x00'
对ROP链设置约束:
# Bytes that should not appear in the ropchain
rop.bad_bytes = [0x00, 0x0a, 0x0b]
# Register that should not be clobbered by the ropchain
rop.keep_regs = ['rsi', 'rdx']
# Enable/Forbid ropchain to dereference registers that might hold invalid addresses
# Safe mode is 'True' by default
rop.safe_mem = False
# Specify which ABI you want to use when calling functions
rop.abi = ABI.X86_CDECL
# Specify which system to target when doing syscalls
rop.os = OS.LINUX
如有需要,可以在Docker容器中运行ROPium。可按如下方式从Dockerfile生成容器:
# Create your docker image (this will take time!)
docker build . --tag ropium
# Run the image in interactive mode, bind mounting the file to analyze
docker run --rm -it -v /FULL/HOST/PATH/FILE:/tmp/FILE:ro ropium
(ropium)> load -a X86 /tmp/FILE
实际镜像大小约为200 MB,基于Debian Stretch并安装了Python 3.7.3。
Boyan MILANOV - boyan.milanov (at) hotmail (dot) fr
ROPium采用MIT许可证。
贡献者:
ROPium使用了以下优秀项目: