Skip to content
SQL injection Write-up Advanced

From 0 to RCE: Cockpit CMS

Cockpit CMS contained NoSQL injection flaws in authentication endpoints that let unauthenticated attackers extract usernames and password reset tokens, leading to account takeover. A PHP injection in the MongoLite library allowed authenticated users to execute arbitrary code.

swarm.ptsecurity.com

Published on swarm.ptsecurity.com

Our team searched for bugs in the source code of Cockpit, an open-source content management system. Here is the description of Cockpit from its official site:

The author, on swarm.ptsecurity.com

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 application failed to validate that user-supplied parameters were strings, allowing MongoDB operators to be injected into database queries, and later failed to escape a field name used in a PHP string literal.

Impact

An unauthenticated attacker could take over any user account, including administrator, and then execute arbitrary code on the server.

What the attacker needed

None for NoSQL injection; authentication for PHP injection

The fix

The vulnerabilities were fixed in Cockpit version 0.12.0 and later.

How it was found

  1. Send a request to /auth/requestreset to generate a password reset token for the target user.
  2. Use a NoSQL injection in /auth/resetpassword or /auth/newpassword to extract the reset token.
  3. Use the token with /auth/newpassword to extract user account data including username, password hash, API key, and reset token.
  4. Use the API key, brute-force the password hash, or change the password via /auth/resetpassword to access the account.
  5. Upload a web shell using the Finder component to achieve remote 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.

Cockpit is a content management system. The login and password reset features did not properly check the type of data they received, so an attacker could send special database queries to find out usernames and reset tokens. With that information, they could take over any account, including the administrator's, and then run their own code on the server.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.