当前位置:网站首页>汇编语言与逆向工程 栈溢出漏洞逆向分析实验报告
汇编语言与逆向工程 栈溢出漏洞逆向分析实验报告
2022-04-23 08:28:00 【蜕寒】
汇编语言与逆向工程 栈溢出漏洞逆向分析实验报告
实验环境:windows xp professional VC6.0 OllyDBG
- 实验现象
c语言 源代码:#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define PASSWORD "1234567"
int verify_password(char *password){
int authentication;
char buffer[8];
authentication=strcmp(password,PASSWORD);
strcpy(buffer,password);
return authentication;
}
main(){
int valid_flag=0;
char password[1024];
while(1){
printf("please input pssword: ");
scanf("%s",password);
valid_flag=verify_password(password);
if(valid_flag){
printf("incorrect password!\n\n");
}
else{
printf("congratulations");
break;
}
}
system("pause");
}
正常情况:若输入的密码为1234567(已define的PASSWORD)则输出congratulations,反之输出incorrect password!。
栈溢出情况:在输入某些特定的字符串,如”12345678”时依旧输出congratulations。如下所示:
- 实验分析
将StackOverFlow.cpp在OD中打开 分析汇编语言:
main函数对应的汇编语言:
verify_password函数对应的汇编语言:
流程分析:

为main函数创建栈空间

循环:将eax赋值为1,进行与运算,易知永远不会跳转,对应while(1),不控制循环的结束。

打印:00427064存储要打印的话。

输入:将输入的password保存至ebp-404。

调用函数:将输入结果保存至数据寄存器中,然后调用地址为00401005的verify_password函数。

保存main函数环境:将调用函数前的寄存器压入栈中,以便回到主函数以后恢复main函数的环境。

创建变量

比较:先将定义的PASSWORD入栈,然后将输入的password入栈,进行比较。

将strcmp的返回值放入eax。

先将ebp+8(passward)入栈,再将buffer(ebp-c)的地址交给edx,最后将password赋值给
buffer。

将函数的返回值(ebp-4)存入到eax中,恢复环境变量,返回原函数。

将返回值存入栈底,比较0和返回值,若相等则打印incorrect password!,不相等则打印congratulations。
情况分类:
- 输入为123456时:

因为123456比1234567小 ebp-4存放FFFFFFFF,ebp-12存放着123456的ASCII码与一个截断字符00。
比较FFFFFFFF与0不等,打印incorrect password!。为正常情况。
2.输入为1234567时:

1234567与1234567相等 所以ebp-4为0,ebp-12存放1234567的ASCII码与一个阶段字符00。
比较0与0相等,打印congratulations,为正常轻狂。
3.输入为12345678时:

12345678大于1234567,所以返回01,存在ebp-4中,在strcpy前栈底如图所示。
当strcpy执行后,在ebp-12存储了12345678的ASCII码占八位,此外还有一个截断字符00,因为没有预留空间,所以存储在ebp-4的地方,此时ebp-4为0。当回到main函数时进行比较时,0与0相等,打印congratulations,发生栈溢出。
三、实验结论
由以上实验,栈溢出发生的原因主要是输入字符过长,导致截断字符占据了返回值的空 间,造成了数据的错误。
版权声明
本文为[蜕寒]所创,转载请带上原文链接,感谢
https://blog.csdn.net/anewpunpkin/article/details/124277925
边栏推荐
- Misunderstanding of flush () method of OutputStream class
- Failed to convert a NumPy array to a Tensor(Unsupported Object type int)
- Let the earth have less "carbon" and rest on the road
- Notes on English class (4)
- 分组背包呀
- 【路科V0】验证环境2——验证环境组件
- Use of Arthas in JVM tools
- Go语言自学系列 | golang结构体的初始化
- synchronized 锁的基本用法
- Swagger document export custom V2 / API docs interception
猜你喜欢

跨域配置报错: When allowCredentials is true, allowedOrigins cannot contain the special value “*“

LeetCode-199-二叉树的右视图

《深度学习》学习笔记(八)
![[learning] audio and video development from scratch (9) -- nuplayer](/img/62/20b0d80088181fb6ff1fe842500c0a.png)
[learning] audio and video development from scratch (9) -- nuplayer

Redis Desktop Manager for Mac(Redis可视化工具)

Notes on 30 steps of introduction to the Internet of things of yangtao electronics STM32 III. cubemx graphical programming and setting the IO port on the development board

Ansible Automation Operation and Maintenance details (ⅰ) Installation and Deployment, Parameter use, list Management, Profile Parameters and user level ansible operating environment Construction

分布式消息中间件框架选型-数字化架构设计(7)

Using qlst excel file

洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
随机推荐
Generate and parse tokens using JWT
rust 使用tokio的Notify 和timeout实现类似可超时条件变量的效果
经典题目刷一刷
Redis master-slave server problem
idea底栏打开services
洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
Swagger document export custom V2 / API docs interception
flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
Protobuf简介
What is RPC
信息收集相关知识点及题解
Data deletion and modification (MySQL)
Idea import commons-logging-1.2 Jar package
记录:js删除数组中某一项或几项的几种方法
对OutputStream类的flush()方法的误解
form中enctype属性
Yangtao electronic STM32 Internet of things entry 30 step notes II. Cube ide download, installation, sinicization and setting
Ansible Automation Operation and Maintenance details (ⅰ) Installation and Deployment, Parameter use, list Management, Profile Parameters and user level ansible operating environment Construction
数论求a^b(a,b为1e12级别)的因子之和
STM32使用HAL库,整体结构和函数原理介绍
