Skip to content
RCE Write-up Advanced

Code vulnerabilities put health records at risk

OpenEMR [redacted] contained a command injection flaw in an admin backup feature, a persistent XSS in a user's last name, and an authentication bypass in the Patient Portal API. Chained together, these allowed an unauthenticated attacker to execute arbitrary OS commands on the server and access patient data.

blog.sonarsource.com

Published on blog.sonarsource.com

OpenEMR is the most popular open source software for electronic health record and medical practice management. It is used world-wide to manage sensitive patient data, including information about medications, laboratory values, and diseases.

The author, on blog.sonarsource.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

The command injection occurred because user input was escaped for SQL but then placed inside double quotes in a shell command, allowing command substitution; the XSS lacked output encoding; and the API authentication bypass stemmed from a session flag set during registration that disabled authentication checks.

Impact

An unauthenticated attacker could execute arbitrary OS commands on the server, potentially compromising sensitive patient data and critical infrastructure.

What the attacker needed

Patient Portal component active and accessible; No authentication required for initial attack

The fix

The command injection was fixed by swapping single and double quotes in the shell command; the XSS was fixed by using htmlspecialchars() for output encoding; and the authentication bypass was fixed by properly handling the registration session flag.

How it was found

  1. Send a request to register.php to create a session with the registration flag set.
  2. Access the API dispatcher without completing registration, bypassing authentication.
  3. Use the API to change the administrator's last name to contain an XSS payload.
  4. When the administrator views the user's information, the XSS payload executes in their browser.
  5. The XSS payload triggers the backup feature with a crafted form_sel_layouts parameter containing backticks.
  6. The injected command executes on the server, leading to full compromise.

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.

This report describes three security bugs in a medical records system. One bug lets an attacker run system commands on the server, another lets them insert malicious code into a user's name that runs in an admin's browser, and a third lets them skip login. By combining them, an attacker could take over the server without needing any password.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.