当前位置:网站首页>栈溢出漏洞
栈溢出漏洞
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
源码
边栏推荐
- [micro service sentinel] degradation rules slow call proportion abnormal proportion abnormal constant
- 对数器
- Oracle/PLSQL: Replace Function
- lottie. JS creative switch button animal head
- Look! In June, 2022, the programming language ranking list was released! The first place is awesome
- 学习太极创客 — MQTT(八)ESP8266订阅MQTT主题
- Oracle/PLSQL: Soundex Function
- Constraintlayout Development Guide
- 企业数字化转型:信息化与数字化
- Test the respective roles of nohup and &
猜你喜欢

Press key to control LED status reversal

Dameng database installation

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

lottie.js创意开关按钮动物头像

学习太极创客 — MQTT 第二章(一)QoS 服务质量等级

超级详细,2 万字详解,吃透 ES!

p5.js死亡星球

Learn from Taiji Maker - mqtt Chapter 2 (I) QoS service quality level

Solve the problem of error reporting in cherry pick submission

Qingscan use
随机推荐
Uninstallation of Dameng database
Would rather go to 996 than stay at home! 24 years old, unemployed for 7 months, worse than work, no work
lodash get js代码实现
Oracle/PLSQL: Translate Function
Flink学习4:flink技术栈
学习太极创客 — MQTT 第二章(二)ESP8266 QoS 应用
Is the division of each capability domain of Dama, dcmm and other data management frameworks reasonable? Is there internal logic?
Laravel 的 ORM 缓存包
Enterprise digital transformation: informatization and digitalization
超级详细,2 万字详解,吃透 ES!
元透实盘周记20220627
Memcached basics 15
学习太极创客 — MQTT(六)ESP8266 发布 MQTT 消息
C# Tcp服务器如何限制同一个IP的连接数量?
Oracle/PLSQL: VSize Function
学习太极创客 — MQTT(九)ESP8266 同时订阅和发布 MQTT 消息
lottie.js创意开关按钮动物头像
YaLM 100B:来自俄罗斯Yandex的1000亿参数开源大模型,允许商业用途
Yiwen teaches you Kali information collection
Summer planning for the long river