修改邻接变量的方法对代码环境限制比较多,更通用、更强大的方法是修改 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的更多相关文章

  1. OD: Exploit Me - Overwrite Nearby Varible

    实验代码: #include<stdio.h> #include<string.h> #define PASSWORD "1234567" int veri ...

  2. 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 ...

  3. 栈帧的内部结构--动态返回地址(Return Address)

    每个栈帧中包含: 局部变量表(Local Variables) 操作数栈(Opreand Stack) 或表达式栈 动态链接 (Dynamic Linking) (或指向运行时常量的方法引用) 动态返 ...

  4. OD: Exploit Me - Inject Instruction

    修改之前的代码: #include<stdio.h> #include<stdlib.h> #include<string.h> #include<windo ...

  5. OD: Shellcode / Exploit & DLL Trampolining

    看到第五章了. 标题中 Dll Tramplining(跳板)名字是从如下地址找到的,写的很好: http://en.wikipedia.org/wiki/Buffer_overflow#The_ju ...

  6. BUFFER OVERFLOW 10 Vulnerability & Exploit Example

    SRC= http://www.tenouk.com/Bufferoverflowc/Bufferoverflow6.html THE VULNERABLE AND THE EXPLOIT     W ...

  7. OD: ASLR

    ASLR,Address Space Layout Randomization,通过加载程序的时候不再使用固定的基址,从而干扰 shellcode 定位的一种保护机制,包括映像随机化.堆栈随机化.PE ...

  8. Detecting a return-oriented programming exploit

    A method and apparatus for detecting a Return-Oriented Programming exploitation. At a computer devic ...

  9. OD: DEP - Ret2Libc via VirtualProtect() & VirtualAlloc()

    一,通过 VirutalProtect() 修改内存属性绕过 DEP DEP 的四种工作模式中,OptOut 和 AlwaysOn 下所有进程默认都开启 DEP 保护,这里如果一个程序自身需要从堆栈中 ...

随机推荐

  1. 真机测试,Xcode报错:process launch failed: Security

    解决办法:手机->通用->设备管理->信任开发商应用即可

  2. JS+CSS+HTML简单计算器

    <!doctype html> <html> <head> <title>计算器</title> <meta charset=&quo ...

  3. java事件处理3

    鼠标拖动事件 接口MouseMotionListener 两个方法 mouseDragged(MouseEvent)//拖动鼠标 mouseMoved(MouseEvent)//移动鼠标 一个拖动按钮 ...

  4. js 浏览器版本检测

    整理了一下浏览器检测的js脚本 分享给大家 浏览器检测一般都是在网页打开的时候执行 使用js的闭包来实现页面加载以后执行的脚本 (function(){ //页面加载后执行的脚本 })() ; 检测浏 ...

  5. HTML5 canvas文本属性与方法

    文本属性和方法 font                        设置或返回文本内容的当前字体属性 textAlign                设置或返回文本内容的当前对齐方式 start ...

  6. php resizeimage 部分jpg文件 生成缩略图失败

    今天遇到GD的resizeimage 函数处理jpg后缀文件的缩略图的时候 提示该图片不是合法的jpg图片并报错 <b>Warning</b>: imagecreatefrom ...

  7. MOOTOOLS和JQUERY如何同时存在,解决冲突

    mootools-jquery 今天在做EcStore前台的做效果时,由于Jquery的插件比较多,于是就使用了Jquery的插件,但是发现会引起Mootools的冲突. 于是猛找资料,终于找到了,现 ...

  8. 手机端禁止iPhone字体放大

    /*禁止iphone字体放大 */ html { -webkit-text-size-adjust: none; }

  9. UIImagePickerController 操作图库

     UIImagePickerController详解   转载自:http://blog.csdn.net/kingsley_cxz/article/details/9157093 1.UIImage ...

  10. IE6\ IE7、IE8\9\10和Firefox的hack方式

    #test{color:red;color:red !important;/ Firefox.IE7支持 */_color:red; / IE6支持 */*color:red; / IE6.IE7支持 ...