# joe-desimone/mongobleed architecture

> Architecture diagram of the GitHub repository joe-desimone/mongobleed, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/joe-desimone/mongobleed
- Repository: https://github.com/joe-desimone/mongobleed

## Overview

#### Purpose and Entry Points

`mongobleed.py` is a Python proof-of-concept scanner for CVE-2025-14847, targeting vulnerable MongoDB servers that accept unauthenticated wire-protocol connections. Its CLI is the primary entry point; it accepts target host/port, probe-length range, and output file parameters.

The local test environment starts through `docker-compose.yml`, then the scanner connects to that MongoDB instance.

#### Exploit Scanner

`mongobleed.py` owns the end-to-end attack workflow:

- Opens a direct network connection to MongoDB.
- Constructs malformed compressed MongoDB messages containing BSON with attacker-controlled inflated length claims.
- Iterates configured document-length offsets to alter where uninitialized memory is interpreted as BSON field-name data.
- Receives and parses server responses for leaked fragments.
- Deduplicates, reports, and writes recovered bytes to the configured output file.

Path: `mongobleed.py`

#### MongoDB Wire-Protocol Boundary

The scanner operates below normal MongoDB client APIs, communicating directly with the MongoDB server’s binary wire protocol. The critical boundary is the compressed-message/decompression path on the remote server: a claimed uncompressed size drives allocation, while the vulnerable server later treats the full allocated region as valid BSON input.

Path: `mongobleed.py`

#### Probe and Leak Extraction Stage

Each probe uses a selected BSON/document length within the `--min-offset` to `--max-offset` range. The remote parser reads beyond actual decompressed content until null terminators are encountered, so separate offsets can expose different memory regions. The scanner aggregates useful decoded fragments and tracks total leaked bytes and unique fragments.

Path: `mongobleed.py`

#### Output Persistence

Recovered memory is surfaced in console findings and persisted as a binary artifact, defaulting to `leaked.bin`. This output is intentionally separate from the scanner’s transient request/response processing and can contain arbitrary server-memory content.

Path: `mongobleed.py`

#### Local Vulnerable Target Infrastructure

`docker-compose.yml` defines the disposable MongoDB environment used to reproduce and validate the vulnerability locally. `init/init-mongo.js` is MongoDB initialization logic executed for that containerized test setup, establishing any seed state needed for meaningful memory-leak demonstrations.

Paths: `docker-compose.yml`, `init/init-mongo.js`

#### Runtime and External Dependencies

The operator runtime is Python 3 executing `mongobleed.py`. The target runtime is an affected MongoDB release, typically reached over TCP port 27017. Docker Compose provides local orchestration; the exploit itself depends on MongoDB’s server-side zlib decompression and BSON parsing behavior rather than a MongoDB driver or web service.

Main entry points: [`mongobleed.py`](https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py) (MongoDB TCP connection), [`docker-compose.yml`](https://github.com/joe-desimone/mongobleed/blob/main/docker-compose.yml) (Docker Compose), [`init/init-mongo.js`](https://github.com/joe-desimone/mongobleed/blob/main/init/init-mongo.js) (MongoDB initialization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_operator["Operator scanner"]
  node_cli["Scanner CLI<br/>entry point<br/>[mongobleed.py]"]
  node_python["Python 3<br/>runtime"]
  node_scanner["Attack workflow<br/>scanner<br/>[mongobleed.py]"]
  node_message_builder["Malformed message builder<br/>wire encoder<br/>[mongobleed.py]"]
  node_offset_probes["Offset probe loop<br/>probe stage<br/>[mongobleed.py]"]
  node_response_parser["Response parser<br/>leak extraction<br/>[mongobleed.py]"]
  node_fragment_store["Fragment aggregation<br/>deduplication<br/>[mongobleed.py]"]
  node_leaked_output["Recovered bytes<br/>binary artifact<br/>[mongobleed.py]"]
end

subgraph group_local_target["Local vulnerable target"]
  node_compose["Docker Compose<br/>local orchestration<br/>[docker-compose.yml]"]
  node_mongo_init["MongoDB initialization<br/>seed setup<br/>[init-mongo.js]"]
  node_mongodb[("Affected MongoDB server<br/>target runtime")]
end

subgraph group_remote_boundary["MongoDB vulnerability boundary"]
  node_decompression["zlib decompression allocation<br/>vulnerable stage"]
  node_bson_parser["BSON parser over-read<br/>vulnerable stage"]
end

node_tcp["MongoDB TCP connection<br/>network boundary<br/>[mongobleed.py]"]

node_python -->|"executes"| node_cli
node_cli -->|"configures"| node_scanner
node_scanner -->|"runs"| node_offset_probes
node_offset_probes -->|"selects length"| node_message_builder
node_message_builder -->|"sends compressed request"| node_tcp
node_tcp -->|"wire protocol"| node_mongodb
node_compose -->|"starts"| node_mongodb
node_mongo_init -->|"initializes"| node_mongodb
node_mongodb -->|"processes request"| node_decompression
node_decompression -->|"oversized allocation"| node_bson_parser
node_bson_parser -->|"returns leaked response"| node_tcp
node_tcp -->|"receives response"| node_response_parser
node_response_parser -->|"extracts fragments"| node_fragment_store
node_fragment_store -->|"reports and writes"| node_leaked_output

click node_cli "https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py"
click node_scanner "https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py"
click node_message_builder "https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py"
click node_offset_probes "https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py"
click node_tcp "https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py"
click node_response_parser "https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py"
click node_fragment_store "https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py"
click node_leaked_output "https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py"
click node_compose "https://github.com/joe-desimone/mongobleed/blob/main/docker-compose.yml"
click node_mongo_init "https://github.com/joe-desimone/mongobleed/blob/main/init/init-mongo.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_python,node_scanner,node_message_builder,node_offset_probes,node_response_parser,node_fragment_store,node_leaked_output toneBlue
class node_compose,node_mongo_init,node_mongodb toneAmber
class node_decompression,node_bson_parser toneMint
class node_tcp toneNeutral
```

## Components

### Operator scanner

- [Scanner CLI](https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py): entry point · Accepts target, offset range, and output parameters. · `mongobleed.py`
- **Python 3**: runtime
- [Attack workflow](https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py): scanner · Coordinates probing, extraction, reporting, and persistence. · `mongobleed.py`
- [Malformed message builder](https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py): wire encoder · Builds compressed MongoDB messages with inflated BSON length claims. · `mongobleed.py`
- [Offset probe loop](https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py): probe stage · Varies claimed document length across the configured range. · `mongobleed.py`
- [Response parser](https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py): leak extraction · Parses server responses for leaked BSON fragments. · `mongobleed.py`
- [Fragment aggregation](https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py): deduplication · Tracks unique fragments and total recovered bytes. · `mongobleed.py`
- [Recovered bytes](https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py): binary artifact · Console findings and binary memory-leak output, defaulting to leaked.bin. · `mongobleed.py`

### Local vulnerable target

- [Docker Compose](https://github.com/joe-desimone/mongobleed/blob/main/docker-compose.yml): local orchestration · Starts the disposable vulnerable MongoDB environment. · `docker-compose.yml`
- [MongoDB initialization](https://github.com/joe-desimone/mongobleed/blob/main/init/init-mongo.js): seed setup · Establishes test state for leak demonstrations. · `init/init-mongo.js`
- **Affected MongoDB server**: target runtime · Accepts unauthenticated wire-protocol connections.

### MongoDB vulnerability boundary

- **zlib decompression allocation**: vulnerable stage · Claimed uncompressed size drives allocation.
- **BSON parser over-read**: vulnerable stage · Treats the allocated region as valid BSON beyond actual decompressed content.

### Other components

- [MongoDB TCP connection](https://github.com/joe-desimone/mongobleed/blob/main/mongobleed.py): network boundary · Direct binary wire-protocol connection, typically port 27017. · `mongobleed.py`

## Connections

- Python 3 → Scanner CLI: executes
- Scanner CLI → Attack workflow: configures
- Attack workflow → Offset probe loop: runs
- Offset probe loop → Malformed message builder: selects length
- Malformed message builder → MongoDB TCP connection: sends compressed request
- MongoDB TCP connection → Affected MongoDB server: wire protocol
- Docker Compose → Affected MongoDB server: starts
- MongoDB initialization → Affected MongoDB server: initializes
- Affected MongoDB server → zlib decompression allocation: processes request
- zlib decompression allocation → BSON parser over-read: oversized allocation
- BSON parser over-read → MongoDB TCP connection: returns leaked response
- MongoDB TCP connection → Response parser: receives response
- Response parser → Fragment aggregation: extracts fragments
- Fragment aggregation → Recovered bytes: reports and writes
