实验吧--web--你真的会php吗

---恢复内容开始---

实验吧的一道题php审计题。拉下来写一写。 

http://ctf5.shiyanbar.com/web/PHP/index.php

打开之后说have fun

那就抓包来看看吧

  

嗯...没啥收获,放在repeater里面看看

是这样的,根据response反馈的信息,我们可以看见 hint(提示)

那就打开它看看吧

 代码审计走一波。

<?php

$info = ""; 
$req = [];
$flag="xxxxxxxxxx";

ini_set("display_error", false); 
error_reporting(0); 


if(!isset($_POST['number'])){ //注意这里post请求  1.不能为空
   header("hint:6c525af4059b4fe7d8c33a.txt");  //文件头添加hint提示。

   die("have a fun!!"); // 直接就die了
}
foreach([$_POST] as $global_var) { //遍历数组
    foreach($global_var as $key => $value) { 
        $value = trim($value); //trim() 函数移除字符串两侧的空白字符或其他预定义字符。
        is_string($value) && $req[$key] = addslashes($value); 
    } 
} 
//global $var是外部$var的同名引用或者指针。
//函数
function is_palindrome_number($number) { 
    $number = strval($number); //本函数可将数组及类之外的变量类型转换成字符串类型。
    $i = 0; 
    $j = strlen($number) - 1;//strlen() 函数返回字符串的长度 
    while($i < $j) { 
        if($number[$i] !== $number[$j]) { 
            return false; 
        } 
        $i++; 
        $j--; 
    } 
    return true; 
} 

//判断是否为数值型
if(is_numeric($_REQUEST['number'])){

   $info="sorry, you cann't input a number!";

}elseif($req['number']!=strval(intval($req['number']))){

     $info = "number must be equal to it's integer!! ";  

}else{

     $value1 = intval($req["number"]);
     $value2 = intval(strrev($req["number"])); //strrev() 函数反转字符串。 

     if($value1!=$value2){
          $info="no, this is not a palindrome number!";
     }else{
          //判断回文数
          if(is_palindrome_number($req["number"])){
              $info = "nice! {$value1} is a palindrome number!"; 
          }else{
             $info=$flag;
          }
     }

}

echo $info;

如果要拿flag,需要满足以下条件:
1.不为空,且不能是一个数值型数字,包括小数。(由is_numeric函数判断)
2.不能是一个回文数。(is_palindrome_number判断)
3.该数的反转的整数值应该和它本身的整数值相等。即:
4.post个number.

原文地址:https://www.cnblogs.com/EEEE1/p/8074574.html