{"vuln_id":"CVE-2012-1823","aliases":[],"description":"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.","published_at":"2012-05-11T10:15:48.043000Z","modified_at":"2026-06-16T23:40:22.147000Z","first_seen_at":"2026-11-22T14:05:37.625872Z","severity":"critical","severity_source":"nvd","cvss_score":9.8,"cvss_vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","cwe":["CWE-77","CWE-20"],"vendor":"PHP","product":"PHP","kev":{"is_kev":true,"date_added":"2022-03-25","due_date":"2022-04-15","ransomware":false},"epss":0.99999,"epss_percentile":0.99996,"nvd_status":"Analyzed","enriched_at":"2026-11-22T14:20:40.221027Z","links":{"nvd":"https://nvd.nist.gov/vuln/detail/CVE-2012-1823"},"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"}},{"id":13545,"source":{"id":"cisa-kev","name":"CISA Known Exploited Vulnerabilities"},"title":"CVE-2024-4577 added to KEV: PHP-CGI OS Command Injection Vulnerability","summary":"PHP, specifically Windows-based PHP used in CGI mode, contains an OS command injection vulnerability that allows for arbitrary code execution. This vulnerability is a patch bypass for CVE-2012-1823.\nRequired action: Apply mitigations per vendor instructions or discontinue use of the product if mitigations are unavailable.\nDue date: 2024-07-03\nKnown ransomware campaign use","url":"https://cisa.gov/known_exploited_vulnerabilities_catalog?search_api_fulltext=CVE-2024-4577","published_at":"2024-06-12T00:00:00Z","updated_at":null,"fetched_at":"2026-11-22T19:20:09.656241Z","severity":"critical","cvss_score":9.8,"epss":0.99999,"is_kev":true,"has_exploit":true,"kev_due_date":"2022-04-15","vendor":"PHP Group","product":"PHP","vuln_id":"CVE-2024-4577","vuln_ids":["CVE-2012-1823","CVE-2024-4577","GHSA-3QGC-JRRR-25JV"],"tags":["kev","ransomware"],"cluster_id":385,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/13545","html":"https://vulnwatch.ve1ve2.com/item/13545"}},{"id":14152,"source":{"id":"cisa-kev","name":"CISA Known Exploited Vulnerabilities"},"title":"CVE-2012-1823 added to KEV: PHP-CGI Query String Parameter Vulnerability","summary":"sapi/cgi/cgi_main.c in PHP, when configured as a CGI script, does not properly handle query strings, which allows remote attackers to execute arbitrary code.\nRequired action: Apply updates per vendor instructions.\nDue date: 2022-04-15","url":"https://cisa.gov/known_exploited_vulnerabilities_catalog?search_api_fulltext=CVE-2012-1823","published_at":"2022-03-25T00:00:00Z","updated_at":null,"fetched_at":"2026-11-22T19:20:09.656747Z","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","vuln_id":"CVE-2012-1823","vuln_ids":["CVE-2012-1823"],"tags":["kev"],"cluster_id":11776,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/14152","html":"https://vulnwatch.ve1ve2.com/item/14152"}}]}