/

CVE-2012-20007

Severity:

CRITICAL RISK

(9.8)

Eval Injection (CWE-95) in ThinkPHP Dispatcher PATH_INFO

CVE-2012-20007

Received

Vulnerability type

Category:

Eval Injection

CWE:

CWE-95

Impact:

Remote Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

ThinkPHP's Dispatcher can evaluate attacker-controlled PHP expressions while parsing PATH_INFO because it uses preg_replace with the /e modifier and a double-quoted replacement. An unauthenticated attacker who can send a crafted request with a malicious s parameter may execute arbitrary code on the server.

Affected context

The vulnerability is described in ThinkPHP 2.0 through 2.2 and ThinkPHP 3.0 Lite mode, in Dispatcher PATH_INFO parsing. It becomes risky when the affected code processes attacker-controlled request parameters through the vulnerable preg_replace expression and the application endpoint is reachable.

Exploit preconditions

  • Attack surface: An HTTP endpoint running an affected ThinkPHP configuration
  • Required access: No authentication is required, according to the vulnerability description
  • Trigger point: Request handling in index.php when parsing the s parameter
  • Why exploitation is possible: The parsing expression evaluates a replacement containing attacker-controlled PHP expressions

Why this happens

The underlying bug is the use of preg_replace with the /e modifier and a double-quoted replacement in request parsing. This pattern evaluates the replacement as PHP code rather than treating input purely as data, mapping to CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code.

Potential impact

  • An attacker may execute arbitrary code with the privileges of the web server process.
  • The application and its accessible data could be compromised.
  • An attacker could modify application files or disrupt service.
  • If the web server has excessive permissions, compromise could extend to other resources in its environment.

General mitigation guidance

Defensive patterns include removing dynamic evaluation from request parsing and using ordinary string or routing operations instead. Treat request parameters as untrusted data, validate them against a narrow expected format, and avoid constructing executable expressions from user input. Where dynamic behavior is necessary, use constrained mappings and run the application with least-privilege permissions.

How teams detect issues like this

Review request-parsing code for preg_replace calls using the /e modifier, especially when replacement strings include request-derived values or double-quoted interpolation. Static analysis and code review can flag dynamic evaluation functions and data flows from HTTP parameters into executable contexts. Policy checks can prohibit deprecated evaluation patterns and require validation of externally supplied routing values.

Sources

SourceLink
web.archive.orgweb.archive.org/web/20140201221754/http://www.jb51.net:80/softjc/43550.html
github.comgithub.com/projectdiscovery/nuclei-templates/blob/main/http/vulnerabilities/thinkphp/thinkphp-2-rce.yaml
github.comgithub.com/vulhub/vulhub/tree/master/thinkphp/2-rce
vulncheck.comvulncheck.com/advisories/thinkphp-2-x-3.0-lite-unauthenticated-rce-via-dispatcher-path-info

Frequently asked

questions

Yes. The description indicates that an unauthenticated attacker can trigger it through a crafted HTTP request when an affected endpoint is exposed.

No authentication is described as necessary; network access to the vulnerable application endpoint is the key prerequisite.

Remove dynamic evaluation from request parsing and handle routing values as validated data using non-evaluating operations.

Prohibit evaluation-based string processing, validate request inputs against strict formats, and use static analysis and code review to identify flows from untrusted input into dynamic execution.

Find out what's already
exploitable in your codebase.