你真的会PHP吗?

你真的会PHP吗?分值:30

  • 来源: 实验吧
  • 难度:中
  • 参与人数:7258人
  • Get Flag:1362人
  • 答题人数:1665人
  • 解题通过率:82%

 

你真的会PHP吗?

会?还是不会?

解题链接: http://ctf5.shiyanbar.com/web/PHP/index.php

 

1.看完源代码,没有有价值的信息,打开brup抓包会发现一个.txt,打开看一下

                                               

2.打开后发现是一个php程序,审计吧

<?php


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

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


if(!isset($_POST[‘number‘])){
   header("hint:6c525af4059b4fe7d8c33a.txt");

   die("have a fun!!"); 
}

foreach([$_POST] as $global_var) { 
    foreach($global_var as $key => $value) { 
        $value = trim($value); 
        is_string($value) && $req[$key] = addslashes($value); 
    } 
} 


function is_palindrome_number($number) { 
    $number = strval($number); 
    $i = 0; 
    $j = strlen($number) - 1; 
    while($i < $j) { 
        if($number[$i] !== $number[$j]) { 
            return false; 
        } 
        $i++; 
        $j--; 
    } 
    return true; 
} 


if(is_numeric($_REQUEST[‘number‘])){         /*is_numeric — 检测变量是否为数字或数字字符串*/
    
   $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"])); if($value1!=$value2){ $info="no, this is not a palindrome number!"; }/*该数的反转的整数值应该和它本身的整数值相等*/
else{ if(is_palindrome_number($req["number"])){                     /*palindrome number验证回文数字*/
$info = "nice! {$value1} is a palindrome number!"; }else{ $info=$flag; } } } echo $info; 



也许你会问什么是回文数字?直接给例子

Example 1:

Input: 121
Output: true

Example 2:

Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.

Example 3:

Input: 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.

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

intval($req[“number”])=intval(strrev($req[“number”]))

2,3看似矛盾,但可以利用空格或空字符串提交,如0200%00、0200%20,构造post提交

通过科学计数法构造:0e%00 满足条件1和条件3。继续构造0e-0%00(经测试,0e+0%00是不可以的)满足所有条件。