> 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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ninjia.gitbook.io/secskill/serve/php/strcmp.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
