因为今年接触到信息安全,所以更多的往原理性的东西看看,以前也知道有什么冲击波病毒,等等什么,什么缓冲区溢出漏洞等等

但是为什么呢,不明白?

所以在网站上特别搜索了一些这样的简单程序。

下面就是我这两天在找到的程序,很简单,但我目前还没看懂,原理明白,但因汇编不熟,谁叫我不是计算机专业的,半路出家:(

 

// gongji.cpp : Defines the entry point for the console application.
//

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

void gongji()
{
printf("大家可以看到攻击函数执行了\n");
getch();
exit(-1); //为防止程序非正常退出,所以在这里强制结束程序了。
}

void ceshi(const char * input)
{
char buf[10];
strcpy(buf,input); //有问题的语句

}

void main()
{
//先用printf("%p\n",gongji);得到gongji()函数的地址

//我得到的是0x0040100f (vc++6.0,debug版本)
//0x0040100f 依次对应的8进制的 0,100,20,17,但地址要反过来写\17\20\100\0
//printf("%p\n",gongji);
char buffer[21]="ABCDEFGHIJKLMNOP\17\20\100\0";
ceshi(buffer);
}

 

我看了一下stcpy的算法和asm代码,只是看不太懂asm的东西,下面贴出来

;char *strcpy(dst, src) - copy one string over another
;
;Purpose:
;       Copies the string src into the spot specified by
;       dest; assumes enough room.
;
;       Algorithm:
;       char * strcpy (char * dst, char * src)
;       {
;           char * cp = dst;
;
;           while( *cp++ = *src++ )
;                   ;               /* Copy src over dst */
;           return( dst );
;       }
;
;Entry:
;       char * dst - string over which "src" is to be copied
;       const char * src - string to be copied over "dst"
;
;Exit:
;       The address of "dst" in EAX
;
;Uses:
;       EAX, ECX
;
;Exceptions:
;*******************************************************************************

 

 

 

%       public  strcat, strcpy      ; make both functions available
strcpy  proc
        push    edi                 ; preserve edi
        mov     edi,[esp+8]         ; edi points to dest string
        jmp     short copy_start

strcpy  endp

        align   16

 如果有人很清楚这些,请指点一二

我以后会继续关注程序安全的问题

posted on 2008-08-28 22:41  黄剑父  阅读(383)  评论(0编辑  收藏  举报