前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Writeup-北邮新生赛MRCTF-Web题:ez_bypass

Writeup-北邮新生赛MRCTF-Web题:ez_bypass

作者头像
Y5neKO
发布2022-01-13 12:48:35
8040
发布2022-01-13 12:48:35
举报
文章被收录于专栏:Y5neKO博客

原题地址:https://merak-ctf.site/challenges#ez_bypass

首先从题目可以看出:easy_bypass,简单的绕过 我们打开题目地址,简单的展示了源码的一部分

代码语言:javascript
复制
I put something in F12 for you include 'flag.php'; $flag='MRCTF{xxxxxxxxxxxxxxxxxxxxxxxxx}'; if(isset($_GET['gg'])&&isset($_GET['id'])) { $id=$_GET['id']; $gg=$_GET['gg']; if (md5($id) === md5($gg) && $id !== $gg) { echo 'You got the first step'; if(isset($_POST['passwd'])) { $passwd=$_POST['passwd']; if (!is_numeric($passwd)) { if($passwd==1234567) { echo 'Good Job!'; highlight_file('flag.php'); die('By Retr_0'); } else { echo "can you think twice??"; } } else{ echo 'You can not get it !'; } } else{ die('only one way to get the flag'); } } else { echo "You are not a real hacker!"; } } else{ die('Please input first'); } }Please input first

我们将其格式化方便观察

代码语言:javascript
复制
I put something in F12 for you
include 'flag.php';
$flag='MRCTF{xxxxxxxxxxxxxxxxxxxxxxxxx}';
if(isset($_GET['gg'])&&isset($_GET['id'])) {
    $id=$_GET['id'];
    $gg=$_GET['gg'];
    if (md5($id) === md5($gg) && $id !== $gg) {
        echo 'You got the first step';
        if(isset($_POST['passwd'])) {
            $passwd=$_POST['passwd'];
            if (!is_numeric($passwd))
            {
                 if($passwd==1234567)
                 {
                     echo 'Good Job!';
                     highlight_file('flag.php');
                     die('By Retr_0');
                 }
                 else
                 {
                     echo "can you think twice??";
                 }
            }
            else{
                echo 'You can not get it !';
            }

        }
        else{
            die('only one way to get the flag');
        }
}
    else {
        echo "You are not a real hacker!";
    }
}
else{
    die('Please input first');
}
}Please input first

很明显的看出是几层if语句套娃,只要一层一层解开,就会由最中间的highlight函数展示出flag 首先我们看第一层:

代码语言:javascript
复制
if(isset($_GET['gg'])&&isset($_GET['id']))

isset检测参数的存在,若两个条件都满足则执行if内代码,否则执行die('Please input first');,这一步我们只需要简单的提交gg和id两个get参数即可,提交后返回的代码发生了改变

代码语言:javascript
复制
I put something in F12 for you
include 'flag.php';
$flag='MRCTF{xxxxxxxxxxxxxxxxxxxxxxxxx}';
if(isset($_GET['gg'])&&isset($_GET['id'])) {
    $id=$_GET['id'];
    $gg=$_GET['gg'];
    if (md5($id) === md5($gg) && $id !== $gg) {
        echo 'You got the first step';
        if(isset($_POST['passwd'])) {
            $passwd=$_POST['passwd'];
            if (!is_numeric($passwd))
            {
                 if($passwd==1234567)
                 {
                     echo 'Good Job!';
                     highlight_file('flag.php');
                     die('By Retr_0');
                 }
                 else
                 {
                     echo "can you think twice??";
                 }
            }
            else{
                echo 'You can not get it !';
            }

        }
        else{
            die('only one way to get the flag');
        }
}
    else {
        echo "You are not a real hacker!";
    }
}
else{
    die('Please input first');
}
}You are not a real hacker!

证明绕过了第一层,接下来解决第二层中间将gg和id的值赋给了变量gg和id第二层的判断条件为

代码语言:javascript
复制
if (md5($id) === md5($gg) && $id !== $gg)

这段语句需要同时满足两个条件,首先第一个条件md5(id) === md5(gg),需要id和gg的MD5值“全等”(“===”表示数值和类型完全相同),本来随便提交两个相同的值即可,但是同时还需满足第二个条件id !== gg,这个条件中的“!==”表示“不全等”(值相同但类型不同),故第一个条件的方法无法使用,这时候我们需要利用md5函数本身的特性,传递两个值不同但无法用来比较的数据类型,这里可以通过数组也就是gg[]和id[]来绕过,于是我们通过get提交?gg[]=1&id[]=2如图,虽然这里报错了,不过不影响,成功绕过第二层解决,接下来解决第三层和第四层中间将POST参数passwd的值赋给了变量

代码语言:javascript
复制
if (!is_numeric($passwd))

第四层的判断条件为

代码语言:javascript
复制
if($passwd==1234567)

其中的is_numeric函数的作用是检测变量是否为数字或数字字符串,是则返回ture,反之。不过要注意的是if语句条件中的“!”,if判断语句是通过判断括号内的值是否为0来决定是否执行下面的语句

打个比方,假设a=0,如果if(a)成立执行if里的语句,那么if(!a)不成立不执行if里的语句

条件$passwd==1234567需要变量$passwd的值等于1234567,但不需要全等(参考第一层)

综上,我们需要通过POST提交一段使$passwd不为数字或数字字符串的值

用hackbar通过POST提交$passwd=1234567+任意字符即可

flag:

代码语言:javascript
复制
MRCTF{f684b6ef-e9e4-4cab-b250-a522b7c6a3f0}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020年03月29日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档