当前位置:网站首页>栈溢出漏洞
栈溢出漏洞
2022-06-27 02:42:00 【不会写代码的丝丽】
前言
本文利用栈溢出漏洞弹出一个警告窗口。
我们假设用户正在运行以下代码:
#include <stdio.h>
#include <string.h>
char Paswword[20]="aaaaaaaaaaaaaaaaaaa";
int main(){
char cPas[20]={
0};
int iResult;
FILE * pFile =NULL;
pFile = fopen("pd.txt","r");
fscanf(pFile,"%s",cPas);
iResult =strcmp(Paswword,cPas);
if(iResult==0){
printf("Welcome \r\n");
}else{
printf("fail \r\n");
}
getchar();
return 0;
}
就是一段读取文件后判断内容是否和预期相等。
这段代码代码在不开启任何系统保护时会利用fscanf
进行栈溢出。fscanf
会一直读取字符串直到碰到特殊字符为止,而cPas
又是在栈上的,假设我们有如下骚操作:
恶意程序伪装为pd.txt
,并且大小大于20字节。那么将会覆盖原始的栈上存储的返回地址。
是一个很特殊的地址7ffa4512
,大多数用户电脑这个内存地址都是一个特殊的指令jmp esp
.我们把这个地址称为通用跳板地址,当然你可以找到其他类似地址。
也就是函数返回时会执行 jmp esp,转而跳转到我们栈溢出的代码。
我们绘制一个流程如下:
当你写了一伪装的pd.txt
伪装文件后你会发现你的.恶意代码太长了,原始程序预留空间不足。
于是乎我们会在此利用fscanf
漏洞,但在利用前首先抬起栈保证足够的存储空间放入恶意代码。
fscanf
会截断特殊字符,所以你的恶意代码可能会被截断,因此我们需要对恶意代码出现截断字符进行转义,我们采取异或方式进行处理。
鄙人写了一个小程序方便快速转义,可以通过下文链接下载。
我们从头整理我们需要做的事情:
- 伪装"pd.txt"
- “pd.txt” 内部进行栈溢出
- “pd.txt” 再次利用scanf 进行栈溢出加载恶意程序
- 异或返回恶意程序源代码
- 运行异或代码
保护
下面两个安全开关都会校验内存区域的可执行权限。一般情况下不可执行区域的权限不会严格检验。
开启电脑DEP
PE中开启部分特性
跳板地址改为修改权限即可绕过这类保护
- 编译器开启GS选项
GS 安全选项
开了这个选项后,编译时会在函数EBP
之前插入一个探测数据。如下图所示
在函数进入后 会放一个变量到栈区中,在函数返回前插入一段代码检测这个变量是否改变。
工具
我们编写shellcode时可以利用已有的工具帮助我们快速生产符合预期的代码,比如过滤掉特殊敏感字符。如注明的MSF
程序.
比如下面的命令會生成一個代碼無關的messagebox汇编代码
msfvenom -p windows/messagebox -e x86/shikata_ga_nai -f raw -o shellcode0
源码
边栏推荐
- Learn Tai Chi maker mqtt (IX) esp8266 subscribe to and publish mqtt messages at the same time
- Would rather go to 996 than stay at home! 24 years old, unemployed for 7 months, worse than work, no work
- 流沙画模拟器源码
- Oracle/PLSQL: NumToDSInterval Function
- How does the C # TCP server limit the number of connections to the same IP?
- Don't be brainwashed. This is the truth about the wages of 90% of Chinese people
- Mmdetection uses yolox to train its own coco data set
- Microsoft365开发人员申请
- C# Tcp服务器如何限制同一个IP的连接数量?
- Oracle/PLSQL: Lpad Function
猜你喜欢
How does the brain do arithmetic? Both addition and subtraction methods have special neurons, and the symbol text can activate the same group of cell sub journals
TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘
Learn from Taiji Maker - mqtt Chapter 2 (I) QoS service quality level
Learn Tai Chi Maker - mqtt Chapter 2 (3) reserved messages
Introduction to stm32
超级详细,2 万字详解,吃透 ES!
参数估计——《概率论及其数理统计》第七章学习报告(点估计)
Yiwen teaches you Kali information collection
Google began to roll itself, AI architecture pathways was blessed, and 20billion generation models were launched
Why pass SPIF_ Sendchange flag systemparametersinfo will hang?
随机推荐
P5.js death planet
Flink learning 5: how it works
Microsoft365开发人员申请
Learn Tai Chi maker mqtt (IX) esp8266 subscribe to and publish mqtt messages at the same time
Oracle/PLSQL: Translate Function
Why pass SPIF_ Sendchange flag systemparametersinfo will hang?
学习太极创客 — MQTT 第二章(一)QoS 服务质量等级
Oracle/PLSQL: From_ Tz function
Flink学习2:应用场景
Flink學習2:應用場景
TechSmith Camtasia latest 2022 detailed function explanation Download
2022年氯碱电解工艺试题及答案
Flink学习5:工作原理
[Shangshui Shuo series] day 6
Web development framework - Express (installation and use, static hosting, routing processing, use of Middleware)
1. Project preparation and creation
Flink学习1:简介
h5液体动画js特效代码
CVPR2022 | PointDistiller:面向高效紧凑3D检测的结构化知识蒸馏
lottie. JS creative switch button animal head