Komodosec| Through the cloud — remote debugging to crack MQ
The event aggregator server did not verify some event parameters against the RabbitMQ user that delivered them, allowing an attacker with access to the aggregator to inject events under the name of other customers. The attacker first extracted RabbitMQ credentials from the Java process memory and then used remote debugging to understand the message format.
medium.com
Published on medium.com
In a simple penetration test the tester is presented with a target, say a web application, and attacks it from his workstation. However, systems can be far more complicated than standard web applications and can span multiple servers with different accessibility.
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.
Context
The target was a system designed to sit inside a corporate network, made up of two main parts: an endpoint agent and a cloud-hosted "event aggregator" server. The aggregator collects events from the endpoints, analyses them and presents them in a dashboard. On top of that, special events are forwarded to the manufacturer for analysis through a RabbitMQ message queue. The report includes a very basic diagram of the system:

The endpoint and the event aggregator were tested black box in the first part of the engagement. That produced a number of vulnerabilities, but the cloud RabbitMQ server itself could not be reached: it is only accessible from the event aggregator servers. The second part of the test therefore simulated an attacker who had already gained access to an organisation's event aggregator server, and the task was to test the RabbitMQ implementation from there.
Setup
The starting point was an SSH connection to the aggregator server with a root-capable user. The tools used across the engagement were:
netstatto map local and outgoing connections- a port scan of the server
- the
jmaputility to dump the memory of the Java process - a Java memory analyzer to query the dump
- a Java debug server, reached through an SSH tunnel, to debug the production JAR
The outgoing connection was to port 5672, a port used by RabbitMQ.
Finding it
The first step was to work out which processes on the aggregator server talk to RabbitMQ. Running netstat -pa quickly showed an outgoing connection to port 5672 owned by a Java application. A port scan of the server did not reveal any other services, so the only path forward was to probe the implementation itself.
Credentials came next. Digging into the Java VM revealed the JAR file that makes the connection. Searching the configuration file for credentials was unsuccessful: they were retrieved dynamically over an encrypted connection. The decision was to pull them from memory instead.
Exploitation
Step 1: Locate the credential object and dump memory
The JAR file was disassembled and the object holding the credentials for the AMQP connection was located. The process memory was then dumped, which the report describes as straightforward because the application runs under the Java VM; jmap was used for this. Loading the dump into a Java memory analyzer and querying for the desired object produced the plaintext credentials:

With working credentials in hand, the RabbitMQ instance was probed for misconfigured permissions, for example read access to shared event queues or write access to configuration queues. Nothing was found, and the management interface for the RabbitMQ instance was closed as well. The broker appeared properly configured, so attention turned to the application that reads from it.
Step 2: Establish a baseline event
A standard event was generated on the endpoint and watched as it appeared at the backend dashboard. The goal was to modify the event's values midway. The message sent to the queue, however, was packed in a way that made reproducing it difficult. That is what pushed the test towards debugging the production JAR on the remote server and copying the routines and data involved.
Step 3: Enable a remote debug server
The JAR was started by an init.d script. The initialization script was altered to include a Java debug server on port 5005 by adding the parameter:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
This turns on the JDWP debug agent, listens on TCP port 5005 (server=y), does not suspend the JVM at startup (suspend=n) and accepts connections over a socket transport. The port was then tunnelled through the existing SSH session, which allowed a connection to the debug server on the remote host.
Step 4: Break, copy, reproduce
A breakpoint was placed right before the event was sent. Through what the report calls a slow and sometimes agonizing process, the relevant parameters and routines were copied into a basic Java program of the researchers' own:

That gave complete control over the event's parameters.
Step 5: Inject events as other customers
Shortly afterwards the dashboard application was found not to verify some of the event's parameters against the RabbitMQ user used to deliver them. For instance, events could be injected under the name of other customers. The report does not list the individual parameters involved.
Root cause
The broker itself was not the weak point: permissions were not misconfigured and the management interface was closed. The flaw sat in the dashboard application consuming the queue. It trusted parameters carried inside the event without checking them against the identity of the RabbitMQ user that delivered the message, so a producer holding valid broker credentials could set those parameters to values belonging to another customer. The report does not describe the exact check that was missing.
Impact
An attacker who has already compromised an event aggregator server, and can therefore reach the broker and obtain its credentials, can inject events under the name of other customers. The report frames this as the conclusion of the exercise and notes that the backend systems were mostly out of the test's scope, so the wider consequences were not explored.
Fix
The report does not state what was changed. Based on the finding, the dashboard application should validate the event's parameters against the RabbitMQ user that delivered the message, so that a producer cannot set fields identifying another customer.
Variants to test
- Credential retrieval from memory. On any Java service that fetches secrets dynamically, dump the heap with
jmapand query it for the connection object. A positive result is plaintext credentials for a backend service in the dump. - Broker permission review. With obtained AMQP credentials, try reading shared queues and writing to configuration queues. A positive result is access to queues that belong to other tenants or to administrative functions.
- Message field trust. Publish an event with fields naming a different customer and see whether the dashboard accepts it. A positive result is the event appearing under the other customer's name.
- Debug agent exposure. Check whether production JARs are started with a JDWP agent and whether the port is reachable, directly or through a tunnel. A positive result is an attachable debugger on the production process.
- Producer identity binding. For each field in the message, change it to a value belonging to another tenant and observe whether the consumer rejects it. A positive result is any field that is accepted without being tied to the authenticated producer.
What happened, in plain words
A security company was hired to test a product that watches over computers inside a company network. The product has two halves. One half is a small program installed on each employee's computer, called an endpoint agent. The other half is a server in the cloud, called the event aggregator, which collects reports (called events) from all those agents, analyses them and shows them on a dashboard. Some special events are also forwarded to the manufacturer for further analysis, and that forwarding happens through a piece of software called RabbitMQ, which is a message queue.
A message queue is easiest to picture as a conveyor belt in a factory. One machine puts boxes onto the belt, another machine takes them off. The two machines never talk to each other directly; they only agree on the shape of the boxes and the belt between them. RabbitMQ is a very popular brand of such a conveyor belt, and the protocol it speaks is called AMQP.
In the first part of the test, the researchers attacked the endpoint agent and the event aggregator from the outside, without any inside knowledge (this is called black box testing, like being handed a locked box and asked to open it without a key or a manual). That part found plenty of problems. But one piece of the system stayed out of reach: the RabbitMQ server in the cloud. It only accepts connections from the event aggregator servers, so nobody outside that network can touch it.
So the second part of the test changed the story. The researchers pretended that an attacker had already broken into one of the company's event aggregator servers, and they were asked: from there, can you do damage through RabbitMQ? That is the part this article walks through.
The setup
To play the role of that attacker, the researchers were given a way to log in to the aggregator server remotely, using a protocol called SSH. SSH is a way to open a text terminal on another computer over the network, securely. The account they were given was root-capable, meaning it could become the all-powerful administrator account on that machine.
The tools they used along the way were:
netstat, a command that lists network connections open on a machine, a bit like checking which doors and windows of a house are currently open and who is standing in them.- a port scan, which is a way of asking a computer, one numbered door at a time, whether anything is listening behind it. Computers have thousands of numbered ports, and each network service listens on one or more of them.
jmap, a tool that takes a snapshot of the memory of a running Java program.- a Java memory analyzer, a program that lets you search inside such a snapshot.
- a Java debug server, a feature built into Java that lets a developer pause a running program, look at its variables and step through its code line by line, from another machine.
One number matters here: RabbitMQ listens on port 5672 by default. That is the standard port for AMQP, the protocol RabbitMQ speaks. Knowing the default port is like knowing that the post office is always on the main square: it makes an outgoing connection easy to spot.
Finding the connection
The first question was: which programs on this server actually talk to RabbitMQ? The researchers ran:
netstat -pa
Line by line: netstat is the tool that lists network connections. The -p option asks it to also show which program (process) owns each connection. The -a option asks it to show all connections, including ones that are listening for incoming traffic, not just the ones currently active. Together, the command prints a table of every network connection on the machine and the program behind it.
The output quickly showed an outgoing connection to port 5672, owned by a Java application. A port scan of the server did not turn up any other services, so there was no side door to try. The only way forward was to attack the implementation itself.
Getting the credentials
To talk to RabbitMQ, a program needs a username and password, called credentials. The researchers needed them too. They dug into the running Java process and found the JAR file that makes the connection. A JAR file is Java's version of a zip archive: a single file that bundles a Java program and all its parts.
Their first idea was to look in the program's configuration file, the settings file where such things are often written down. That failed: the credentials were not stored there. Instead, the program fetched them at runtime over an encrypted connection, so they never sat on disk in readable form. The researchers decided to pull them out of the program's memory instead, because at some point the program has to hold the password in order to use it.
Step 1: find the object and dump memory
They disassembled the JAR file, meaning they unpacked it and read its contents, and located the object that holds the credentials for the AMQP connection. In Java, an object is a bundle of data and code that represents one thing, here the connection settings including the password.
Then they dumped the process's memory. The report calls this straightforward, because the program runs inside the Java Virtual Machine (JVM), a layer that runs Java programs and keeps their memory in a predictable, inspectable layout. The tool for the job was jmap. Loading the resulting memory dump into a Java memory analyzer and querying it for the object they had identified produced the credentials in plain text:

The plaintext credentials were recovered from the memory dump. This is a classic lesson: encrypting a secret in transit or at rest does not help if the program must eventually hold the decrypted secret in its own memory, and anyone who can read that memory can read the secret.
With working credentials in hand, the researchers probed the RabbitMQ instance for misconfigured permissions. A message queue has its own permission system: each user can be allowed to read from certain queues and write to others. They looked for two specific kinds of mistake: read access to shared event queues (which would let them spy on other customers' events) and write access to configuration queues (which would let them change how the system behaves). They found nothing. The management interface of RabbitMQ, a web page for administering the broker, was closed as well. The broker itself looked properly locked down.
So attention turned to the application that reads from the queue: the dashboard program on the other side of the conveyor belt.
Step 2: send a normal event and watch it
Before tampering with anything, the researchers established a baseline. They generated a standard event on the endpoint and watched it appear at the backend dashboard. A baseline is what a scientist calls the control group: you first confirm what normal looks like, so that later you can tell exactly what your changes did.
The goal was to modify the event's values while it was in transit, between the endpoint and the dashboard. But the message sent to the queue was packed in a way that made reproducing it by hand difficult. The message was packed in a way that made reproducing it difficult. To reproduce it, the researchers needed to see exactly how the production program builds it. That meant debugging the production JAR on the remote server and copying the routines and data involved.
Step 3: switch on a remote debug server
The JAR was started by an init.d script. An init.d script is a startup script that the operating system runs when the machine boots, to launch a service. The researchers edited that script to add a Java debug server on port 5005, by adding this parameter to the command line:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
Line by line, this is one long instruction to the Java Virtual Machine, made of several settings separated by commas:
-agentlib:jdwptells Java to load a built-in agent called JDWP, the Java Debug Wire Protocol. This is the part of Java that lets an external debugger attach to a running program.transport=dt_socketsays the debugger will connect over a network socket, rather than, say, a serial cable.server=ysays this program should act as the server: it waits for a debugger to connect to it, instead of dialling out to one.suspend=nsays do not pause the program at startup while waiting for a debugger. Withsuspend=y, the service would freeze until someone attached, which on a production server would be an outage.address=5005says listen on TCP port 5005.
This turns on the JDWP debug agent, listens on TCP port 5005, does not suspend the JVM at startup and accepts connections over a socket transport. The port was then tunnelled through the existing SSH session. A tunnel here means carrying one network connection inside another: the researchers' machine talks to the SSH server, and the SSH server forwards the traffic onward to port 5005 on the remote host. That let them connect to the debug server on the remote machine as if it were local.
Step 4: pause, copy, reproduce
A breakpoint is a marker you put on a line of code that tells the debugger: stop the program here and let me look around. The researchers placed a breakpoint right before the event was sent. When the program hit that line, it froze, and they could inspect every variable in scope: the message being built, the parameters going into it, the helper routines that shaped it.
Through what the report calls a slow and sometimes agonizing process, they copied the relevant parameters and routines into a basic Java program of their own:

Copying the routines into their own program meant they could now build messages exactly the way the real aggregator does, but with whatever values they liked. That gave them complete control over the event's parameters.
Step 5: inject events as other customers
Shortly afterwards, the researchers found that the dashboard application was not verifying some of the event's parameters against the RabbitMQ user used to deliver them. In plain terms: the conveyor belt knows who put each box on it, because each sender has its own username and password. But the machine at the other end was not checking the label inside the box against that sender. It simply believed whatever the box said about who sent it.
For instance, they could inject events under the name of other customers. The report does not list the individual parameters involved. This is a trust problem: the receiving application trusted data inside the message without tying it to the identity of the authenticated sender.
Why it worked
The broker itself was not the weak point. Permissions were not misconfigured, and the management interface was closed. The flaw sat in the dashboard application that consumes the queue. It trusted parameters carried inside the event without checking them against the identity of the RabbitMQ user that delivered the message. So a producer holding valid broker credentials could set those parameters to values belonging to another customer. The report does not describe the exact check that was missing.
What it means
An attacker who has already compromised an event aggregator server, and can therefore reach the broker and obtain its credentials, can inject events under the name of other customers. The report frames this as the conclusion of the exercise and notes that the backend systems were mostly out of the test's scope, so the wider consequences were not explored.
How to fix it
The report does not state what was changed. Based on the finding, the dashboard application should validate the event's parameters against the RabbitMQ user that delivered the message, so that a producer cannot set fields identifying another customer.
Variants to test
- Credential retrieval from memory. On any Java service that fetches secrets dynamically, dump the heap with
jmapand query it for the connection object. A positive result is plaintext credentials for a backend service in the dump. - Broker permission review. With obtained AMQP credentials, try reading shared queues and writing to configuration queues. A positive result is access to queues that belong to other tenants or to administrative functions.
- Message field trust. Publish an event with fields naming a different customer and see whether the dashboard accepts it. A positive result is the event appearing under the other customer's name.
- Debug agent exposure. Check whether production JARs are started with a JDWP agent and whether the port is reachable, directly or through a tunnel. A positive result is an attachable debugger on the production process.
- Producer identity binding. For each field in the message, change it to a value belonging to another tenant and observe whether the consumer rejects it. A positive result is any field that is accepted without being tied to the authenticated producer.
Glossary
- AMQP: the standard protocol that message queues like RabbitMQ speak; the agreed format for putting boxes on and taking boxes off the conveyor belt.
- Baseline: a normal, unmodified observation taken first, so that later changes can be compared against it.
- Black box testing: testing a system from the outside without knowledge of its internals, like trying to open a locked box with no key or manual.
- Breakpoint: a marker placed on a line of code that makes a debugger pause the program there so its state can be inspected.
- Credentials: a username and password (or similar proof) that a program uses to identify itself to another service.
- Dashboard: the web page where the collected events are shown to the user.
- Debug server: a feature that lets an external debugger attach to a running program, pause it and inspect its variables.
- Endpoint agent: a small program installed on an employee's computer that reports events to a central server.
- Event: a single report of something that happened, sent from an endpoint to the aggregator.
- Event aggregator: the cloud server that collects events from endpoints, analyses them and presents them.
- init.d script: a startup script the operating system runs at boot to launch a service.
- JAR file: Java's version of a zip archive, bundling a Java program and its parts into one file.
- Java memory analyzer: a tool that lets you search inside a snapshot of a Java program's memory.
- Java Virtual Machine (JVM): the layer that runs Java programs and manages their memory.
- JDWP: the Java Debug Wire Protocol, the built-in mechanism that lets a debugger attach to a running Java program.
- jmap: a tool that takes a snapshot (dump) of a running Java program's memory.
- Message queue: software that lets one program put messages onto a belt and another take them off, without talking directly.
- netstat: a command that lists the network connections open on a machine and the programs behind them.
- Object: in Java, a bundle of data and code representing one thing, such as a connection with its settings.
- Port: a numbered door on a computer that a network service listens behind; RabbitMQ's default is 5672.
- Port scan: asking a computer, one numbered door at a time, whether anything is listening behind it.
- RabbitMQ: a popular message queue product that speaks AMQP.
- Root-capable user: an account that can become the all-powerful administrator on a machine.
- SSH: a way to open a secure text terminal on another computer over the network.
- Tunnel: carrying one network connection inside another, so traffic to a remote port can be reached as if it were local.
- Trust problem: when a receiving program believes data inside a message without checking it against who actually sent it.