tommy

It's hard to tell the world we live in is either a reality or a dream
posts - 52, comments - 17, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

最简单的堆栈溢出demo

Posted on 2005-12-03 14:04 Tommy Liang 阅读(2630) 评论(4)  编辑 收藏 引用
参考了Nish Bhalla的堆栈溢出教程。要看到效果必须把VC编译选项 /GZ去掉。

#include "stdafx.h"
#include 
<string.h>
#include 
<stdlib.h>

int copy(char* input)
{
    
char var[20];
    strcpy (var, input);
    
return 0;
}

int hacked(void)
{
    printf(
"这里是堆栈溢出程序.看到我了吧.\n");
    exit(
0);
}

int main(int argc, char* argv[])
{
    
char hackstr[] = "AAAABBBBCCCCDDDDEEEEFFFFGGGG";
    
int *eip = (int*)&hackstr[24];        //20->23是EBP
    *eip = (int)hacked;

    copy(hackstr);
    
return 0;
}

Feedback

# re: 最简单的堆栈溢出demo  回复  更多评论   

2007-04-25 15:17 by lemonwater
这个应该有什么效果呀?我编译运行后,直接就是windows的错误提示了。

# re: 最简单的堆栈溢出demo  回复  更多评论   

2007-04-25 19:46 by tommy
要看到效果必须把VC编译选项 /GZ去掉。

# re: 最简单的堆栈溢出demo  回复  更多评论   

2009-08-05 17:33 by nuke
int *eip = (int*)&hackstr[24]; //20->23是EBP
这一行中的[24]应该改成[20]吧,我是arm指令

# re: 最简单的堆栈溢出demo  回复  更多评论   

2010-04-19 22:43 by 石头儿
在哪儿有个/gz 啊大哥

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理