# pwnlandia/mhn architecture

> Architecture diagram of the GitHub repository pwnlandia/mhn, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pwnlandia/mhn
- Repository: https://github.com/pwnlandia/mhn

## Overview

##### Project Type and Purpose
- This is a full-stack, server-centric honeypot management and data-collection platform (“Modern Honey Network” or MHN).

##### High-Level Architectural Components
a. Sensor Layer (“Honeypots”)
- Deployed sensors (Dionaea, Cowrie, Snort, etc.) run remote scripts (in `scripts/deploy_*.sh`).
- They register with the MHN server via the HTTP API and/or hpfeeds protocol to send events/logs.
b. Ingress/API Layer
- Nginx (or another web proxy) sits at the front, routing requests to:
- uWSGI-hosted Flask app (the main `server/mhn` code).
- Raw collector endpoints (`collector.py`, `collector_v2.py`).
c. Application Layer
- Flask application exposes RESTful endpoints (`mhn/api/views.py`) and renders the UI (`mhn/ui/views.py`).
- Background workers:
- Celery (tasks in `mhn/tasks`) handles periodic jobs (e.g., rule updates, geolocation).
- Supervisor orchestrates processes: hpfeeds-broker, honeymap, geoloc, mhn-collector, mhn-uwsgi, Celery beat/worker, mnemosyne.
d. Data Layer
- Primary datastore: MongoDB (configured via `initdatabase.py`, `requirements.txt`).
- hpfeeds message broker stores incoming honeypot events in-memory and feeds them into the collector.
e. External Integrations
- Splunk/ArcSight loggers (`install_hpfeeds-logger-*.sh`) subscribe to hpfeeds and forward to SIEMs.
- Honeymap visualization service (runs on port 3000).
- Optional email provider (SMTP) for password resets and alerts.

##### Relationships and Data Flows
- Deployment: Admin UI → Flask API → Deploy script URL → Sensor
- Registration & Logs: Sensor → HTTP or hpfeeds → hpfeeds-broker → mhn-collector → MongoDB
- Rule Distribution: Flask API → Sensor (on request)
- Background Processing: Celery workers process raw events, update rule sets, perform geolocation, and write enriched data back to MongoDB.
- UI Requests: Browser → Nginx → uWSGI Flask → MongoDB → JSON/views → Browser
- External SIEM: hpfeeds-logger → Splunk/ArcSight

##### Key Architectural Patterns and Principles
- Layered architecture (Ingress/API → Application logic → Persistence → External integrations)
- Asynchronous processing via message queue (hpfeeds) and task queue (Celery)
- Process supervision (Supervisor, Docker entrypoint)
- Configuration via templates (`config.py.template`, environment variables for Docker)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Sensor Layer
    subgraph "Sensor Layer" 
        direction TB
        AMUN["Amun Sensor"]:::network
        CONPOT["Conpot Sensor"]:::network
        SURICATA["Suricata Sensor"]:::network
    end

    %% Ingress / Proxy
    NGINX["Nginx / Proxy"]:::network

    %% Collector Endpoints
    subgraph "Raw Collectors"
        direction TB
        COL1["collector.py"]:::compute
        COL2["collector_v2.py"]:::compute
    end

    %% Application Layer
    subgraph "Flask App (uWSGI)" 
        direction TB
        INIT["__init__.py"]:::compute
        API["api/views.py"]:::compute
        UI["ui/views.py"]:::compute
        AUTH["auth/"]:::compute
        COMMON["common/"]:::compute
        STATIC["static/"]:::compute
        TEMPLATES["templates/"]:::compute
    end

    %% Background & Supervisor
    subgraph "Supervisor & Workers"
        direction TB
        CELERY["Celery tasks"]:::compute
        SUPERVISOR["supervisord & entrypoint"]:::compute
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        HPF["hpfeeds Broker"]:::data
        MONGO["MongoDB"]:::data
    end

    %% External Integrations
    subgraph "External Systems"
        direction TB
        SIEM["SIEM Loggers"]:::external
        HMAP["Honeymap Service"]:::external
        EMAIL["Email Service"]:::external
    end

    %% Browser
    Browser["Browser UI"]:::ui

    %% Connections
    AMUN -->|HTTP / hpfeeds| NGINX
    CONPOT -->|HTTP / hpfeeds| NGINX
    SURICATA -->|HTTP / hpfeeds| NGINX

    NGINX -->|uWSGI HTTP| INIT
    NGINX -->|raw HTTP| COL1
    NGINX -->|raw HTTP| COL2

    COL1 -->|hpfeeds| HPF
    COL2 -->|hpfeeds| HPF

    HPF -->|"feed events"| MONGO
    HPF -->|consume| CELERY

    INIT -->|calls| MONGO
    API -->|REST API| MONGO
    UI -->|renders| Browser

    CELERY -->|reads/writes| MONGO
    SUPERVISOR -->|manages| HPF
    SUPERVISOR -->|manages| CELERY

    SIEM -->|subscribe hpfeeds| HPF
    HMAP -->|visualize| MONGO
    EMAIL -->|SMTP| Browser

    Browser -->|HTTP| NGINX

    %% Click Events
    click AMUN "https://github.com/pwnlandia/mhn/blob/master/scripts/deploy_amun.sh"
    click CONPOT "https://github.com/pwnlandia/mhn/blob/master/scripts/deploy_conpot.sh"
    click SURICATA "https://github.com/pwnlandia/mhn/blob/master/scripts/deploy_suricata.sh"
    click NGINX "https://github.com/pwnlandia/mhn/blob/master/scripts/proxy/proxy-iptables-rules.sh"
    click COL1 "https://github.com/pwnlandia/mhn/blob/master/server/collector.py"
    click COL2 "https://github.com/pwnlandia/mhn/blob/master/server/collector_v2.py"
    click INIT "https://github.com/pwnlandia/mhn/blob/master/server/mhn/__init__.py"
    click API "https://github.com/pwnlandia/mhn/blob/master/server/mhn/api/views.py"
    click UI "https://github.com/pwnlandia/mhn/blob/master/server/mhn/ui/views.py"
    click AUTH "https://github.com/pwnlandia/mhn/tree/master/server/mhn/auth/"
    click COMMON "https://github.com/pwnlandia/mhn/tree/master/server/mhn/common/"
    click STATIC "https://github.com/pwnlandia/mhn/tree/master/server/mhn/static/"
    click TEMPLATES "https://github.com/pwnlandia/mhn/tree/master/server/mhn/templates/"
    click CELERY "https://github.com/pwnlandia/mhn/blob/master/server/mhn/tasks/rules.py"
    click SUPERVISOR "https://github.com/pwnlandia/mhn/blob/master/scripts/docker_supervisord-mhn.conf"
    click SUPERVISOR "https://github.com/pwnlandia/mhn/blob/master/scripts/docker_entrypoint.sh"
    click HPF "https://github.com/pwnlandia/mhn/blob/master/server/mhn/static/hpfeeds.py"
    click MONGO "https://github.com/pwnlandia/mhn/blob/master/server/initdatabase.py"
    click SIEM "https://github.com/pwnlandia/mhn/blob/master/scripts/install_hpfeeds-logger-splunk.sh"
    click SIEM "https://github.com/pwnlandia/mhn/blob/master/scripts/install_hpfeeds-logger-arcsight.sh"
    click SIEM "https://github.com/pwnlandia/mhn/blob/master/scripts/install_hpfeeds-logger-json.sh"
    click HMAP "https://github.com/pwnlandia/mhn/blob/master/scripts/install_honeymap.sh"
    click HMAP "https://github.com/pwnlandia/mhn/blob/master/server/mhn/templates/ui/honeymap.html"
    click EMAIL "https://github.com/pwnlandia/mhn/blob/master/server/manual_password_reset.py"
    click EMAIL "https://github.com/pwnlandia/mhn/blob/master/server/mhn/templates/auth/reset-email.html"

    %% Styles
    classDef network fill:#D0E6FA,stroke:#0366D6,color:#0366D6
    classDef compute fill:#E6F4EA,stroke:#28A745,color:#155724
    classDef data fill:#FFF4CE,stroke:#FFC107,color:#856404
    classDef external fill:#FFEFE6,stroke:#FD7E14,color:#7A3500
    classDef ui fill:#F0F0F0,stroke:#6C757D,color:#343A40
```
