CVE-2018-18530
Description
ThinkPHP 5.1.25 has SQL Injection via the count parameter because the library/think/db/Query.php aggregate function mishandles the aggregate variable. NOTE: a backquote character is required in the attack URI.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
ThinkPHP 5.1.25 SQL injection in aggregate functions via unsanitized 'count' parameter allows blind data extraction.
Vulnerability
In ThinkPHP versions 5.0.x through 5.1.25 and 3.x through 3.2.4, the aggregate function in library/think/db/Query.php does not sanitize the $field parameter before concatenating it into SQL statements. Specifically, the count parameter (and other aggregate function parameters) can be directly injected with arbitrary SQL when passed via user input. The vulnerability requires that a backquote character (`) be present in the attack URI [1][2].
Exploitation
An attacker must be able to supply a count GET parameter (or similar aggregate parameter) to an endpoint that calls an aggregate function like count(), sum(), avg(), etc., on user-controlled input. In a typical scenario, a controller method such as db('user')->count(input('get.count')); is used. The attacker then sends a crafted URI containing a backtick and a subquery, e.g., ?count=id),(select sleep(5)),(username. This payload is concatenated directly into the SQL statement without parameterized placeholders, causing a time-based blind SQL injection [2].
Impact
Successful exploitation allows an attacker to execute arbitrary SQL queries against the database. Because the database connection uses PDO::ATTR_EMULATE_PREPARES disabled, normal parameterized queries would prevent data retrieval, but this vulnerability bypasses that protection by avoiding placeholders, thus enabling the attacker to retrieve sensitive data (e.g., passwords via blind injection) [2]. The impact is full information disclosure of the database contents.
Mitigation
The vulnerability is fixed in ThinkPHP 5.1.25 and later, and in ThinkPHP 3.2.4 and later. Users should upgrade to these versions immediately [1][2]. No workarounds are documented; however, avoiding the use of unvalidated user input in aggregate function parameters can prevent exploitation. The vulnerability is not listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.
AI Insight generated on May 22, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
topthink/frameworkPackagist | <= 5.1.25 | — |
Affected products
1Patches
0No patches discovered yet.
Vulnerability mechanics
AI mechanics synthesis has not run for this CVE yet.
References
4- github.com/advisories/GHSA-7xfj-4jpg-58vfghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2018-18530ghsaADVISORY
- github.com/top-think/framework/issues/2613ghsaWEB
- www.kingkk.com/2018/10/Thinkphp-%E8%81%9A%E5%90%88%E6%9F%A5%E8%AF%A2%E6%BC%8F%E6%B4%9E/ghsax_refsource_MISCWEB
News mentions
0No linked articles in our index yet.