Craft CMS Authenticated Remote Code Execution via Malicious Attached Behavior
Craft CMS versions before 4.17.12 and 5.9.18 are vulnerable to authenticated remote code execution via malicious behavior injection in the field layout hydration path.
Craft CMS versions before 4.17.12 and 5.9.18 are vulnerable to authenticated remote code execution. The vulnerability stems from an input-handling flaw in a Yii object creation path, allowing any authenticated user to inject malicious configuration and execute arbitrary commands on the server. This is achieved by exploiting the dynamic object configuration feature of Yii, which Craft CMS utilizes to build parts of itself from a settings list. This vulnerability is related to a previously disclosed issue (GHSA-255j-qw47-wjh5) but utilizes a different, unmitigated path. The attack exploits the condition field layouts data conversion to a live FieldLayout object without proper sanitization.
Attack Chain
- An authenticated user logs into the Craft CMS admin panel.
- The attacker crafts a malicious POST request to
/admin/actions/element-search/searchwith a JSON payload. - The JSON payload contains a
conditionparameter with a nestedfieldLayoutsarray. - Within the
fieldLayoutsarray, the attacker injects ayii\\behaviors\\AttributeTypecastBehaviorobject with a__construct()method. - The
__construct()method contains the malicious configuration, includingattributeTypesandtypecastBeforeSaveparameters. - The
typecastBeforeSaveparameter is configured to execute a shell command (e.g., using/bin/bash -c). - The server-side application processes the request and attempts to create a FieldLayout object from the provided configuration data.
- Due to the lack of sanitization, the malicious configuration is injected during object creation, leading to the execution of the attacker-controlled command.
Impact
Successful exploitation allows an attacker to execute arbitrary commands on the server with the privileges of the web server user. This can lead to complete compromise of the Craft CMS instance, including data theft, modification, or deletion. An attacker could also pivot to other systems on the network from the compromised server. There is no specific victim count or sector targeted mentioned, but any Craft CMS instance using a vulnerable version is susceptible.
Recommendation
- Upgrade Craft CMS to version 4.17.12 or 5.9.18 or later to patch the vulnerability (Affected products).
- Deploy the Sigma rule
Detect Craft CMS RCE Attempt via Element Searchto identify exploitation attempts in web server logs (rules). - Monitor POST requests to
/admin/actions/element-search/searchfor suspicious JSON payloads, particularly those containingyii\\behaviors\\AttributeTypecastBehavior(Attack Chain).
Detection coverage 2
Detect Craft CMS RCE Attempt via Element Search
criticalDetects potential remote code execution attempts in Craft CMS by monitoring POST requests to /admin/actions/element-search/search with suspicious JSON payloads.
Detect Craft CMS AttributeTypecastBehavior Injection
highDetects attempts to inject AttributeTypecastBehavior into Craft CMS requests, which can lead to remote code execution.
Detection queries are kept inside the platform. Get full rules →