OD: Exploit Me - Overwrite Return Address
修改邻接变量的方法对代码环境限制比较多,更通用、更强大的方法是修改 EBP、返回地址等状态值。
为了方便调试,修改之前的代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<string.h> #define PASSWORD "1234567" int verify_password(char *password)
{
int authenticated=0x03050709;
char buffer[]; // add local buf to be overflowed
authenticated=strcmp(password,PASSWORD);
strcpy(buffer, password); // overflow here
return authenticated;
} int main()
{
int valid_flag=;
char password[];
if(!freopen("password.txt","r",stdin)) // 非打印字符不便于从console输入,故 redirect stdin
//FILE *fp;
//if(!(fp=fopen("password.txt","rw+")))
{
printf("file open error!\n");
exit();
}
scanf("%s",password);
//fscanf(fp,"%s",password);
printf("password input: %s\n",password);
valid_flag=verify_password(password);
if(valid_flag){
printf("Incorrect password!\n\n");
}
else
{
printf("Congratulation! You have passed the verification!\n\n");
}
//fclose(fp);
return ;
}
在 password.txt 中存储内容为 abcdefg 时,OD 调试 exp_me.exe,执行完第 12 行 strcpy 后的栈帧如下图所示:

如上图,此时栈帧中 authenticated 的值(0x0012FAE8)为 1,表示验证未通过。EBP : 0x0012FAEC,前栈帧 EBP : 0x0012FF48,返回地址 : 0x0040ECD8。
0040ECCC |. 8D95 FCFBFFFF LEA EDX,DWORD PTR SS:[EBP-]
0040ECD2 |. PUSH EDX
0040ECD3 |. E8 2D23FFFF CALL exp_me.
0040ECD8 |. 83C4 ADD ESP,
0040ECDB |. FC MOV DWORD PTR SS:[EBP-],EAX
0040ECDE |. 837D FC CMP DWORD PTR SS:[EBP-],
0040ECE2 |. 0F JE SHORT exp_me.0040ECF3
0040ECE4 |. AC404200 PUSH OFFSET exp_me.??_C@_0BG@GFGB@Incorr>; /format = "Incorrect password! "
0040ECE9 |. E8 F225FFFF CALL exp_me.printf ; \printf
0040ECEE |. 83C4 04 ADD ESP,4
0040ECF1 |. EB 0D JMP SHORT exp_me.0040ED00
0040ECF3 |> 68 6C404200 PUSH OFFSET exp_me.??_C@_0DD@FPBB@Congra>; /format = "Congratulation! You have passed the verification! "
0040ECF8 |. E8 E325FFFF CALL exp_me.printf ; \printf
0040ECFD |. 83C4 04 ADD ESP,4
0040ED00 |> 33C0 XOR EAX,EAX
0040ED02 |. 5F POP EDI
0040ED03 |. 5E POP ESI
从上面的反汇编代码可以看到,0x0040ECD8 处的代码对应源码第 30 行后恢复栈帧处,如果能将此时的返回地址覆盖为 0x0040ECF3,就能跳过错误验证流程,直接执行源码中第 36 行的 else 分支,进入验证正确后的执行流程。
用 UltraEdit 将 password.txt 修改为如下内容:

注意,CPU 为 Little_Endian 模式,最后的四字节返回地址(0x0040ECF3)要反写成 E3 EC 40 00
在返回地址之前的前栈帧地址 0x0012FF48 不能写为 48 FF 12 00,因为这里的 00 会被 scanf 当作截断符中止读取,导致内容读取不够,覆盖返回地址失败(只能覆盖到 EBP)。
修改 password.txt 后,OD 调试结果如下:

紧接着出现如下错误,因为 EBP 覆盖成了错误的 0xAA12FF48 而不是 0x0012FF48,导致栈帧不平衡。
这个问题留着以后再学习吧,今天到此了,睡觉去(2014-3-31 23:31:55)。

OD: Exploit Me - Overwrite Return Address的更多相关文章
- OD: Exploit Me - Overwrite Nearby Varible
实验代码: #include<stdio.h> #include<string.h> #define PASSWORD "1234567" int veri ...
- Multi-tasking RTOS for microprocessors with limited memory by saving only a single return address per task during context switching
A real-time operating system (RTOS) for use with minimal-memory controllers has a kernel for managin ...
- 栈帧的内部结构--动态返回地址(Return Address)
每个栈帧中包含: 局部变量表(Local Variables) 操作数栈(Opreand Stack) 或表达式栈 动态链接 (Dynamic Linking) (或指向运行时常量的方法引用) 动态返 ...
- OD: Exploit Me - Inject Instruction
修改之前的代码: #include<stdio.h> #include<stdlib.h> #include<string.h> #include<windo ...
- OD: Shellcode / Exploit & DLL Trampolining
看到第五章了. 标题中 Dll Tramplining(跳板)名字是从如下地址找到的,写的很好: http://en.wikipedia.org/wiki/Buffer_overflow#The_ju ...
- BUFFER OVERFLOW 10 Vulnerability & Exploit Example
SRC= http://www.tenouk.com/Bufferoverflowc/Bufferoverflow6.html THE VULNERABLE AND THE EXPLOIT W ...
- OD: ASLR
ASLR,Address Space Layout Randomization,通过加载程序的时候不再使用固定的基址,从而干扰 shellcode 定位的一种保护机制,包括映像随机化.堆栈随机化.PE ...
- Detecting a return-oriented programming exploit
A method and apparatus for detecting a Return-Oriented Programming exploitation. At a computer devic ...
- OD: DEP - Ret2Libc via VirtualProtect() & VirtualAlloc()
一,通过 VirutalProtect() 修改内存属性绕过 DEP DEP 的四种工作模式中,OptOut 和 AlwaysOn 下所有进程默认都开启 DEP 保护,这里如果一个程序自身需要从堆栈中 ...
随机推荐
- Jq/Js收集
判断checkbox选中的个数1.$('#del').click(function(){ var length = $("input[name='checkItem']:checked&qu ...
- sql语法图
- 记一次 nginx 504 Gateway Time-out
今天程序在执行一项excel导出任务的时候 出现了nginx超时的提示 nginx 504 Gateway Time-out 排查过程: 查看该任务 发现内容是一个数据量20000条信息 每条信息有5 ...
- Css透明度
全透明代码:{background:transparent} 半透明代码:{filter:alpha(opacity=80);-moz-opacity:0.8;width:auto !importan ...
- Centos7 wget和普通下载有区别
今天下的禅道 wget和用win下载之后再ssh传过去,效果不一样 wget不能正常启动禅道.回来要探讨一下wget的不同之处,先记下来
- 一个读取propeties配置文件的工具类,线程安全的
public class ConfigUtil { private static Map<String,Properties> map = new HashMap<String,Pr ...
- ASP超级网店V2.5一注入漏洞
Title:ASP超级网店V2.5一注入漏洞 --2011-10-30 17:59 ASP超级网店V2.5 这个系统,有很多地方可以注入 http://www.xxxxxx.com/admin/pi ...
- Android百度地图默认位置中心点设置
//初始化地图 MapView mMapView = (MapView) findViewById(R.id.map); BaiduMap mBaidumap = mMapView.getMap ...
- Leetcode:Largest Number详细题解
题目 Given a list of non negative integers, arrange them such that they form the largest number. For e ...
- VS快捷键大全(转)
相信.Net开发人员都想能够熟记各种VS快捷键以提高平时开发的效率,但苦于记忆能力太差而快捷键又特别多,特别烦,所以作罢! 下面我将简单介绍一下我记忆VS快捷键的一些方法,希望对大家有所帮助. 1.窗 ...