phar反序列化实施远程代码攻击
0X01 前言
记录一道CISCN的真题,让我对phar反序列化有更深层次的理解和应用,也对代码审计有了新的感悟,知道了在不使用php函数unserialize()同样引起PHP对象注入
参考链接:
https://xz.aliyun.com/t/2715
https://www.cnblogs.com/kevinbruce656/p/11316070.html
0X02 正文
首先这道题让我们注册,成功注册后发现是一个文件上传页面
这里上传一句话jpg后没有路径,也没有任何信息,dirb扫描路径也是无果,无奈之下我删除了一些文件,同样也下载了文件,但当我抓下载包的时候发现:
我们能不能远程下载服务器文件呢?试了一下,可以成功下载index.php、download.php和class.php以及delete.php其中前三者都是抓包能够得到有这三个PHP文件存在,对应着三种功能,而class.php则是被include()进去的,因此同样下载了过来。
现在附上完整源码:
index.php:
<?php
include "class.php";
$a = new FileList($_SESSION['sandbox']);
$a->Name();
$a->Size();
?>//省略了无关的html页面代码
download.php:
<?php
session_start();
if (!isset($_SESSION['login'])) {
header("Location: login.php");
die();
}
if (!isset($_POST['filename'])) {
die();
}
include "class.php";
ini_set("open_basedir", getcwd() . ":/etc:/tmp");
chdir($_SESSION['sandbox']);
$file = new File();
$filename = (string) $_POST['filename'];
if (strlen($filename) < 40 && $file->open($filename) && stristr($filename, "flag") === false) {
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=" . basename($filename));
echo $file->close();
} else {
echo "File not exist";
}
?>
delete.php:
<?php
session_start();
if (!isset($_SESSION['login'])) {
header("Location: login.php");
die();
}
if (!isset($_POST['filename'])) {
die();
}
include "class.php";
chdir($_SESSION['sandbox']);
$file = new File();
$filename = (string) $_POST[

本文深入探讨PHAR反序列化攻击,展示如何利用PHP的PHAR文件特性结合魔术方法__call和file_get_contents实现远程代码执行,获取服务器敏感信息。
最低0.47元/天 解锁文章
504

被折叠的 条评论
为什么被折叠?



