VulnWatch by ve1ve2
critical 9.8 KEVEXPLOITEPSS 100.0%

GHSA-3qgc-jrrr-25jv / CVE-2024-4577: PHP RCE: A Bypass of CVE-2012-1823, Argument Injection in PHP-CGI

Source:
PHP releases (GitHub php/php-src tags)
Published:
Fetched:
Updated:
Affects:
php php-src
KEV due:
2022-04-15

https://github.com/php/php-src/security/advisories/GHSA-3qgc-jrrr-25jv ↗

repo-advisoryCWE-20securityrepo:php/php-srcstack

PHP RCE: A Bypass of CVE-2012-1823, Argument Injection in PHP-CGI Hi, I am Orange Tsai from DEVCORE Research Team. We recently found a vulnerability on PHP. We have reproduced the issues in the latest version of PHP 8.3.6 and would like to report it to you. Please check the attached document for details. This advisory is in accordance with our vulnerability disclosure policy, which will be publicly disclosed after 90 days. Our aim is to ensure that vulnerabilities can be patched in a timely manner. Although it’s not a hard deadline, we still hope you can fix this vulnerability before August 04, 2024. Please let me know if you have any questions, thanks! # Impact An attacker can execute arbitrary PHP code on the remote server. This vulnerability affects the PHP built with Windows. # Details The PHP-CGI which configured under Apache HTTP Server accepts the command-line arguments by default. This behavior was prove to vulnerable, and tracked as [CVE-2012-1823](https://bugs.php.net/bug.php?id=61910) before. The PHP published the following code to patch the vulnerability: ***# Path: sapi/cgi/cgi_main.c:1801** https://github.com/php/php-src/blob/php-8.0.30/sapi/cgi/cgi_main.c#L1801* ```c /* {{{ main */ int main(int argc, char *argv[]) { int free_query_string = 0; int exit_status = SUCCESS; int cgi = 0, c, i; size_t len; zend_file_handle file_handle; char *s; // ... // [1] this is the patch of CVE-2012-1823 if((query_string = getenv("QUERY_STRING")) != NULL && strchr(query_string, '=') == NULL) { /* we've got query string that has no = - apache CGI will pass it to command line */ unsigned char *p; decoded_query_string = strdup(query_string); php_url_decode(decoded_query_string, strlen(decoded_query_string)); for (p = (unsigned char *)decoded_query_string; *p && *p <= ' '; p++) { /* skip all leading spaces */ } if(*p == '-') { skip_getopt = 1; } free(decoded_query_string); } while (!skip_getopt && (c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { switch (c) { // process the arguments } } ``` This argument `argv` is based on the `QUERY_STRING`, and the patch checks for no leading hyphen on the `QUERY_STRING` to ensure there are no dangerous arguments. However, if the binding between `argv` and `QUERY_STRING` is broken, the vulnerability of PHP-CGI Argument Injection would reappear! This patch will fail under the Windows system. Internally, Windows uses UCS-2 as its character set. Any characters passed to the ANSI Win32 API (such as `GetCommandLineA`), especially those with code point greater than 0x80, will be mapped to the corresponding UCS-2 code points by the current code page. The Windows internal also introduces a "Best-Fit" feature that replace the character if there is a more suitable character to display in the destination code page. The description and specification can be found here: * [WindowsBestFit/readme.txt](https://ww Patched: 8.3.8, 8.2.20, 8.1.29

Linked vulnerabilities (3)

CVE-2024-4577 critical 9.8 KEVEPSS 100.0% (p100) NVDCVE.orgGHSA
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

PHP RCE: A Bypass of CVE-2012-1823, Argument Injection in PHP-CGI

CWE: CWE-20, CWE-78KEV added 2024-06-12, due 2024-07-03, ransomwareAliases: GHSA-3qgc-jrrr-25jv, CVE-2012-1823NVD: Analyzed

PHP RCE: A Bypass of CVE-2012-1823, Argument Injection in PHP-CGI

CWE: CWE-20Aliases: CVE-2024-4577, CVE-2012-1823
CVE-2012-1823 critical 9.8 KEVEPSS 100.0% (p100) NVDCVE.org
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

sapi/cgi/cgi_main.c in PHP before 5.3.12 and 5.4.x before 5.4.2, when configured as a CGI script (aka php-cgi), does not properly handle query strings that lack an = (equals sign) character, which allows remote attackers to execute arbitrary code by placing command-line options in the query string, related to lack of skipping a certain php_getopt for the 'd' case.

CWE: CWE-77, CWE-20KEV added 2022-03-25, due 2022-04-15NVD: Analyzed