Introduction
A single unauthenticated GET request to index.php is enough to run arbitrary PHP on a server built with older ThinkPHP, and the Shadowserver Foundation observed exploitation in the wild as early as October 14, 2023. If you still run ThinkPHP 2.x applications, or 3.0 in Lite mode, that request path leads straight from the URL parser to eval().
ThinkPHP is a free, open source, lightweight PHP framework developed by TopThink and published under the Apache 2 license, intended for agile web and enterprise application development. It is widely embedded into custom Chinese-language web applications, which is one reason exposed instances often carry no visible version banner. That bundling makes behavioral testing, rather than version fingerprinting, the reliable way to find affected hosts.
Technical Information
The vulnerability is an eval injection (CWE-95) in the ThinkPHP Dispatcher. When the framework parses the request route, it splits the leftover PATH_INFO segments into key/value pairs using preg_replace with PHP's /e (eval) modifier and a double-quoted replacement string. Vulhub's write-up documents the vulnerable 2.x line:
$res = preg_replace('@(\w+)'.$depr.'([^'.$depr.'\/]+)@e', '$var[\'\\1\']="\\2";', implode($depr,$paths));
With the /e modifier, PHP substitutes the captured backreferences into the replacement string and then calls eval() on the result. The value capture \2 lands inside double quotes, and PHP interpolates variables in double-quoted strings, including the ${...} complex-variable syntax. So a path segment such as ${@phpinfo()} is treated as an expression and evaluated while the assignment statement is being built. The @ prefix suppresses any PHP errors, so the probe stays quiet.
According to Vulhub, ThinkPHP 3.0 in Lite mode never received the standard-mode hardening, so the same vulnerable pattern persists there and 3.0 Lite is in scope.
Attack flow
- The attacker locates a ThinkPHP 2.x or 3.0 Lite application reachable at
index.php. - They issue a single unauthenticated GET request where the
sparameter carries a PATH_INFO-style route, for example/index/index/name/${@phpinfo()}. - The Dispatcher runs its
preg_replacewith the/emodifier over the route segments. - The
${@phpinfo()}value is interpolated inside the double-quoted replacement and evaluated as PHP, executing on the server. - Replacing
${@phpinfo()}with an expression such as${@eval(...)}or a command-execution function yields full remote code execution. No authentication is required.
Proof of Concept
A working, publicly available proof of concept exists. Vulhub provides a reproducible Docker environment running a ThinkPHP 2.1 demo app, reachable at http://your-ip:8080/Index/Index. Exploitation is a single unauthenticated GET request that injects PHP into a URL path segment:
http://your-ip:8080/index.php?s=/index/index/name/${@phpinfo()}
Visiting this URL causes phpinfo() to execute on the target, which confirms code execution. The ${@...} construct abuses PHP's complex-variable syntax inside the double-quoted replacement so the enclosed expression is evaluated.
ProjectDiscovery ships the thinkphp-2-rce.yaml Nuclei template (severity: critical, CWE-95), which sends the URL-encoded equivalent of the same payload and confirms execution by matching phpinfo() output:
http: - method: GET path: - "{{BaseURL}}/index.php?s=/index/index/name/$%7B@phpinfo()%7D" matchers-condition: and matchers: - type: word words: - "PHP Extension" - "PHP Version" - "ThinkPHP" condition: and - type: status status: - 200
The probe still executes code on the target, even if only phpinfo(), so run it only against systems you are authorized to test.
Patch Information
There was never a clean, versioned security release for the 2.x line. The fix arrived in two stages.
Stage 1: the April 2012 hotfix (SVN r2838). A report dated 20 April 2012 told users to install the official patch, published as revision 2838 on the old Google Code project. As a manual alternative, it said to edit /trunk/ThinkPHP/Lib/Core/Dispatcher.class.php and change the double quotes in the second argument of preg_replace to single quotes, so the PHP variable syntax inside them is no longer parsed and executed. Google Code has shut down, so the r2838 diff cannot be checked directly, and the 'fixed' line in that blog post has unbalanced quotes and should not be copied as-is.
The upstream form of the fix can be verified in the 3.1.3 tree, whose ThinkPHP/Lib/Core/Dispatcher.class.php reads:
preg_replace('@(\w+)\/([^\/]+)@e', '$var[\'\\1\']=strip_tags(\'\\2\');', implode('/',$paths));
Two things changed. The captured value now sits inside a single-quoted PHP literal, so ${...} stays plain text, and /e escapes quotes and backslashes in backreferences before evaluation, which blocks quote breakout. The value also runs through strip_tags(), which is defence in depth rather than the real fix. This hardening only covered standard mode; the vulnerable pattern stayed in ThinkPHP 3.0 Lite mode.
Stage 2: structural fix in ThinkPHP 3.2 (commit 1fe13d0106078aec79be0a5578734bcdeec5dea9, 18 Dec 2013). This rewrite deletes ThinkPHP/Lib/Core/Dispatcher.class.php and adds a namespaced ThinkPHP/Library/Think/Dispatcher.class.php whose parser uses preg_replace_callback with a closure:
preg_replace_callback('/(\w+)\/([^\/]+)/', function($match) use(&$var){$var[$match[1]]=strip_tags($match[2]);}, implode('/',$paths));
No string is built and evaluated. The captured key and value are plain PHP strings passed as array elements, so nothing executes attacker input. The same commit moves other /e uses (parse_name(), Db::parseTable()/parseJoin(), ReadHtmlCacheBehavior) to preg_replace_callback. The cleanup was not complete: /e still appears in CheckActionRouteBehavior (route-rule parsing) and the SAE log driver. So 3.2 removes the URL-dispatch attack path covered by this CVE but is not entirely free of /e. This also matches PHP itself, where /e was deprecated in PHP 5.5 and removed in 7.0.
What 'patched' means here. Neither NVD nor the VulnCheck advisory lists a fixed version or vendor patch, and there is no publicly verifiable backported 2.x or 3.0 Lite release. The verifiable remediations are:
- Legacy code you cannot upgrade: apply the single-quote change to the Dispatcher's
/ereplacement, as in r2838 and the 3.1.x code above. - Otherwise: move to ThinkPHP 3.2 or later, where the Dispatcher no longer evaluates URL-derived strings at all.
Detection Methods
Public detection for this CVE mostly takes the form of active vulnerability scanning. During verification, no vendor-published Snort/Suricata, Sigma, or YARA signature and no published IoC set were found for this CVE. What does exist is a verified scanner template and a well-documented trigger payload.
Active scanning with the Nuclei template. NVD and the VulnCheck advisory both list ProjectDiscovery's http/vulnerabilities/thinkphp/thinkphp-2-rce.yaml, titled "ThinkPHP 2/3 - Remote Code Execution" (CWE-95), as the reference detection:
http: - method: GET path: - "{{BaseURL}}/index.php?s=/index/index/name/$%7B@phpinfo()%7D" matchers-condition: and matchers: - type: word words: - "PHP Extension" - "PHP Version" - "ThinkPHP" condition: and - type: status status: - 200
The s parameter holds a PATH_INFO-style route, and the value of the name key is the URL-encoded expression ${@phpinfo()} with @ suppressing errors. The response must return HTTP 200 and contain all three strings: "PHP Version" and "PHP Extension" appear only if phpinfo() actually ran, while "ThinkPHP" ties the response to the framework. Requiring all three keeps false positives low compared with simple version fingerprinting. The template needs only one request (max-request: 1) and is tagged thinkphp,rce,vuln. Because it tests real behavior rather than a banner, it works even when ThinkPHP is bundled into a custom app with no visible version. The probe still executes code, so use it only against authorized systems.
Lab validation with Vulhub. The thinkphp/2-rce environment runs a ThinkPHP 2.1 demo in Docker, reproduced by requesting /index.php?s=/index/index/name/${@phpinfo()}. Use it to confirm your scanner, WAF, or IDS fires before you rely on it in production.
Hunting for exploitation traffic. The VulnCheck advisory describes exploitation as unauthenticated requests to index.php where the s parameter carries PHP expressions, with Shadowserver first observing evidence on 2023-10-14. From the published payload structure, look in web server, reverse proxy, or WAF logs for:
- requests to
index.phpwith ans=route parameter, or PATH_INFO-style paths, - route segments containing PHP complex-variable syntax
${...}, which may be URL-encoded as$%7B ... %7D, - PHP function calls inside those segments, often with the
@error-suppression prefix.
Real attackers will swap phpinfo() for other functions, so hunts should key on the ${...} structure inside s, not on phpinfo alone. These traits are guidance from the public payload, not a vendor-published signature, so write and test your own rules against the Vulhub lab before you deploy them.
Limitations. The Nuclei check proves a host is exploitable; it does not tell you whether the host was already compromised. No public post-exploitation IoCs are tied specifically to this CVE, so pair positive scan results with a review of past access logs for the request patterns above.
Affected Systems and Versions
- ThinkPHP 2.0 through 2.2 (all affected).
- ThinkPHP 3.0 when running in Lite mode (standard-mode 3.0 received the earlier single-quote hardening; Lite mode did not).
The vendor is TopThink. The CVE record rates the issue Critical, CVSS 3.1 at 9.8 and CVSS 4.0 at 9.3, with CWE-95 (eval injection). Neither NVD nor the VulnCheck advisory lists a fixed version.
Vendor Security History
Available sources do not provide independent market share, deployment counts, or a complete vendor history sufficient to judge TopThink's overall security track record. For context on the broader framework, Akamai has reported exploitation campaigns against ThinkPHP applications involving other, separate vulnerabilities including CVE-2018-20062 and CVE-2019-9082; that reporting concerns different flaws and should not be treated as evidence of the same actors or campaign exploiting CVE-2012-20007. The upstream repository's note that ThinkPHP 3.2 had passed its maintenance lifecycle applies only to that old release and should not be generalized to all ThinkPHP versions or the current project.
References
- NVD: CVE-2012-20007
- CVE Record: CVE-2012-20007
- VulnCheck advisory: ThinkPHP 2.x / 3.0 Lite Unauthenticated RCE via Dispatcher PATH_INFO
- Vulhub ThinkPHP 2-rce environment
- Vulhub 2-rce README (raw)
- ProjectDiscovery Nuclei template: thinkphp-2-rce.yaml
- Nuclei template (raw)
- ThinkPHP historical patch notice
- Upstream ThinkPHP 3.2 repository
- ThinkPHP 3.2 structural fix commit 1fe13d0
- April 2012 hotfix report (cnblogs)
- Akamai: 2024 exploitation of ThinkPHP (separate CVEs)
- Archived original disclosure (jb51.net)



