upload-labs第十七十八关

第十七关

php 复制代码
$is_upload = false;
$msg = null;

if(isset($_POST['submit'])){
    $ext_arr = array('jpg','png','gif');
    $file_name = $_FILES['upload_file']['name'];
    $temp_file = $_FILES['upload_file']['tmp_name'];
    $file_ext = substr($file_name,strrpos($file_name,".")+1);
    $upload_file = UPLOAD_PATH . '/' . $file_name;

    if(move_uploaded_file($temp_file, $upload_file)){
        if(in_array($file_ext,$ext_arr)){
             $img_path = UPLOAD_PATH . '/'. rand(10, 99).date("YmdHis").".".$file_ext;
             rename($upload_file, $img_path);
             $is_upload = true;
        }else{
            $msg = "只允许上传.jpg|.png|.gif类型文件!";
            unlink($upload_file);
        }
    }else{
        $msg = '上传出错!';
    }
}

由于这个是先上传在判断我们就可以使用木马让木马写文件

我们只需要不停的上传然后自己不停的访问

python 复制代码
import requests
url = 'http://127.0.0.1/upload/upload/1.php'
while True:
    print('running')
    html = requests.get(url)
    if html.status_code == 200:
        print('ok')
        break

先运行py脚本再上传(或者直接脚本上传),记得上传的时候抓一个包

这个是无限发送包

访问成功

上传完成

第十八关

php 复制代码
//index.php
$is_upload = false;
$msg = null;
if (isset($_POST['submit']))
{
    require_once("./myupload.php");
    $imgFileName =time();
    $u = new MyUpload($_FILES['upload_file']['name'], $_FILES['upload_file']['tmp_name'], $_FILES['upload_file']['size'],$imgFileName);
    $status_code = $u->upload(UPLOAD_PATH);
    switch ($status_code) {
        case 1:
            $is_upload = true;
            $img_path = $u->cls_upload_dir . $u->cls_file_rename_to;
            break;
        case 2:
            $msg = '文件已经被上传,但没有重命名。';
            break; 
        case -1:
            $msg = '这个文件不能上传到服务器的临时文件存储目录。';
            break; 
        case -2:
            $msg = '上传失败,上传目录不可写。';
            break; 
        case -3:
            $msg = '上传失败,无法上传该类型文件。';
            break; 
        case -4:
            $msg = '上传失败,上传的文件过大。';
            break; 
        case -5:
            $msg = '上传失败,服务器已经存在相同名称文件。';
            break; 
        case -6:
            $msg = '文件无法上传,文件不能复制到目标目录。';
            break;      
        default:
            $msg = '未知错误!';
            break;
    }
}

//myupload.php
class MyUpload{
......
......
...... 
  var $cls_arr_ext_accepted = array(
      ".doc", ".xls", ".txt", ".pdf", ".gif", ".jpg", ".zip", ".rar", ".7z",".ppt",
      ".html", ".xml", ".tiff", ".jpeg", ".png" );

......
......
......  
  /** upload()
   **
   ** Method to upload the file.
   ** This is the only method to call outside the class.
   ** @para String name of directory we upload to
   ** @returns void
  **/
  function upload( $dir ){
    
    $ret = $this->isUploadedFile();
    
    if( $ret != 1 ){
      return $this->resultUpload( $ret );
    }

    $ret = $this->setDir( $dir );
    if( $ret != 1 ){
      return $this->resultUpload( $ret );
    }

    $ret = $this->checkExtension();
    if( $ret != 1 ){
      return $this->resultUpload( $ret );
    }

    $ret = $this->checkSize();
    if( $ret != 1 ){
      return $this->resultUpload( $ret );    
    }
    
    // if flag to check if the file exists is set to 1
    
    if( $this->cls_file_exists == 1 ){
      
      $ret = $this->checkFileExists();
      if( $ret != 1 ){
        return $this->resultUpload( $ret );    
      }
    }

    // if we are here, we are ready to move the file to destination

    $ret = $this->move();
    if( $ret != 1 ){
      return $this->resultUpload( $ret );    
    }

    // check if we need to rename the file

    if( $this->cls_rename_file == 1 ){
      $ret = $this->renameFile();
      if( $ret != 1 ){
        return $this->resultUpload( $ret );    
      }
    }
    
    // if we are here, everything worked as planned :)

    return $this->resultUpload( "SUCCESS" );
  
  }
......
......
...... 
};

这一关有点麻烦,由于过滤无法上传php文件只能做图片马

可以直接修改后缀

我们需要一个网页写一个文件包含的漏洞

解析完成

成功

相关推荐
Coder个人博客3 分钟前
Linux6.19-ARM64 mm mmap子模块深入分析
大数据·linux·安全·车载系统·系统架构·系统安全·鸿蒙系统
Coder个人博客29 分钟前
Linux6.19-ARM64 mm hugetlbpage子模块深入分析
linux·安全·车载系统·系统架构·系统安全·鸿蒙系统·安全架构
hellojackjiang201131 分钟前
如何保障分布式IM聊天系统的消息可靠性(即消息不丢)
分布式·网络安全·架构·信息与通信
EverydayJoy^v^40 分钟前
RH134简单知识点——第11章—— 管理网络安全
linux·网络·web安全
ZeroNews内网穿透1 小时前
关于飞牛fnOS重要安全更新的提醒
运维·服务器·web安全·ssh
liux35281 小时前
Kafka 4.1.1 部署指南:单机版与安全认证配置
安全·kafka·linq
周某人姓周1 小时前
DOM型XSS案例
前端·安全·web安全·网络安全·xss
开开心心就好2 小时前
开源免费高速看图工具,支持漫画大图秒开
linux·运维·服务器·安全·ruby·symfony·1024程序员节
上海云盾第一敬业销售2 小时前
游戏盾在保障游戏安全方面的独特优势
网络·安全·游戏
Yff_world2 小时前
网络安全与 Web 基础笔记
前端·笔记·web安全