PHP_Code_Challenge-16-科学计数&00截断ereg

题目

<?php
if (isset($_POST["submit"]))  
{
  if (isset($_POST['hihi']))
  {
    if (ereg("^[a-zA-Z0-9]+$", $_POST['hihi']) === FALSE)// 只能有数字字母,00截断?
    {
      exit('<script>alert("have fun:)")</script>');
    }
    elseif (strlen($_POST['hihi']) < 11 && $_POST['hihi'] > 999999999)//至多10位,要大于999999999[9位],科学计数法?
    {
      if (strpos($_POST['hihi'], '#HONG#') !== FALSE)
      {
        if (!is_array($_POST['hihi'])) {
        include("flag.php");
        echo "Congratulations! FLAG is : ".$flag;
        }
        else
      {
        exit('<script>alert("nonono")</script>');
      }
      }
      else
      {
        exit('<script>alert("nonono")</script>');
      }
    }
    else
    {
      exit('<script>alert("sorry")</script>');
    }
  }
}
show_source(__FILE__);
?>

分析

  1. if (ereg("^[a-zA-Z0-9]+$", $_POST['hihi']) === FALSE)
    只能有数字字母
  2. elseif (strlen($_POST['hihi']) < 11 && $_POST['hihi'] > 999999999)
    至多10位,要大于999999999[9位]
  3. if (strpos($_POST['hihi'], '#HONG#') !== FALSE)
    要有#HONG#
  4. 综合
    1+2=>用科学计数法,1e9=1000000000[10位]
    1+3=>ereg可被00截断,ereg识别1e9%00#HONG#%00就认为字符串已结束,前面的1e9符合正则

知识点

科学计数法

1e9=1000000000

ereg函数的两个注意点

在使用ereg过滤时,可使用00截断绕过和传数组绕过

可被%00截断

可被NULL字符截断,即%00截断,识别到%00则认为字符串结束

<?php
$_FILES["name"]="1.jpg%00.php";
if(ereg(".jpg$",$_FILES["name"]) === 1)
{
    echo "upload success!";
}

数组作参数返回NULL

只能处理字符串,遇到数组作参数返回NULL

<?php
//传数组,ereg返回NULL,!==False
if(ereg("admin$",$_POST["name"]) !== False)//当开发以为ereg只会返回true或false时
{
    echo "success!";
}

解法

submit=1&hihi=1e9%00#HONG#

原文地址:https://www.cnblogs.com/Rain99-/p/12726630.html