Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1077716
  • 博文数量: 104
  • 博客积分: 3715
  • 博客等级: 中校
  • 技术积分: 1868
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-30 08:38
文章分类

全部博文(104)

文章存档

2013年(1)

2012年(9)

2011年(41)

2010年(3)

2009年(3)

2008年(47)

分类: C/C++

2008-08-19 17:02:02

下午什么也不想干,心气烦躁......
基本上是打开什么,扫两眼,关掉什么。大概每个人都有这种时候吧。
无聊之余,忽然想起来以前了解过的缓冲区溢出攻击,虽然知道是怎么回事,但是从来没有自己动手写一个。于是就有了下面更加无聊的代码。在x86,32位,Fedora 9上可以成功。
%{
#include
#include
void print1(char *str);
void print2();

int main(int argc, char *argv[])
{
    char buf[32]={0};
    int *p=(int *)(buf+8);
    int i;
    for(i=0;i<8;i++)
        buf[i]='a';
    *p=(int *)print2;
    print1(buf);
    return 0;
}

void strcp(char *str1, char *str2)
{
    int i=0;
    while(str2[i]!='\0'){
        str1[i]=str2[i];
        i++;
    }
    str1[i]='\0';
    return;
}

void print1(char *str)
{
    char buf[4];
    strcp(buf,str);
    return;
}

void print2()
{
    printf("Hello, world!\n");
    exit(0);
    return;
}

%}
阅读(1496) | 评论(4) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-08-29 00:22:12

3Q

freearth2008-08-28 19:36:06

你仔细分析一下栈帧每一时刻的状态,以及函数的入口代码。 下面的代码在打印Hello, world后可以正确的执行结束。 [\code] #include #include #include void print1(char *str); void print2(); void stub(); static int main_retaddr; int main(int argc, char *argv[]) { char buf[32]={0}; int *p=(int *)(buf+8); int i; for(i=0;i<8;i++) buf[i]='b'; *p=(int *)((char *)print2+3); print1(buf); printf("Execute normally.\n"); return 0; } void strcp(char *str1, char *st

chinaunix网友2008-08-27 20:15:45

写了一个缓冲区溢出,不过有问题,能指点一下吗,谢谢 #include "stdio.h" int shellcode() { int value = 0,i; unsigned int *s = &value; printf("address of value: %x\n", &value); printf("Overflow Successful!\n"); __asm__( "movl $0x80484e1,4( %ebp )" //0x80484e1是call test 后的代码地址,此处修改后就可以跳转到test() 后的语句执行 /* "movl $0x8f4390,44( %ebp )" 如果 不加这句会出现段错误(加了也错 。。。)加这句是因为我觉得会出现段错误是让他进入shellcode,并没有用call,没有构建环境,但是却在shellcode内ret了,所以我想模仿call:push eip, 不知道该怎么改

chinaunix网友2008-08-27 20:12:08

这个程序打印出hello,world后会出现段错误,你有什么办法能解决吗(让他按原来的路径继续执行),谢谢