BUUOJ刷题记录


BUUOJ 刷题记录

[极客大挑战 2019]EasySQL

? 入门中的入门

? 在用户名的地方输入' or 1=1#(万能密码), 就能绕过去了


[HCTF 2018]WarmUp

进入后看源码, 发现提示去source.php看看, 跳转之后, 看到源码, 代码审计

<?php
    highlight_file(__FILE__);
    class emmm
    {
        public static function checkFile(&$page)
        {
            $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {
                echo "you can't see it";
                return false;
            }

            if (in_array($page, $whitelist)) {
                return true;
            }

            $_page = mb_substr(
                $page,
                0,
                mb_strpos($page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page);
            $_page = mb_substr(
                $_page,
                0,
                mb_strpos($_page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }
            echo "you can't see it";
            return false;
        }
    }

    if (! empty($_REQUEST['file'])
        && is_string($_REQUEST['file'])
        && emmm::checkFile($_REQUEST['file'])
    ) {
        include $_REQUEST['file'];
        exit;
    } else {
        echo "
"; } ?>

mb_substr

  • 用于获取部分字符串

  • mb_substr(
    string $str,
    int $start,
    int $length = NULL,
    string $encoding = mb_internal_encoding()
    )

    • $str: 目标字符串
    • $start: 起始位置 (正数从0开始, 负数则为倒数)
    • $length: 获取字符串的长度, 若未传入/传入为NULL则进行到字符串末尾
    • $encoding: 字符编码, 未传入则默认使用内部编码
mb_substr(
    string $str,
    int $start,
    int $length,
    string $encoding = mb_internal_encoding()
): string  // 返回字符串

mb_strpos

  • 查找一字符串在另一字符串中出现的位置
  • mb_strpos(
    string $haystack,
    string $needle,
    int $offset = 0,
    string $encoding = mb_internal_encoding()
    )
    • $haystack: 被检查的字符串
    • $needle: 所查找的字符串
    • $offset: 开始查找的位置 (正数从0开始, 负数从倒数开始)
    • $encoding: 字符编码, 未传入则默认使用内部编码
mb_strpos(
    string $haystack,
    string $needle,
    int $offset = 0,
    string $encoding = mb_internal_encoding()
): int	// 返回一个整数

解题过程

? 首先传入 file = hint.php, 获得提示

? 发现有include $_REQUEST['file'];, 尝试用伪协议读_ffffllllaaaagggg.php(没有 php )_, 然后就读到了 (待会儿再学学文件包含和伪协议)


[ACTF2020 新生赛]Include

? 进去看有一个tip的按钮, 点击之后跳转到flag.php, 尝试burp抓一下包

? ......一无所获

? 转了半天才意识到应该直接对flag.php进行处理, 这里便用到了伪协议读代码(打完这道题就去整理), 直接放payload

payload = ?file=php://filter/read=convert.base64-encode/resource=flag.php

? 得到base64编码后的源码, 再解密一下就得到flag


CTF