一、实验说明
1、实验环境:
Distributor ID: Ubuntu
Description: Ubuntu 16.04.1 LTS
Release: 16.04
Codename: xenial
2、实验工具:
gdb
3、源码
首先看看abo3的源码:
/* abo3.c *
* specially crafted to feed your brain by gera@core-sdi.com */
/* This'll prepare you for The Next Step */
int hacked(void)
{
printf("Congratulation! You have successed!\n");
return 0;
}
int main(int argv,char **argc) {
extern system, puts;
void (* fn)(char*)=(void(*)(char*))& system;
char buf[256];
fn=(void(*)(char*))& puts;
strcpy(buf,argc[1]);
fn(argc[2]);
exit(1);
}
4、实验目的
构造字符串,实现栈溢出,从而执行函数hacked()。
5、编译:
二、调试
1、使用指令disas main查看汇编代码
地址0x8048514处,对eax进行赋值,然后在0x8048517处,call eax,即跳转到eax所存储的地址处。
2、分别在main函数开头、地址0x8048500和0x8048517处下断点。
3、输入字符串并运行,此时返回地址已经入栈,地址是0xffffcfcc。
4、使用c指令直接运行到第二个断点处,eax中存储了buf的地址,为0xffffceac。
5、使用c指令直接运行到第三个断点处,此时已完成赋值操作,eax=0x8048360
6、接下来跳转到0x8048360处继续执行。
7、小结
此程序通过call eax来跳转到相应地址,而eax=[ebp-0xc]。因此,只需修改ebp-0xc处的值,即可控制程序的执行流程。