CiviCRM 5.22.0 – Code Execution Vulnerability Chain Explained
CiviCRM 5.22.0 had a CSRF vulnerability that let an attacker write a JavaScript config file, leading to stored XSS, and a Phar deserialization flaw that allowed code execution. An attacker could lure an authenticated administrator to a malicious page and, by chaining these issues, execute arbitrary system commands on the server.
blog.sonarsource.com
Published on blog.sonarsource.com
During our vulnerability research on the largest CMS systems we came across CiviCRM last year. It’s an open source CRM plugin for the most popular CMS systems like Wordpress, Joomla, Drupal, and Backdrop.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the CKEditor configuration form lacked CSRF tokens and allowed attacker-controlled content to be saved as a JavaScript file, while the Badge component passed user-controlled input to getimagesize(), enabling Phar deserialization.
Impact
An attacker could execute arbitrary system commands on CiviCRM instances running on WordPress, fully compromising the server and its data; other CMS systems like Joomla prevent deserialization of Phar metadata, limiting the code execution.
What the attacker needed
Victim is an authenticated administrator; victim is lured to a malicious page; CiviCRM runs on WordPress for code execution
The fix
The vulnerabilities were fixed in CiviCRM versions 5.28.1, 5.27.5 ESR, 5.24.3, and 5.21.3; the report recommends adding CSRF tokens and using a custom Phar wrapper to prevent untrusted deserialization.
How it was found
- The attacker lures an authenticated administrator to a malicious page that submits a form to the CiviCRM site.
- The first CSRF request creates a JavaScript configuration file containing an XSS payload.
- The second CSRF request overwrites the default CKEditor configuration to include the previously created file, causing stored XSS.
- The attacker uploads an image containing Phar metadata.
- The attacker calls the getImageProp() method via an AJAX request with the img parameter pointing to the uploaded image, triggering deserialization and code execution.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
CiviCRM is a tool for managing contacts and donations. The report shows two mistakes: one let an attacker trick a logged-in administrator into saving a malicious file, and another let an uploaded image be used to run code on the server. Together, these could give an attacker full control of the website.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.