Skip to content
RCE Disclosed report Intermediate CVE-2019-5475

OS Command Injection in Nexus Repository Manager 2.x

The Nexus Yum Repository Plugin passes user-supplied data to a command-line executor without sanitisation, allowing an authenticated user to set the path of 'createrepo' or 'mergerepo' to an arbitrary OS command. This results in remote code execution on the underlying operating system.

christianaugust Follow

Originally disclosed on HackerOne

Critical 9.1 View original
  • Triaged in 27 hours
  • Fixed in 20 days
  • Disclosed after 28 days

Summary by the program

https://support.sonatype.com/hc/en-us/articles/360033490774-CVE-2019-5475-Nexus-Repository-Manager-2-OS-Command-Injection-2019-08-09

The report

Maven artifact

groupId: org.sonatype.nexus.plugins artifactId: nexus-yum-repository-plugin version: 2.14.9-01

Vulnerability

Vulnerability Description

The Nexus Yum Repository Plugin is vulnerable to Remote Code Execution. All instances using CommandLineExecutor.java with user-supplied data is vulnerable, such as the Yum Configuration Capability.

Additional Details

Source File and Line Number: https://github.com/sonatype/nexus-public/blob/release-2.14.9-01/plugins/yum/nexus-yum-repository-plugin/src/main/java/org/sonatype/nexus/yum/internal/capabilities/YumCapability.java#L121

Steps To Reproduce:

  1. Navigate to "Capabilities" in Nexus Repository Manager.
  2. Edit or create a new Yum: Configuration capability
  3. Set path of "createrepo" or "mergerepo" to an OS command (e.g. C:\Windows\System32\calc.exe)
  4. The OS command should now have executed as the SYSTEM user. Note that in this case, Nexus appends --version to the OS command.

The following HTTP request was used to trigger the vulnerability:

PUT /nexus/service/siesta/capabilities/000013ea3743a556 HTTP/1.1
Host: HOST:PORT
Accept: application/json
Authorization: Basic YWRtaW46YWRtaW4xMjM=
Content-Type: application/xml
Content-Length: 333
Connection: close

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:capability xmlns:ns2="http://sonatype.org/xsd/nexus-capabilities-plugin/rest/1.0"><id>healthcheck</id><notes>123</notes><enabled>true</enabled><typeId>1</typeId><properties><key>createrepoPath</key><value>C:\Windows\System32\calc.exe</value></properties></ns2:capability>

Supporting Material/References:

  • Windows Server 2016
  • Sonatype Nexus Repository Manager 2.14.9-01
  • Java 8

Wrap up

  • I contacted the maintainer to let them know: N
  • I opened an issue in the related repository: N

Impact

An authenticated user with sufficient privileges in a Nexus Repository Manager installation can exploit this to execute code on the underlying operating system.

Attachments

The original report as published on HackerOne, by christianaugust. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

Nexus Repository Manager 2.x is a repository manager, and the report concerns its Yum repository plugin. The affected Maven artifact is:

Text
groupId: org.sonatype.nexus.plugins
artifactId: nexus-yum-repository-plugin
version: 2.14.9-01

The plugin provides a capability called Yum: Configuration, which lets an administrator point Nexus at the external tools it uses to build Yum repository metadata, createrepo and mergerepo. Those paths are stored as capability properties and are later handed to a command line executor. The report states that any instance using CommandLineExecutor.java with user-supplied data is vulnerable, and names the Yum Configuration Capability as an example.

The program's summary links to the vendor advisory for CVE-2019-5475.

Setup

The researcher tested against the following environment, as listed in the report:

  • Windows Server 2016
  • Sonatype Nexus Repository Manager 2.14.9-01
  • Java 8

The request in the report carries an HTTP Basic Authorization header, so the attacker needs an authenticated session. The report's impact section qualifies this further: the user must have sufficient privileges in the Nexus installation to edit capabilities. The command in the proof of concept runs as the SYSTEM user on the Windows host.

Finding it

The researcher traced the capability's handling of the createrepoPath property to a specific source location:

Text
https://github.com/sonatype/nexus-public/blob/release-2.14.9-01/plugins/yum/nexus-yum-repository-plugin/src/main/java/org/sonatype/nexus/yum/internal/capabilities/YumCapability.java#L121

The capability is edited through the Nexus UI, and the report's request shows the same value being set through the capabilities REST endpoint.

Exploitation

Step 1: Reach the capability settings

Navigate to "Capabilities" in Nexus Repository Manager.

Step 2: Create or edit the Yum capability

Edit an existing Yum: Configuration capability, or create a new one.

Step 3: Put an OS command in the tool path

Set the path of createrepo or mergerepo to an OS command. The report's example is:

Text
C:\Windows\System32\calc.exe

Step 4: Observe execution

The OS command executes as the SYSTEM user. The report notes one detail about how the command is invoked: Nexus appends --version to the OS command. In the calculator example this does not prevent execution.

The HTTP request

The researcher triggered the vulnerability with the following request, which updates capability 000013ea3743a556 through the capabilities REST endpoint:

HTTP
PUT /nexus/service/siesta/capabilities/000013ea3743a556 HTTP/1.1
Host: HOST:PORT
Accept: application/json
Authorization: Basic [redacted]
Content-Type: application/xml
Content-Length: 333
Connection: close

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:capability xmlns:ns2="http://sonatype.org/xsd/nexus-capabilities-plugin/rest/1.0"><id>healthcheck</id><notes>123</notes><enabled>true</enabled><typeId>1</typeId><properties><key>createrepoPath</key><value>C:\Windows\System32\calc.exe</value></properties></ns2:capability>

The important parts:

  • PUT to /nexus/service/siesta/capabilities/000013ea3743a556 targets a single existing capability by its identifier, so the request modifies rather than creates.
  • The Authorization header carries Basic credentials, which is why authentication and the right privileges are a precondition.
  • The body is XML in the nexus-capabilities-plugin namespace. The properties element sets the key createrepoPath to C:\Windows\System32\calc.exe, which is the value that ends up on the command line.
  • enabled is true, so the capability is active.

The report does not include the server's response to this request.

Root cause

The Yum capability stores the paths of the external metadata tools as plain strings and passes them to CommandLineExecutor.java when the tools are invoked. Nothing in that path restricts the value to a real executable, so the property is effectively a command to run. The report points at YumCapability.java line 121 as the source location. Because the capability is writable through both the UI and the REST API, any user who can edit capabilities can place an arbitrary command there.

The report notes that Nexus appends --version to the OS command.

Impact

An authenticated user with sufficient privileges in a Nexus Repository Manager installation can exploit this to execute code on the underlying operating system. In the tested configuration the command ran as the SYSTEM user. The report does not describe what an attacker could reach beyond that host.

Fix

The report itself does not describe a code change. The program's summary points to the Sonatype advisory for CVE-2019-5475, which is where the remediation is documented.

Variants to test

  • Other capabilities or plugin settings that name an external binary (any property that ends up in CommandLineExecutor.java). A positive result is the same behaviour seen here: the value is executed, with any fixed arguments appended.
  • The mergerepo path alongside createrepo. The report names both as settable to an OS command, so try each independently.
  • Creating a capability rather than updating one. The report's request updates an existing capability by id; a create request carrying the same createrepoPath property is worth checking.
  • Non-Windows hosts. The report only demonstrates Windows Server 2016 with a Windows executable path; on Linux the equivalent is a shell command in the same property, and a positive result is command output or a side effect attributable to the Nexus process user.

Hunting notes

This class of bug hides in administrative features that shell out to external tools: repository metadata generators, indexers, scanners and backup hooks. The signal during recon is a product or plugin whose configuration exposes filesystem paths to binaries, especially where those paths are editable through a REST API as well as the UI. The report's request targets the capability REST endpoint under /nexus/service/siesta/capabilities/ with an XML body that sets the tool path.

The report's example sets the tool path to calc.exe and notes that the OS command executed as the SYSTEM user.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

Nexus Repository Manager is a piece of software that companies run on their own servers to store and organise the software packages their developers use. Think of it as a large, well-ordered warehouse for code: instead of boxes, it holds files that other programs download and install. One of the things it can store is a "Yum repository", which is a collection of software packages used on certain Linux systems.

To build the index for a Yum repository, Nexus does not do the work itself. It calls two small helper programs that live on the same machine, called createrepo and mergerepo. An administrator tells Nexus where those helper programs are by typing their file paths into a settings screen. A file path is just the address of a program on disk, for example C:\Windows\System32\calc.exe is the address of the Windows calculator.

The bug is that the value typed into that setting is passed to CommandLineExecutor.java, the part of Nexus that launches a program. It simply took the text and handed it to the part of the program that runs commands on the operating system. So if someone typed the address of a different program, Nexus would run that instead. The researcher put the address of the Windows calculator in that field, and the report says the OS command should now have executed as the SYSTEM user.

This kind of bug is called OS command injection. "OS" means operating system, the underlying software (Windows, Linux) that runs programs. "Command injection" means that text a user supplies is treated as a command to run rather than as harmless data. The everyday comparison: imagine a form at a restaurant where you write what you want, and the kitchen reads your note as instructions to the chef. If you write "one soup", you get soup. If you write "one soup, and also unlock the back door", and the kitchen obeys every word, you have just done command injection.

Two conditions make this serious. First, the attacker has to be logged in to Nexus and have enough rights to change these settings, so it is not open to absolutely anyone on the internet. Second, the command runs as the SYSTEM user. On Windows, SYSTEM is the most powerful local account, more powerful than a normal administrator. A program running as SYSTEM can do essentially anything on that machine. So the command runs with the privileges of the SYSTEM account, not just those of the Nexus program.

The report was filed under the identifier CVE-2019-5475. A CVE is a public catalogue number given to a known security flaw so that people can talk about it unambiguously. The program that ran the report also linked to the vendor's own advisory page, which is where the official description and the fix live.

The affected component

The report identifies the vulnerable piece of software using Maven coordinates. Maven is a tool for managing software components written in Java, and it names each component with three labels: a groupId (who made it), an artifactId (its name) and a version (which release). The affected component is:

Text
groupId: org.sonatype.nexus.plugins
artifactId: nexus-yum-repository-plugin
version: 2.14.9-01

Line by line:

  • groupId: org.sonatype.nexus.plugins says the component belongs to Sonatype, the company behind Nexus, and sits in its plugins family. A plugin is an add-on that gives a bigger program extra abilities, like an app on a phone.
  • artifactId: nexus-yum-repository-plugin is the name of this particular add-on: the plugin that adds Yum repository support to Nexus.
  • version: 2.14.9-01 is the exact release that was tested. Version numbers matter because a fix usually appears in a later one.

The plugin adds a settings item called Yum: Configuration. A capability in Nexus is a switchable feature with its own settings; the Yum: Configuration capability is the one that holds the paths to createrepo and mergerepo. Those paths are stored as properties, which simply means named settings: a name (the key) and a value. Later, when Nexus needs to build repository metadata, it takes the stored value and passes it to CommandLineExecutor.java. That file is the part of Nexus responsible for actually launching a program on the operating system. The report says that any place using CommandLineExecutor.java with data supplied by a user is vulnerable, and gives the Yum Configuration Capability as the example.

The test environment

The researcher ran the test on this setup, as listed in the report:

  • Windows Server 2016
  • Sonatype Nexus Repository Manager 2.14.9-01
  • Java 8

Windows Server 2016 is a version of Windows made for servers rather than desktops. Java 8 is the runtime that Nexus is written to run on; Java is a programming language and a program that executes it. Knowing the environment matters because the proof uses a Windows program and a Windows account, and the same bug on a Linux server would look different in its details.

The request in the report includes an HTTP Basic Authorization header. HTTP is the language browsers and servers use to talk to each other, and a header is a labelled line of extra information sent with each request, like the address block on an envelope. HTTP Basic authentication means the username and password are sent, encoded, in that header. So the attacker must already be logged in. The report's impact section adds that the user must have sufficient privileges to edit capabilities. In plain terms: this is not a bug that a random visitor can use; it is a bug that turns a trusted administrator, or someone who has stolen an administrator's credentials, into the owner of the server.

Finding the flaw

The researcher followed the handling of the createrepoPath property, the setting that holds the path to createrepo, down to a specific place in the source code:

Text
https://github.com/sonatype/nexus-public/blob/release-2.14.9-01/plugins/yum/nexus-yum-repository-plugin/src/main/java/org/sonatype/nexus/yum/internal/capabilities/YumCapability.java#L121

This is a link to a file on GitHub, a website where source code is published. Reading it from left to right: sonatype/nexus-public is the project, release-2.14.9-01 is the version branch, and the long path ending in YumCapability.java is the file. The .java ending means it is Java source code. #L121 means line 121 of that file, the spot the researcher wants you to look at. Source code is the human-readable text a programmer writes; it is what gets turned into the running program.

The report points at that line as the source location, and states that instances using CommandLineExecutor.java with user-supplied data are vulnerable. Nothing confirms that the text is the address of createrepo; it is accepted as-is and ends up on a command line. Because the capability can be changed both through the Nexus web interface and through a REST endpoint, the value is user-supplied data reaching a command line. A REST endpoint is a web address that a program (rather than a person clicking) can send requests to, to read or change something on the server. It is the same idea as a web page, but designed for software to talk to software.

Reproducing it

Step 1: Open the capability settings

Navigate to "Capabilities" in Nexus Repository Manager. This is the settings area where the switchable features and their options are listed. The researcher starts here because the bug lives in one of these settings, and seeing it in the interface makes the rest easier to follow.

Step 2: Create or edit the Yum capability

Edit an existing Yum: Configuration capability, or create a new one. Either route works because both end up writing the same kind of setting. Editing an existing one is the quicker path if the feature is already switched on.

Step 3: Put a command where a program path belongs

Set the path of createrepo or mergerepo to an OS command. The report's example is:

Text
C:\Windows\System32\calc.exe

This is the full address of the Windows calculator. C: is the drive, Windows and System32 are folders, and calc.exe is the program file; .exe is the ending Windows uses for programs. The field expects the address of a helper tool, and the researcher gives it the address of a completely different program. The report says the OS command should now have executed as the SYSTEM user.

Step 4: Watch it run

The OS command executes as the SYSTEM user. The report notes one detail about how the command is invoked: Nexus appends --version to the OS command. In other words, Nexus does not run exactly what was typed; it adds an extra word on the end. --version is a common instruction that asks a program to print its version number. In the calculator example this does not stop the calculator from starting. The report notes that Nexus appends --version to the OS command.

The HTTP request

The researcher triggered the vulnerability with the following request, which updates capability 000013ea3743a556 through the capabilities REST endpoint:

HTTP
PUT /nexus/service/siesta/capabilities/000013ea3743a556 HTTP/1.1
Host: HOST:PORT
Accept: application/json
Authorization: Basic [redacted]
Content-Type: application/xml
Content-Length: 333
Connection: close

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:capability xmlns:ns2="http://sonatype.org/xsd/nexus-capabilities-plugin/rest/1.0"><id>healthcheck</id><notes>123</notes><enabled>true</enabled><typeId>1</typeId><properties><key>createrepoPath</key><value>C:\Windows\System32\calc.exe</value></properties></ns2:capability>

Line by line, in plain words:

  • PUT /nexus/service/siesta/capabilities/000013ea3743a556 HTTP/1.1 is the first line of the request. PUT is the HTTP method used to replace or update something that already exists. The path points at one specific capability, identified by the long code 000013ea3743a556, so this request changes that one rather than creating a new one. HTTP/1.1 is the version of the protocol being spoken.
  • Host: HOST:PORT says which server to talk to. HOST stands for the server's name and PORT for the numbered channel on it; both are placeholders here, not real values.
  • Accept: application/json tells the server the client is willing to receive a JSON reply. JSON is a common text format for structured data, made of names and values in curly brackets.
  • Authorization: Basic [redacted] is the login line. The credentials have been removed here because they are secret; in the original they were the encoded username and password. This is why the attacker must already be authenticated.
  • Content-Type: application/xml says the body of the request is written in XML, another text format for structured data, this one built from tags in angle brackets.
  • Content-Length: 333 states how many bytes long the body is, so the server knows where it ends.
  • Connection: close asks the server to close the connection after answering, rather than keeping it open for more requests.
  • The blank line separates the headers from the body. Everything after it is the content being sent.
  • <?xml version="1.0" encoding="UTF-8" standalone="yes"?> is the XML declaration: it says this is XML version 1.0, the text is encoded in UTF-8 (a standard way of representing characters), and the document stands alone.
  • <ns2:capability xmlns:ns2="http://sonatype.org/xsd/nexus-capabilities-plugin/rest/1.0"> opens the capability element. The xmlns:ns2 part declares a namespace, a way of saying which vocabulary of tag names this document uses, so the server knows these tags belong to the Nexus capabilities API. An API is the set of addresses and formats a program offers so other programs can use it; think of a restaurant menu: it lists what you can order and how to ask for it, without you entering the kitchen.
  • <id>healthcheck</id> gives the capability an id value of healthcheck.
  • <notes>123</notes> is a free-text note field, set to 123.
  • <enabled>true</enabled> switches the capability on, so it is active and will be used.
  • <typeId>1</typeId> selects the type of capability by number.
  • <properties><key>createrepoPath</key><value>C:\Windows\System32\calc.exe</value></properties> is the heart of the request. It sets the property named createrepoPath to the address of the calculator. This is the same change an administrator would make in the settings screen, done here in one request instead.
  • </ns2:capability> closes the element.

The report does not include the server's response to this request.

Why it works

The Yum capability stores the paths of the external helper tools as plain text and passes them to CommandLineExecutor.java when the tools are invoked. Nothing along that path restricts the value to a real program, so the setting is effectively a command to run. The report points at YumCapability.java line 121 as the source location. Because the capability can be written through both the web interface and the REST API, anyone who can edit capabilities can place an arbitrary command there.

The appended --version shows that the tool is launched with a fixed extra argument, but it does not clean up the program part of the command line, so it does not fix the problem. Cleaning up, or sanitising, means checking and rewriting user input so that it can only be used as intended; here that check is missing.

What an attacker gains

An authenticated user with sufficient privileges in a Nexus Repository Manager installation can exploit this to execute code on the underlying operating system. In the tested setup the command ran as the SYSTEM user. The report does not describe what an attacker could reach beyond that host.

The fix

The report itself does not describe a code change. The program's summary points to the Sonatype advisory for CVE-2019-5475, which is where the remediation is documented.

Other places to look

  • Other capabilities or plugin settings that name an external program, meaning any property that ends up in CommandLineExecutor.java. A positive result looks the same as here: the value is executed, with any fixed arguments added on.
  • The mergerepo path as well as createrepo. The report names both as settable to an OS command, so try each on its own.
  • Creating a capability rather than updating one. The report's request updates an existing capability by id; a create request carrying the same createrepoPath property is worth checking.
  • Non-Windows hosts. The report only demonstrates Windows Server 2016 with a Windows program path; on Linux the equivalent is a shell command in the same property, and a positive result is command output or a side effect attributable to the user the Nexus process runs as.

Notes for people hunting this kind of bug

This class of bug hides in administrative features that call out to external tools: repository metadata generators, indexers, scanners and backup hooks. The signal during recon is a product or plugin whose configuration exposes filesystem paths to programs, especially where those paths can be edited through a REST API as well as the interface. The report's request targets the capability REST endpoint under /nexus/service/siesta/capabilities/ with an XML body that sets the tool path.

The report's example sets the tool path to calc.exe and notes that the OS command executed as the SYSTEM user.

Glossary

  • API: the set of addresses and data formats a program offers so other programs can use it, like a menu that lists what you can order and how to ask.
  • Artifact: a packaged piece of software, identified in Maven by groupId, artifactId and version.
  • Authentication: proving who you are, usually with a username and password.
  • Authorization header: a line in an HTTP request carrying proof of identity, such as Basic credentials.
  • Basic authentication: a simple HTTP login scheme where the username and password are sent, encoded, in the Authorization header.
  • Capability: a switchable feature in Nexus with its own settings.
  • Command injection: a flaw where text supplied by a user is treated as a command to run instead of harmless data.
  • Command line: the text a computer uses to launch a program, including the program's address and any extra arguments.
  • CVE: a public catalogue number given to a known security flaw so it can be discussed unambiguously.
  • Endpoint: a web address that programs can send requests to, to read or change something on a server.
  • Header: a labelled line of extra information sent with an HTTP request or response.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • HTTP method: the verb of a request, such as GET to read or PUT to update.
  • Java: a programming language, and the runtime that executes programs written in it.
  • JSON: a text format for structured data, made of names and values in curly brackets.
  • Maven: a tool for managing Java software components, which names each one with groupId, artifactId and version.
  • Namespace: a way of saying which vocabulary of tag names a document uses, so the receiver interprets them correctly.
  • OS (operating system): the underlying software, such as Windows or Linux, that runs programs and manages the machine.
  • OS command injection: command injection where the injected text is run by the operating system itself.
  • Plugin: an add-on that gives a larger program extra abilities.
  • Property: a named setting, stored as a key and a value.
  • PUT: an HTTP method used to replace or update something that already exists.
  • REST endpoint: a web address designed for software to call, rather than for a person clicking in a browser.
  • Sanitising: checking and rewriting user input so it can only be used as intended.
  • Source code: the human-readable text a programmer writes, which is turned into a running program.
  • SYSTEM: the highest-privilege local account on Windows, more powerful than a normal administrator.
  • Version: a label identifying which release of a piece of software is being used.
  • XML: a text format for structured data, built from tags in angle brackets.
  • Yum repository: a collection of software packages used on certain Linux systems, with an index that tools read to install them.

More from Central Security Project

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.