实验代码:

 #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. C++中getline函数的使用

    代码: #include <iostream> #include <cstdio> using namespace std; int main(){ char* s; s = ...

  2. VS2010 C++ 优化配置

    个人感觉VC6.0太土了,而且有很多bug存在,且微软早就不对其更新.所以,在选择C++编程的时候.使用IDE,VC6.0一段时间以后,我毅然决然的放弃了,觉得还是使用VS2010比较有前途. 但是当 ...

  3. JQuery里属性赋值,取值prop()和attr()方法?

    1.赋值的时候 如果是<input type="checkbox" checked>这样的只有属性名就能生效的属性 推荐prop,即:$('input').prop(' ...

  4. == 与 is

    Python中的对象包含三要素:id.type.valueid:用来唯一标识一个对象: type:标识对象的类型: value是对象的值. ==是判断对象的值是否相等,也就是value,is是判断对象 ...

  5. 【学习笔记】【oc】类和对象及类的三大基本特征

    1.类和对象 类是抽象化,对象是具体化. (1)定义类: 分为两个步骤,类的声明:定义类的成员变量和方法:@interface 用于声明定义类的接口部分,@end表面定义结束:. 成员变量的定义:{} ...

  6. iOS中常用的四种数据持久化方法简介

    iOS中常用的四种数据持久化方法简介 iOS中的数据持久化方式,基本上有以下四种:属性列表.对象归档.SQLite3和Core Data 1.属性列表涉及到的主要类:NSUserDefaults,一般 ...

  7. Unix和Linux下C语言学习指南

    转自:http://www.linuxdiyf.com/viewarticle.php?id=174074 Unix和Linux下C语言学习指南 引言 尽管 C 语言问世已近 30 年,但它的魅力仍未 ...

  8. grunt serve Warning: Running "sass:server" (sass) task

    使用grunt serve运行时遇到一问题: y@y:ydkt$ grunt serve Running "serve" task Running "clean:serv ...

  9. Oracle基本分组查询group by的使用

    (1)查询各个工作岗位的总人数 (2)查询各个工作岗位的总工资 (3)查询各个工作岗位的平均工资

  10. delphi编写dll心得, 谢谢原作者的分享。转

    delphi编写dll心得 1.每个函数体(包括exports和非exports函数)后面加 'stdcall;', 以编写出通用的dll2.exports函数后面必须加'export;'(放在'st ...