Skip to content
RCE Write-up Advanced

OpenEMR Remote Code Execution in your Healthcare System

OpenEMR versions below 7.0.0 contained an unauthenticated file read via a rogue MySQL server, plus an authenticated reflected XSS and local file inclusion that could be chained to achieve remote code execution. An attacker could read sensitive files or execute arbitrary system commands on the server.

Dennis Brinkrolf Follow

Published on sonarsource.com

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

Dennis Brinkrolf (@DBrinkrolf), on 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

Likely the installer remained accessible after installation and accepted attacker-controlled database settings, while user input reached a JavaScript context and a file path without proper sanitisation.

Impact

An unauthenticated attacker could read sensitive files such as certificates and passwords, and by chaining the XSS and LFI could execute arbitrary system commands, potentially compromising the entire infrastructure.

What the attacker needed

OpenEMR version below 7.0.0; mysqli.allow_local_infile=On for file read; victim interaction for XSS; attacker controls a MySQL server

The fix

The vulnerabilities were fixed in OpenEMR 7.0.0 by adding session and CSRF checks to the installer, encoding the ampersand in the JavaScript context, sanitising the file inclusion parameter, and checking uploaded file extensions.

How it was found

  1. Access the installer and set database connection properties to point to a rogue MySQL server.
  2. Use the rogue server to request arbitrary files via LOAD DATA LOCAL INFILE.
  3. Trigger a reflected XSS through the REQUEST_URI parameter to execute JavaScript in a victim's browser.
  4. Use the XSS to upload a PHP file with a .plugin.php suffix via the file upload feature.
  5. Exploit the local file inclusion in the formname parameter to include and execute the uploaded PHP file.

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.

OpenEMR is software hospitals use to store patient records. The researchers found that an attacker could trick the system into reading files from its own server, and by combining a script-injection flaw with a file-inclusion flaw, could run their own code on the server. This means an attacker could steal patient data or take over the server.

What is RCE?

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

More by Dennis Brinkrolf

View all

1 more disclosed report, best first.

More from OpenEMR

View all

The newest disclosed reports for this program.

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.