|
|
报告名称:phpcms v9 2013-02-01 会员中心注入漏洞分析报告& n! u X* V( ? [! M/ H- x
漏洞作者:skysheep
: N+ `$ n* n# O. z) T9 r分析作者:Seay
" s9 l$ @1 }& V+ j, F# M博客:http://www.cnseay.com/" X, W/ U7 |& n+ l- V+ Q
漏洞分析:, X6 L& g- h! v: @
漏洞存在于 phpcms\modules\member\index.php 文件account_manage_info函数,其功能是更新会员信息。! s) ]3 X7 B& v1 P0 o- x
; I- ?* S- m, F8 R5 K3 u
8 H: y0 y) _; \) O Z3 [9 M
5 l- ]* L+ r6 V/ k1 Z6 _; rpublic function account_manage_info() {
2 n! o. M1 H* C3 U if(isset($_POST['dosubmit'])) { 6 ^7 U8 V& Y e% U* X& _
//更新用户昵称 " ^' d) [& N0 I/ i
$nickname = isset($_POST['nickname']) && trim($_POST['nickname']) ? trim($_POST['nickname']) : '';
- k/ z+ T1 W% U a% y# u if($nickname) { 2 i) u, M, ^9 |( F& J V8 V
$this->db->update(array('nickname'=>$nickname), array('userid'=>$this->memberinfo['userid'])); ( ?- ]1 M! H. ~+ ^" E
if(!isset($cookietime)) { 2 \% Z- t; l& o. N7 o8 u
$get_cookietime = param::get_cookie('cookietime');
% ^3 d3 W) J4 J- E# ] } 0 R. @% I6 Q- w) W! C
$_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0);
" R! ]. c+ X( z) t; g $cookietime = $_cookietime ? TIME + $_cookietime : 0;
9 d: ~ T) m2 c$ o. j4 d" k param::set_cookie('_nickname', $nickname, $cookietime); . g* U. v# g& w" G
}
& _) P( _* r9 y: ^$ ` require_once CACHE_MODEL_PATH.'member_input.class.php'; ) c& V1 O4 C6 y! ]- S4 G8 g
require_once CACHE_MODEL_PATH.'member_update.class.php'; 5 H. H u& o5 w' n
$member_input = new member_input($this->memberinfo['modelid']);
& Y6 J5 n$ ?% C1 i/ w/ ^ $modelinfo = $member_input->get($_POST['info']);
1 n7 a( F K7 a, l* `$ h9 h $this->db->set_model($this->memberinfo['modelid']); + S4 q7 I) K6 _* B' r+ v
$membermodelinfo = $this->db->get_one(array('userid'=>$this->memberinfo['userid']));
' B( v! U- b( r5 e7 `9 w if(!empty($membermodelinfo)) {
- l5 m* D; [2 J6 n $this->db->update($modelinfo, array('userid'=>$this->memberinfo['userid'])); ( u% w. E3 l9 t3 ` a" s
} else { V% p) O$ q+ Z6 Y
$modelinfo['userid'] = $this->memberinfo['userid']; ) ^, s/ b, S( k
$this->db->insert($modelinfo); 6 r) |' i( R, K; ?7 h* E5 n3 L, {
}
# O2 b# ?' o& L" k" |代码中:$modelinfo = $member_input->get($_POST['info']);取得提交上来的会员模型中的字段,我们跟进member_input类中的get()函数看看,
n9 J, B# |) n% u# e+ u/ ^ D在\caches\caches_model\caches_data\ member_input.class.php 文件中:
5 X5 w1 W4 z: ^ n0 m
* ^4 `% W. c/ \2 f; m$ V* i3 q' }. f7 R* \: k3 b* O7 h
: ]9 w. g+ M/ [0 u
function get($data) { 8 C3 b+ F; M# J* T" k( k$ l
$this->data = $data = trim_script($data); , Q6 ~1 f3 R" G' |$ f
$model_cache = getcache('member_model', 'commons'); 9 X. i/ c' _4 y2 w. r
$this->db->table_name = $this->db_pre.$model_cache[$this->modelid]['tablename'];
! @0 A" j, _& ~ $info = array(); S0 u* B9 E8 g, Q8 G
$debar_filed = array('catid','title','style','thumb','status','islink','description');
& g- G( R, A6 Z( B$ [* s, @ if(is_array($data)) {
2 {1 _% q ?0 R/ D; \$ i6 t' D foreach($data as $field=>$value) { $ Z$ w2 R" [% l% k6 q5 D
if($data['islink']==1 && !in_array($field,$debar_filed)) continue; ( l' ?* x- U/ O0 D4 K: R
$name = $this->fields[$field]['name'];
3 E/ N# R8 ]' U* |# K$ t4 Y, f. s $minlength = $this->fields[$field]['minlength']; 8 e1 Q8 e& h4 T$ N
$maxlength = $this->fields[$field]['maxlength'];
1 |: c: f3 K9 |9 G0 X $pattern = $this->fields[$field]['pattern'];
- M$ I4 f$ B/ Q, E $errortips = $this->fields[$field]['errortips']; & A7 L' K9 c! ^, ~5 A7 a5 L5 b# K
if(empty($errortips)) $errortips = "$name 不符合要求!";
7 t' m. p& | U+ h8 |# c5 i: t* ~3 ? $length = empty($value) ? 0 : strlen($value); 3 [$ ^$ s1 A, j7 ]/ D+ a- S: n
if($minlength && $length < $minlength && !$isimport) showmessage("$name 不得少于 $minlength 个字符!");
& y N- m1 ^. i6 A5 k* W6 a if($maxlength && $length > $maxlength && !$isimport) { 0 @( o4 S5 U! e p W1 N" \
showmessage("$name 不得超过 $maxlength 个字符!"); % C1 F5 d- r* h: H! m% ?
} else { 4 v, `7 z; X5 p% X. S* F6 T& Y1 h
str_cut($value, $maxlength); ) ^* Z( s! x ~2 @& K
}
' }8 D; S$ ^3 n if($pattern && $length && !preg_match($pattern, $value) && !$isimport) showmessage($errortips);
+ |9 C4 n* [5 Z$ p: Z, a1 [ if($this->fields[$field]['isunique'] && $this->db->get_one(array($field=>$value),$field) && ROUTE_A != 'edit') showmessage("$name 的值不得重复!"); 4 n) S8 l/ E9 l- _8 P8 k2 i* {3 k
$func = $this->fields[$field]['formtype']; 8 ^& F; G7 P: |
if(method_exists($this, $func)) $value = $this->$func($field, $value); ! B8 W) h) P$ k( }
$info[$field] = $value;
" w2 B, X2 H& p6 u, S& m }
+ Q8 l+ D U M; \0 p) a }
) b4 ~8 K8 Q3 M3 T2 y return $info; / I X0 s+ E2 m* w- f
}
& c! c- n0 v. D, S' y7 Ztrim_script函数是过滤XSS的,上面get函数一段代码干的事就是取提交上来的字段和值重新赋值到数组,( L! l- C Z. [) h% E: L3 D& K' d
, q; y% s( \! ?2 o+ @, |
再到phpcms\modules\member\index.php 文件account_manage_info函数( \9 H# [5 s+ J: k
过了get()函数之后。7 w @. O: P$ J5 Y: E1 n N
: v8 T9 W9 ^+ p9 h* @
( {9 a% W1 b' Y$modelinfo = $member_input->get($_POST['info']);
1 N4 D2 Y# y1 b2 a4 J# w% y t4 j $this->db->set_model($this->memberinfo['modelid']); * L' W+ V* i+ Q! L! ~; b& c5 f
$membermodelinfo = $this->db->get_one(array('userid'=>$this->memberinfo['userid']));
6 p7 o* Z6 v4 q6 k/ y if(!empty($membermodelinfo)) { 0 n* ^) k1 [4 c5 t1 m" p
$this->db->update($modelinfo, array('userid'=>$this->memberinfo['userid']));
Y; k4 D# G7 N3 y } else { " i5 L! v% C* H
直接带入数据库,update函数我们跟进看看
4 B: a7 a# u( {6 ?5 S6 ~& W$ j* `5 s/ f* V7 d! |- Z H G& a9 W
5 j) Q' ]* M' E' t6 l: o, e( \7 R: jpublic function update($data, $table, $where = '') {
( b, f! o/ q' ]0 k/ ? if($table == '' or $where == '') {
1 q+ x+ h3 e6 s$ N( {$ ` return false;
* ~* H* g1 F7 R }
+ N6 m- A/ p( N $where = ' WHERE '.$where;
* Q0 v9 `5 N- G& |! D2 W' V $field = ''; : t: q" \- N/ K2 v0 i. H
if(is_string($data) && $data != '') { & A! c' z& K1 M4 l8 }
$field = $data;
" |6 j: J0 ~/ U' ^; s. n: F' n6 f } elseif (is_array($data) && count($data) > 0) { 5 X" Y3 s4 Z2 v3 ~4 @! ?
$fields = array();
: w3 u4 a/ B ~& T0 } foreach($data as $k=>$v) {
6 G9 J- W3 c; z6 @- @ switch (substr($v, 0, 2)) { 5 t/ m! y( D! T5 r3 T. o7 X
case '+=':
( C U8 N; R$ ^$ Z $v = substr($v,2);
( S# a0 X3 V2 ?" C if (is_numeric($v)) { 0 s. y. [$ S. H% X# f z
$fields[] = $this->add_special_char($k).'='.$this->add_special_char($k).'+'.$this->escape_string($v, '', false); 3 K1 r2 p* P* U' ^4 n- V
} else { ; J1 L3 B' N2 X. u5 f8 m+ b
continue; - \: ~3 M1 e, D! ]
}
8 ~8 I, X0 s s. A: N& h/ s break; 6 }9 g% b' E$ f* R5 a0 I ^6 b
case '-=':
+ \. Q! n3 r# D/ k, Q $v = substr($v,2); ; ]( b, S6 a: F) M7 E$ b0 f4 T( [; j
if (is_numeric($v)) { ; ?% X+ N4 L0 o2 b. P" L
$fields[] = $this->add_special_char($k).'='.$this->add_special_char($k).'-'.$this->escape_string($v, '', false); ! H) s8 u8 F4 H: y7 g
} else {
( e1 w: Z4 m- t& G+ y continue; ) O. p$ d; A% |) ]
}
9 M7 U$ \! ]# h4 [2 p break; * y" i# f3 h: ?6 P2 D
default: ; ^; x. G$ M0 |: t- w$ I3 F: Z
$fields[] = $this->add_special_char($k).'='.$this->escape_string($v);
3 X# C+ D$ v) Q' M+ L L* v* ] }
1 G+ e9 Z5 q) [, t0 P4 j! S- _4 P } ( N! W5 v7 P* M4 V
$field = implode(',', $fields); # w: s0 A5 i3 b, K
} else {
& t) d# J7 }5 j' j return false; ; E4 V; v* Q6 {" Z4 g$ M7 Z
} - z% c+ _# z5 K
$sql = 'UPDATE `'.$this->config['database'].'`.`'.$table.'` SET '.$field.$where; : C: Z- t6 a ~0 v
print_r($sql); 7 {+ V; _& H' Y' F
return $this->execute($sql); 6 j: @! j0 u7 T5 h, Z) l
} # U; `% U5 |4 J0 Y& M6 o& M
从头到尾也是没有验证数据库是否存在数组中的字段,然后直接执行SQL语句。也就是说SQL语句中的字段我们可控,导致注入。
3 n$ L& s9 t2 O5 X" p: M8 B8 R* X- v
攻击测试:& P1 Y, T; z8 V; F$ q- f$ X
测试地址http://localhost! w) S+ d( R5 y5 a3 i* q9 c) ~; S g
注册会员seay并登陆。打开firebug工具HTML选项。修改birthday的name值为注入语句
/ t& g; l: ~) e. y) @& B; N4 w0 p4 \4 g' H9 Q3 S6 a) r( J
/ i. R$ H5 w9 {% n- {/ w9 {( f
- d( i- Q; ~6 M/ O
, O( H3 V" T5 s- b1 B# s: S, N0 I& n( c7 Y" u
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|