# CVE-2012-1823: PHP-CGI Query String Parameter

> Remote attackers can execute arbitrary code on PHP servers configured as CGI by injecting command-line options via query strings.

- **Severity:** Critical 9.8 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Yes, since 25 Mar 2022 (CISA KEV)
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 11 May 2012
- **Updated:** 4 Nov 2025
- **Also known as:** GHSA-3p37-hv77-x3rp, RHSA-2012:0546, RHSA-2012:0547, RHSA-2012:0568, RHSA-2012:0569, RHSA-2012:0570

## What is CVE-2012-1823?

CVE-2012-1823 is a critical command injection vulnerability in Apple Mac Os X, published on 11 May 2012. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official 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.

Weakness: CWE-77 (Improper Neutralization of Special Elements used in a Command)

## Which versions are affected by CVE-2012-1823?

It affects 17 products.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `php` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-bcmath` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-cli` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-common` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-dba` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-debuginfo` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-devel` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-gd` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-imap` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-ldap` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-mbstring` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-mysql` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-ncurses` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-odbc` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-pdo` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-pgsql` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-snmp` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-soap` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-xml` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php-xmlrpc` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.1.6-34.el5_8 |
| `php53` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-bcmath` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-cli` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-common` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-dba` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-debuginfo` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-devel` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-gd` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-imap` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-intl` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-ldap` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-mbstring` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-mysql` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-odbc` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-pdo` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-pgsql` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-process` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-pspell` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-snmp` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |
| `php53-soap` | Red Hat:enterprise_linux:5::client_workstation | All versions | 0:5.3.3-7.el5_8 |

Products: Apple Mac Os X, Debian Debian Linux, Fedoraproject Fedora, Hp Hp-Ux, Opensuse Opensuse, Php Php, Redhat Application Stack, Redhat Enterprise Linux Desktop, Redhat Enterprise Linux Eus, Redhat Enterprise Linux Server, Redhat Enterprise Linux Server Aus, Redhat Enterprise Linux Workstation, Redhat Gluster Storage Server for On-Premise, Redhat Storage, Redhat Storage for Public Cloud, Suse Linux Enterprise Server, Suse Linux Enterprise Software Development Kit.

## How do I fix CVE-2012-1823?

Upgrade to a fixed version. US federal agencies must fix it by 15 Apr 2022.

## Is CVE-2012-1823 being exploited?

Yes. Attackers have exploited CVE-2012-1823 in the wild since at least 25 Mar 2022.

Public exploit code:

- PHP CGI Argument Injection. (github_poc): https://github.com/0xl0k1/CVE-2012-1823
- PHP-CGI-REMOTE_CVE-2012-1823, UnrealIRCd, MySQL, PostgreSQL and SSH bruteforce, VSFTPD2.3.4, samba CVE-2007-2447, JAVA RMI Server, distcc daemon, misconfigured NFS files, etc. (github_poc): https://github.com/Unix13/metasploitable2
- First script, pgp-cgi-cve-2012-1823 BASH script (github_poc): https://github.com/tardummy01/oscp_scripts-1
- Exploited a known RCE vulnerability (PHP-CGI Argument Injection, CVE-2012-1823) on Metasploitable2 using Metasploit Framework, gained a shell, and documented post-exploitation (github_poc): https://github.com/mujtaba815/metasploitable2-php-cgi-exploit
- https://github.com/drone789/CVE-2012-1823 (github_poc): https://github.com/drone789/CVE-2012-1823
- https://github.com/cyberharsh/PHP_CVE-2012-1823 (github_poc): https://github.com/cyberharsh/PHP_CVE-2012-1823

## Other vulnerabilities in Apple Mac Os X

- [CVE-2014-7169](https://insights.sbomify.com/CVE-2014-7169/): GNU Bourne-Again Shell (Bash) Arbitrary Code Execution (critical 9.8, exploited in the wild)
- [CVE-2014-6271](https://insights.sbomify.com/CVE-2014-6271/): GNU Bourne-Again Shell (Bash) Arbitrary Code Execution (critical 9.8, exploited in the wild)
- [CVE-2021-30713](https://insights.sbomify.com/CVE-2021-30713/): Apple macOS Unspecified (high 7.8, exploited in the wild)
- [CVE-2019-8526](https://insights.sbomify.com/CVE-2019-8526/): Apple macOS Use-After-Free (high 7.8, exploited in the wild)
- [CVE-2015-1130](https://insights.sbomify.com/CVE-2015-1130/): Apple OS X Authentication Bypass (high 7.8, exploited in the wild)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2012-1823 and fix it if it is affected.

What it is: CVE-2012-1823 is a critical command injection vulnerability in Apple Mac Os X, published on 11 May 2012. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: Yes. Attackers have exploited CVE-2012-1823 in the wild since at least 25 Mar 2022.

Affected product: Apple Mac Os X. No package-level version data is available, so check the vendor advisory linked from the reference page.

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2012-1823/ (Markdown: https://insights.sbomify.com/CVE-2012-1823/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2012-1823
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2012-1823
- OSV: https://osv.dev/vulnerability/CVE-2012-1823

---
From sbomify Insights: https://insights.sbomify.com/CVE-2012-1823/
Summaries are generated and may contain mistakes; the official description above is the record.
