{"vuln_id":"GHSA-3qgc-jrrr-25jv","aliases":["CVE-2024-4577","CVE-2012-1823"],"description":"PHP RCE: A Bypass of CVE-2012-1823, Argument Injection in PHP-CGI","published_at":"2024-09-28T17:37:20Z","modified_at":"2024-09-28T17:37:20Z","first_seen_at":"2026-11-22T14:05:37.625430Z","severity":"high","severity_source":"ghsa","cvss_score":null,"cvss_vector":null,"cwe":["CWE-20"],"vendor":null,"product":null,"kev":{"is_kev":false,"date_added":null,"due_date":null,"ransomware":false},"epss":null,"epss_percentile":null,"nvd_status":null,"enriched_at":null,"links":{"nvd":"https://github.com/advisories/GHSA-3qgc-jrrr-25jv"},"matched_alias":null,"items":[{"id":12667,"source":{"id":"gh-php-src","name":"PHP releases (GitHub php/php-src tags)"},"title":"GHSA-3qgc-jrrr-25jv / CVE-2024-4577: PHP RCE: A Bypass of CVE-2012-1823, Argument Injection in PHP-CGI","summary":"PHP RCE: A Bypass of CVE-2012-1823, Argument Injection in PHP-CGI\n\nHi, \r\n\r\nI 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.\r\n\r\nThis 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.\r\n\r\nPlease let me know if you have any questions, thanks!\r\n\r\n\r\n# Impact\r\n\r\nAn attacker can execute arbitrary PHP code on the remote server. This vulnerability affects the PHP built with Windows.\r\n\r\n\r\n\r\n\r\n# Details\r\n\r\nThe 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:\r\n\r\n***# Path: sapi/cgi/cgi_main.c:1801** https://github.com/php/php-src/blob/php-8.0.30/sapi/cgi/cgi_main.c#L1801*\r\n\r\n```c\r\n/* {{{ main */\r\nint main(int argc, char *argv[])\r\n{\r\n\tint free_query_string = 0;\r\n\tint exit_status = SUCCESS;\r\n\tint cgi = 0, c, i;\r\n\tsize_t len;\r\n\tzend_file_handle file_handle;\r\n\tchar *s;\r\n    \r\n\t// ...\r\n    \r\n\t// [1] this is the patch of CVE-2012-1823\r\n\tif((query_string = getenv(\"QUERY_STRING\")) != NULL && strchr(query_string, '=') == NULL) {\r\n\t\t/* we've got query string that has no = - apache CGI will pass it to command line */\r\n\t\tunsigned char *p;\r\n\t\tdecoded_query_string = strdup(query_string);\r\n\t\tphp_url_decode(decoded_query_string, strlen(decoded_query_string));\r\n\t\tfor (p = (unsigned char *)decoded_query_string; *p &&  *p <= ' '; p++) {\r\n\t\t\t/* skip all leading spaces */\r\n\t\t}\r\n\t\tif(*p == '-') {\r\n\t\t\tskip_getopt = 1;\r\n\t\t}\r\n\t\tfree(decoded_query_string);\r\n\t}\r\n    \r\n\twhile (!skip_getopt && (c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {\r\n\t\tswitch (c) {\r\n\t\t\t// process the arguments\r\n        }\r\n        \r\n    }\r\n```\r\n\r\nThis 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!\r\n\r\nThis 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.\r\n\r\nThe 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. \r\n\r\nThe description and specification can be found here:\r\n* [WindowsBestFit/readme.txt](https://ww\nPatched:  8.3.8,  8.2.20,  8.1.29","url":"https://github.com/php/php-src/security/advisories/GHSA-3qgc-jrrr-25jv","published_at":"2024-09-28T17:37:20Z","updated_at":"2024-09-28T17:37:20Z","fetched_at":"2026-11-22T14:05:37.431197Z","severity":"critical","cvss_score":9.8,"epss":0.99999,"is_kev":true,"has_exploit":true,"kev_due_date":"2022-04-15","vendor":"php","product":"php-src","vuln_id":"CVE-2024-4577","vuln_ids":["CVE-2012-1823","CVE-2024-4577","GHSA-3QGC-JRRR-25JV"],"tags":["repo-advisory","CWE-20","security","repo:php/php-src","stack"],"cluster_id":11775,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/12667","html":"https://vulnwatch.ve1ve2.com/item/12667"}}]}