Code-Audit-Challenges-php-2

Code-Audit-Challenges-php-2

Challenge

<?php
show_source(__FILE__);
$flag = "xxxx";
if(isset($_GET['time'])){ 
        if(!is_numeric($_GET['time'])){ 
                echo 'The time must be number.'; 
        }else if($_GET['time'] < 60 * 60 * 24 * 30 * 2){ 
                        echo 'This time is too short.'; 
        }else if($_GET['time'] > 60 * 60 * 24 * 30 * 3){ 
                        echo 'This time is too long.'; 
        }else{ 
                sleep((int)$_GET['time']); 
                echo $flag; 
        } 
                echo '<hr>'; 
}
?>

Solution

Mind

  1. 第一个if条件要求:time为数字或数字型字符串
  2. 接下来if-else条件要求:60 * 60 * 24 * 30 * 3<time<60 * 60 * 24 * 30 * 2
  3. 绕过三个判定后会对time参数有一个sleep()延时函数,会等很久
  4. 因此考虑到是利用PHP的弱类型特性

Knowledge

  • is_numeric()-支持普通数字型字符串、科学记数法型字符串、部分支持十六进制0x型字符串
  • int()-不能正确转换的类型有十六进制型字符串、科学计数法型字符串(部分)
  • PHP进行比较操作时,对于0x开头的数字字符串会先转化成十进制再进行比较

Payload

  • ?time=0x5f1a00--十六进制解法
  • ?time=6e000000--科学记数法解法
posted @ 2017-09-25 00:37  v1ce0ye  阅读(507)  评论(1编辑  收藏  举报