【CTF】php反序列化(一文入门) 您所在的位置:网站首页 sunny啥意思 【CTF】php反序列化(一文入门)

【CTF】php反序列化(一文入门)

#【CTF】php反序列化(一文入门)| 来源: 网络整理| 查看: 265

PHP相关学习

#Author:SunnyDog

#Date:23-3-18

#考研er忙里抽闲也得学~

#已对一些错别字、md编辑器造成的错误进行了修改,对文中各部分有疑问欢迎探讨~

文章目录 PHP相关学习一、php.ini中的auto_append_file和auto_prepend_file测试: 二、.htaccess和.user.ini后门.htaccess后门.user.ini后门 三、php序列化与反序列化php序列化php反序列化魔术方法构造函数与析构函数__sleep()方法__wakeup()方法__toString()方法__invoke()方法属性重载 四、php反序列化漏洞原理:LAB: 五、php反序列化pop链[强网杯2021]赌徒(pop链构造) 参考链接

一、php.ini中的auto_append_file和auto_prepend_file

include_path: 当使用函数include()、require()、fopen_with_path()等函数来寻找文件时,在没设置include_path的情况下,这些函数打开文件时默认是以web的根目录去寻找。当配置了include_path()后,这些php函数就会先在指定的include_path目录下面去搜索寻找。

auto_prepend_file: 指定在主文件之前自动解析的文件的名称。该文件就如同调用了require()或include()函数一样被包含了进来,因此使用了include_path。特殊值none禁用自动前缀。

auto_append_file: 指定在主文件之后自动解析的文件的名称。该文件同样是如同调用了require()或include()h函数一样被包含,因此使用了include_path.特殊值none禁止了自动后缀。

测试:

首先使用phpinfo()了解一下我的php.ini的位置

image-20230318180056091

此时我写了三个程序

# index.php 内,因此我们无法直接查看到页面的源码,那么进行进一步操作。尝试将访问这个文件的包发送到Repeater模块中进行测试,发现也只是回显了200,无法查看内容

利用文件备份

一般,当开发者在编写文件时,在linux系统中,为了方便备份,一般开发者会选择直接使用指令cp index.php index.php~来对文件进行备份。

为什么要使用“~”作为后缀呢,因为它是ASCii表中最高位的可打印字符,当使用这种形式的命名方式时,该备份文件永远会跟在源文件的后面

此处我们也尝试使用这样的形式来访问CustomTemplate.php文件,由此可以成功获得该源码

image-20230318234436562

# CustomTemplate.php $this->template_file_path = $template_file_path; $this->lock_file_path = $template_file_path . ".lock"; } private function isTemplateLocked() { return file_exists($this->lock_file_path); } public function getTemplate() { return file_get_contents($this->template_file_path); } public function saveTemplate($template) { if (!isTemplateLocked()) { if (file_put_contents($this->lock_file_path, "") === false) { throw new Exception("Could not write to " . $this->lock_file_path); } if (file_put_contents($this->template_file_path, $template) === false) { throw new Exception("Could not write to " . $this->template_file_path); } } } function __destruct() { // Carlos thought this would be a good idea if (file_exists($this->lock_file_path)) { unlink($this->lock_file_path); } } } ?>

题目对我们的要求,就是要我们删除从 Carlos 的主目录中删除“morale.txt”文件,因此可以注意到析构函数__destruct()中存在unlink()函数,可以帮助我们达到这一目的。并且,删除的lock_file_path变量就是在构造函数中对应赋值的,因此可以考虑利用。

此处介绍一下unlink()函数

unlink(filename, context) # filename:必须。规定要删除的文件 # context:可选。规定文件句柄的环境。

直接根据构造函数的结构构造脚本来得到payload:



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有