upload-labs_pass19_条件竞争+apache解析漏洞

pass19-源码和提示

在这里插入图片描述

提示:
在这里插入图片描述
源码:

//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" );
  
  }
......
......
...... 
};

包含了一个文件myupload.php

上传 的情况用switch语句写了:

1.正常
2.文件已经被上传,但没有重命名。
3.上传失败,上传目录不可写。
4.上传失败,无法上传该类型文件。
5.上传失败,上传的文件过大。
6.上传失败,服务器已经存在相同名称文件。
7.文件无法上传,文件不能复制到目标目录。
8.未知错误!

对于文件类型检查:
(白名单)
“.doc”, “.xls”, “.txt”, “.pdf”, “.gif”, “.jpg”, “.zip”, “.rar”, “.7z”,“.ppt”,
“.html”, “.xml”, “.tiff”, “.jpeg”, “.png”

看到名单中,除了图片类型的文件,还可以上传其他类型的。

pass19-思路

这一关有一个bug

首先建议大家修改一下这个bug再做题:
myupload.php

未修改前:
在这里插入图片描述

修改后:
在这里插入图片描述
保存

就是添加一个分界符

解题思路:

既然有白名单,是不是可以试试图片马呢?你可以试试,但是这么做,就是违背出题人的本意了。

正确的思路是:对于源代码中“文件已经被上传,但没有重命名”,在文件上传够快,还未被重命名的时候,去访问可能就来得及被连接webshell

如果上传的文件是shell.php.7z

正常情况下,会被重命名成9478374837.7z

但是如果服务器处理的不够快,没有来得及重命名,也就是仍然是shell.php.7z,会留下shell.php.7z这个文件,然后再结合一个apache的解析漏洞,只要文件名是shell.php.*,都会当作php代码来解析

可惜,理想很美好,但是现实很残酷,就是理论上可行的 措施,实际并没有办法复现出来。有空我会再加大线程的数量或者观察更加长的时间,来成功复现这一关。

就算上传shell.php.7z成功了,也未必能够连上webshell,因为不同的PHP版本要多次尝试效果。

这题要解决要有耐心和时间吧。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值