实验代码:

 #include<stdio.h>
#include<string.h>
#define PASSWORD "1234567" int verify_password(char *password)
{
int authenticated;
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[];
while(){
printf("Please input password: ");
scanf("%s",password);
valid_flag=verify_password(password);
if(valid_flag){
printf("Incorrect password!\n\n");
}
else
{
printf("Congratulation! You have passed the verification!\n\n\n");
break;
}
}
return ;
}

注意以上第 8 行和第 10 行的代码,对于猜测变量在内存的相对位置和溢出尝试有用。

栈帧

程序执行到 int verify_password(char *password) 时的栈帧如图:

(变量在内存中的位置可能因编译优化而与上图不一致)

可见 authenticated (int 类型,内存中为 DWORD,占 4 字节)恰在 buffer 的 “下方”,如果 buffer 越界,那么 buffer[8..11] 刚好能覆盖 authenticated !

如果输入的字符超过 7 个字符(null 会占第 8 个字符),则越界字符会覆盖 authenticated。若 authenticated 被覆盖为 0,则溢出成功。

TIPS:用 OllyDBG 调试时可在栈区用【右键→Go to EBP】快速定位当前的 EBP,如图:

TIPS:用 OllyDBG 调试时可用 F2 设置断点。

OllyDbg 调试可见,输入 8 位密码 12345678,当程序执行完第 10 行后,authenticated 的值恰好被 password 的第九位字符串结束符 \0 覆盖为 0x00000000

但需注意 authenticated 的值来源于第 9 行的 strcpy,如果输入的密码是 01234567,则 strcpy 返回 -1,authenticated 为 -1 的补码 0xFFFFFFFF,此时溢出后不能欺骗成功。

OD: Exploit Me - Overwrite Nearby Varible的更多相关文章

  1. OD: Exploit Me - Overwrite Return Address

    修改邻接变量的方法对代码环境限制比较多,更通用.更强大的方法是修改 EBP.返回地址等状态值. 为了方便调试,修改之前的代码如下: #include<stdio.h> #include&l ...

  2. OD: Exploit Me - Inject Instruction

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

  3. OD: Shellcode / Exploit & DLL Trampolining

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

  4. OD: Kernel Exploit - 2 Programming

    本节接前方,对 exploitme.sys 进行利用. exploitme.sys 存在任意地址写任意内容的内核漏洞,现在采用执行 Ring0 Shellcode 的方式进行利用. 获取 HalDis ...

  5. OD: Kernel Exploit - 1

    第 22 章,内核漏洞利用技术 首先编写具有漏洞的驱动 exploitme.sys,再展开内核漏洞利用思路和方法: /***************************************** ...

  6. OD: Heap Exploit : DWORD Shooting & Opcode Injecting

    堆块分配时的任意地址写入攻击原理 堆管理系统的三类操作:分配.释放.合并,归根到底都是对堆块链表的修改.如果能伪造链表结点的指针,那么在链表装卸的过程中就有可能获得读写内存的机会.堆溢出利用的精髓就是 ...

  7. struts2 CVE-2012-0392 S2-008 Strict DMI does not work correctly allows remote command execution and arbitrary file overwrite

    catalog . Description . Effected Scope . Exploit Analysis . Principle Of Vulnerability . Patch Fix 1 ...

  8. gdb windbg and od use

    gdb aslr -- 显示/设置 gdb 的 ASLR asmsearch -- Search for ASM instructions in memory asmsearch "int ...

  9. An iOS zero-click radio proximity exploit odyssey

    NOTE: This specific issue was fixed before the launch of Privacy-Preserving Contact Tracing in iOS 1 ...

随机推荐

  1. oracle过滤名字中含有_的行

    select * from emp where ename like '%\_%' escape '\'; escape 定义转义字符串,这样转义字符串后的字符就是普通字符.

  2. 完整版的strcpy函数

    char *strcpy(char *strDest,const char *strSrc) { assert((strDest!=NULL) && (strSrc!=NULL)); ...

  3. js 邮箱正则匹配

    $(function(){ var valAttr = '746979855qq.com'; \-])+\.)+([a-zA-Z0-]{,})+$/; var tmpresult = mail_fil ...

  4. WinForm------DateTime获取月第一天和最后一天取法

    转载: http://blog.csdn.net/livening/article/details/6049341/ 代码: /// <summary> /// 取得某月的第一天 /// ...

  5. oldboy第二天学习

    一.上课体验及感受 第二天上课了,从循环到队列,感觉都可以接受,但是当循环遇到队列之后感觉脑袋就有点不够用了.不知道是因为萌新的问题.每个人都这样,还是个人能力不行.总而言之加油努力吧!! 二.循环, ...

  6. c语言判断用户是否输入-非阻塞函数kbhit

    一.基础研究 要从地址读取数据,肯定是要定义一个指针变量p,用它来实现变换地址和取值的功能.另外程序是当两个条件中的某一个出现时才停止,所以应该用while~do循环语句循环输出n和d,并用while ...

  7. AdHoc发布时出现重复Provisioning Profile的解决方案

    当在developer.apple.com更新Provisioning Profile(添加新机器)后,下载到本地,双击载入xcode,运行时没问题.但如果用adhoc发布,可能会发现重复的provi ...

  8. 优秀的VeriSign和混蛋的GlobalSign

    由于领导不懂行,直接购买了GlobalSign的证书,结果引起了我这个开发人员痛苦的2星期之旅,说说大体情况: 目的:对买来的一个驱动程序进行签名,使之能够在Win x64情况下安装和使用 下载Win ...

  9. java中Runnable接口含义

    Java中实现多线程有两种途径:继承Thread类或者实现Runnable接口. Runnable接口非常简单,就定义了一个方法run(),继承Runnable并实现这个 方法就可以实现多线程了,但是 ...

  10. SqlMapConfig.xml全局配置文件解析

    一:SqlMapConfig.xml配置文件的内容和配置顺序如下 properties(属性) settings(全局配置参数) typeAiases(类型别名) typeHandlers(类型处理器 ...