Skip to content

Commit 5508d4f

Browse files
authored
Merge pull request #2171 from HackTricks-wiki/update_HTB__Sorcery_20260425_184956
HTB Sorcery
2 parents 08d5e84 + c766d72 commit 5508d4f

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/network-services-pentesting/5671-5672-pentesting-amqp.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,40 @@ for method, props, body in ch.consume('loot', inactivity_timeout=5):
139139

140140
Swap the routing key for `audit.#` or `payments.*` to focus on sensitive flows, then republish forged messages by flipping `basic_publish` arguments—handy for replay attacks against downstream microservices.
141141

142+
### Consumer-side command injection (message bus -> RCE)
143+
144+
Treat every message broker as a potential **code-delivery primitive** when downstream consumers turn message data into shell commands, SQL, template input, or config updates. The critical anti-pattern is a worker that reads attacker-controlled content from a queue/topic and feeds it into a shell, for example `bash -c "$MESSAGE"`, `sh -c`, `os.system`, `subprocess(..., shell=True)`, `Runtime.exec`, or `Command::new("bash").arg("-c").arg(message)`.
145+
146+
Typical exploitation chain:
147+
148+
1. Gain **publish capability** to a queue/topic:
149+
- Direct broker access with weak/default credentials or no auth
150+
- Access to an HTTP publish feature such as RabbitMQ Management `POST /api/exchanges/%2F/<exchange>/publish`
151+
- SSRF into an internal broker or debug endpoint that can speak raw TCP to the broker
152+
- Compromise of any producer service that already writes to the target queue/topic
153+
2. **Locate the sink** in source/config:
154+
- Workers calling shells after deserializing messages
155+
- "task runners" that accept commands over the queue
156+
- Consumers that rebuild config files and then execute hooks/reload scripts
157+
3. Publish a **benign probe** first (`id`, `whoami`, `uname -a`) to confirm execution without destroying the worker
158+
4. Upgrade to a reverse shell or data theft once the execution path is confirmed
159+
160+
Things to look for during source review:
161+
162+
- Consumer groups named `update`, `jobs`, `tasks`, `commands`, `hooks`, `admin`, `dns`, or `sync`
163+
- Supervisor/systemd entries launching both a broker consumer and a privileged helper in the same container
164+
- Log lines showing a worker executes each message and then republishes results to a second queue/topic
165+
166+
Example RabbitMQ publish through the management API:
167+
168+
```bash
169+
curl -u user:pass -H 'content-type: application/json' \
170+
-X POST http://TARGET:15672/api/exchanges/%2F/amq.default/publish \
171+
-d '{"properties":{},"routing_key":"update","payload":"id","payload_encoding":"string"}'
172+
```
173+
174+
The same pattern appears outside AMQP. In Kafka, once you can reach the broker and craft a valid **Produce** request for the attacker-controlled topic, any consumer that forwards the message body to `bash -c` becomes an RCE sink. If the only reachable primitive is SSRF, check whether it can send **raw TCP bytes** or follow a `gopher://` redirect so you can still speak the broker protocol.
175+
142176
## Other RabbitMQ ports
143177

144178
In [https://www.rabbitmq.com/networking.html](https://www.rabbitmq.com/networking.html) you can find that **rabbitmq uses several ports**:
@@ -172,5 +206,7 @@ In [https://www.rabbitmq.com/networking.html](https://www.rabbitmq.com/networkin
172206
- [CVE-2024-51988 – RabbitMQ HTTP API queue deletion bug](https://www.cve.news/cve-2024-51988/)
173207
- [GHSA-gh3x-4x42-fvq8 – RabbitMQ logs Authorization header](https://github.com/rabbitmq/rabbitmq-server/security/advisories/GHSA-gh3x-4x42-fvq8)
174208
- [rabbitmqadmin v2 (rabbitmqadmin-ng)](https://github.com/rabbitmq/rabbitmqadmin-ng)
209+
- [Apache Kafka Protocol Guide](https://kafka.apache.org/41/design/protocol/)
210+
- [HTB: Sorcery](https://0xdf.gitlab.io/2026/04/25/htb-sorcery.html)
175211

176212
{{#include ../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)