Ben-Lichtman/ropr
GitHub: Ben-Lichtman/ropr
一款基于 Rust 的高性能多线程 ROP Gadget 搜索工具,用于快速从二进制文件中定位可用代码片段以辅助漏洞利用链构建。
Stars: 550 | Forks: 31
# ropr
ropr 是一个极速的多线程 ROP Gadget 查找工具
### 什么是 ROP Gadget?
ROP(Return Oriented Programming,返回导向编程)Gadget 是一小段包含几条汇编指令的代码片段,通常以 `ret` 指令结尾,它们已经作为可执行代码存在于每个二进制文件或库中。这些 gadget 可用于二进制漏洞利用以及篡改存在漏洞的可执行文件。
当许多 ROP Gadget 的地址被写入一个缓冲区时,我们就形成了一个 ROP Chain。如果攻击者能够将栈指针移动到这个 ROP Chain 中,控制权就可以被完全转移给攻击者。
大多数可执行文件包含足够的 gadget 来编写一个图灵完备的 ROP Chain。对于那些不包含足够 gadget 的可执行文件,一旦我们知道了动态库(例如位于同一地址空间中的 libc)的地址,就可以随时利用它们。
使用 ROP Gadget 的美妙之处在于,不需要在任何地方写入新的可执行代码——攻击者可以只利用程序中已经存在的代码来实现他们的目标。
### 如何使用 ROP Gadget?
通常,使用 ROP Gadget 的第一个要求是有一个可以写入 ROP Chain 的位置——这可以是任何可读的缓冲区。只需将要使用的每个 gadget 的地址写入该缓冲区即可。如果缓冲区太小,可能没有足够的空间写入较长的 ROP Chain,因此攻击者应注意精心设计其 ROP Chain,使其足够高效以适应可用的空间。
下一个要求是能够控制栈——这可以表现为栈溢出,允许将 ROP Chain 直接写入栈指针下方;或者表现为“stack pivot”(栈 piviot),这通常是一个单一的 gadget,用于将栈指针移动到 ROP Chain 的其余部分。
一旦栈指针位于 ROP Chain 的起始位置,下一条 `ret` 指令就会触发 gadget 按顺序执行——每个 gadget 都将其下一个 gadget 的地址作为其自身栈帧的返回地址。
还可以将函数指针添加到 ROP Chain 中——需要注意,函数参数应在 ROP Chain 的下一个元素之后提供。这通常与一个“pop gadget”结合使用,该 gadget 会将参数弹出栈,以便在处理完函数参数后平稳过渡到下一个 gadget。
### 如何安装 ropr?
- 需要 cargo(Rust 构建系统)
简单安装:
```
cargo install ropr
```
应用程序将安装到 `~/.cargo/bin`
从源码构建:
```
git clone https://github.com/Ben-Lichtman/ropr
cd ropr
cargo build --release
```
生成的二进制文件将位于 `target/release/ropr`
另一种方式:
```
git clone https://github.com/Ben-Lichtman/ropr
cd ropr
cargo install --path .
```
应用程序将安装到 `~/.cargo/bin`
### 如何使用 ropr?
```
USAGE:
ropr [OPTIONS]
ARGS:
The path of the file to inspect
OPTIONS:
-b, --base-pivot Filters for gadgets which alter the base pointer
-c, --colour Forces output to be in colour or plain text (`true` or `false`)
-h, --help Print help information
-j, --nojop Removes "JOP Gadgets" - these may have a controllable branch,
call, etc. instead of a simple `ret` at the end
-m, --max-instr Maximum number of instructions in a gadget [default: 6]
-n, --noisy Includes potentially low-quality gadgets such as prefixes,
conditional branches, and near branches (will find significantly
more gadgets)
-p, --stack-pivot Filters for gadgets which alter the stack pointer
-r, --norop Removes normal "ROP Gadgets"
-R, --regex Perform a regex search on the returned gadgets for easy filtering
--range Search between address ranges (in hexadecial) eg. `0x1234-0x4567`
--raw Treats the input file as a blob of code (`true` or `false`)
-s, --nosys Removes syscalls and other interrupts
-V, --version Print version information
```
例如,如果我正在寻找一种用来自另一个寄存器的值填充 `rax` 的方法,我可以选择按正则表达式 `^mov eax, ...;` 进行过滤:
```
❯ ropr /usr/lib/libc.so.6 -R "^mov eax, ...;" > /dev/null
==> Found 197 gadgets in 0.118 seconds
```
现在我可以向命令行添加一些过滤器以获取最高质量的结果:
```
❯ ropr /usr/lib/libc.so.6 -m 2 -j -s -R "^mov eax, ...;"
0x000353e7: mov eax, eax; ret;
0x000788c8: mov eax, ecx; ret;
0x00052252: mov eax, edi; ret;
0x0003ae43: mov eax, edx; ret;
0x000353e6: mov eax, r8d; ret;
0x000788c7: mov eax, r9d; ret;
==> Found 6 gadgets in 0.046 seconds
```
现在我得到了一个很好的 `mov` gadget 候选项,其地址为 `0x00052252`
标签:ASLR绕过, CTF安全工具, DEP绕过, ROP Gadget, ropgadget替代, ropper替代, ROP链, x86, 二进制安全, 二进制漏洞利用, 云资产清单, 可视化界面, 堆栈转移, 栈溢出, 模糊测试辅助, 汇编, 网络安全, 返回导向编程, 逆向工程, 通知系统, 隐私保护