Upload-labs(Pass11-12)

练习网站:upload-labs

Upload-labs(Pass11-12)_第1张图片

注意:

能运行

就能运行一句话木马

本文使用主要是为了简便

知识点

$_FILES[表单提交过来的name]

[name]:获取到的文件名

[type]: 获取到的文件类型(MIMETYPE)

[tmp_name]:文件临时存放的路径

[error]: 上传文件报错信息(为空则上传成功)

[size]:上传文件的大小

Move_uploaded_file(需要移动的文件,要移动到的位置)

Strrchr(指定字符串,匹配的字符) --指针指到指定的字符的位置,取之后的值

Trim() --去除字符串中的前后空格

Rtrim() --去除右空格

Ltrim() --去除左空格

Strtolower() --将字符串转为小写

Str_ireplace --(被转换的字符串,替换成的字符串,需要查找的字符串)

在需要查找的字符串中查找需要被替换的字符串,替换为指定的字符串

Pass-11

代码:

$is_upload = false;
$msg = null;
if (isset($_POST['submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        $deny_ext = array("php","php5","php4","php3","php2","html","htm","phtml","pht","jsp","jspa","jspx","jsw","jsv","jspf","jtml","asp","aspx","asa","asax","ascx","ashx","asmx","cer","swf","htaccess","ini");

        $file_name = trim($_FILES['upload_file']['name']);
        $file_name = str_ireplace($deny_ext,"", $file_name);
        $temp_file = $_FILES['upload_file']['tmp_name'];
        $img_path = UPLOAD_PATH.'/'.$file_name;        
        if (move_uploaded_file($temp_file, $img_path)) {
            $is_upload = true;
        } else {
            $msg = '上传出错!';
        }
    } else {
        $msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';
    }
}

提示:

截取文件后缀名与上面禁用的后缀名匹配,如果想同,转化为空

所有利用双写后缀名绕过

解题思路:

上传phpinfo.pphphp文件

上传成功后右键打开链接

Upload-labs(Pass11-12)_第2张图片

Pass-12

代码:

$is_upload = false;
$msg = null;
if(isset($_POST['submit'])){
    $ext_arr = array('jpg','png','gif');
    $file_ext = substr($_FILES['upload_file']['name'],strrpos($_FILES['upload_file']['name'],".")+1);
    if(in_array($file_ext,$ext_arr)){
        $temp_file = $_FILES['upload_file']['tmp_name'];
        $img_path = $_GET['save_path']."/".rand(10, 99).date("YmdHis").".".$file_ext;

        if(move_uploaded_file($temp_file,$img_path)){
            $is_upload = true;
        } else {
            $msg = '上传出错!';
        }
    } else{
        $msg = "只允许上传.jpg|.png|.gif类型文件!";
    }
}

 提示:

在处理数据时,当处理到00,就当作处理完成

PHP版本小于5.3

Magic_quotes_gpc=Off

解题思路:

上传phpinfo.jpg文件,用BP抓包修改数据

Upload-labs(Pass11-12)_第3张图片

上传成功后右键打开链接

Upload-labs(Pass11-12)_第4张图片

你可能感兴趣的:(WEB渗透,Upload文件上传漏洞,网络安全,php,开发语言,web安全)