PHP

PHP strcmp函数漏洞

Posted by Waldo on February 22, 2018

strcmp函数的返回值

strcmp.jpg

首先贴上官方文档的说明

Note a difference between 5.2 and 5.3 versions echo (int)strcmp(‘pending’,array()); will output -1 in PHP 5.2.16 (probably in all versions prior 5.3) but will output 0 in PHP 5.3.3 Of course, you never need to use array as a parameter in string comparisions.

意思是:在php 5.2版本之前,利用strcmp函数将数组与字符串进行比较会返回-1,但是从5.3开始,会返回0

示例代码:

<?php
  error_reporting();
  $flag=$_GET['flag'];
  if(strcmp('Waldo_cuit',$flag)){
      echo 'NO!';
   }
  else{
      echo 'YES!';
  }
?>

当传入flag[]=1时,会导致 0 = strcmp('Waldo_cuit',$flag),也就是flase = strcmp('Waldo_cuit',$flag),显示出 Yes!。大家可以自行测试一下~~~ 在ctf里可以用这个漏洞绕过判断条件,这里附一道Bugku的题前女友