# burpheart/hachimi architecture

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

- Interactive diagram: https://gitdiagram.com/burpheart/hachimi
- Repository: https://github.com/burpheart/hachimi

## Overview

##### Main Components
- Honeypot (POT) nodes: These are deployed across the network to listen for various protocols using elements in pkg/emulation. They simulate responses for protocols such as HTTP (including plugin support via yaegi), TLS, SSH, and REDIS.
- Message Queue (NSQ): Acts as the intermediary hub that receives logs and traffic data from the honeypot nodes and forwards them to the analysis (hunter) nodes.
- Analysis Nodes (hunter): These nodes process the received data, perform protocol-specific analysis (leveraging pkg/analysis, pkg/rules, etc.), and prepare it for storage.
- Management Platform (BeeKeeper): Provides an interface for monitoring and management of the honeypot network.
- Data Storage (Clickhouse): Stores analyzed data for later visualization and further analysis.
- Ancillary Services: Additional components like configuration management (pkg/config), ingress/transparent proxy handling (pkg/ingress), plugins (pkg/plugin), and distributed session handling/emulation modules.

##### File Structure for Architectural Insights
- The cmd/ directory hosts the main executables:
– cmd/beekeeper: The management UI for overseeing the honeypot network.
– cmd/honeypot: The executable for the honeypot nodes.
– cmd/hunter: The executable for analysis nodes.
- The pkg/ directory is structured into modules such as analysis, config, emulation (divided by protocols like HTTP, TLS, SSH, REDIS, etc.), ingress, logger, mq, plugin, and rules. This indicates a modular design where discrete functionalities are encapsulated by protocol or role.
- There are also helper tools and testing directories that support development and deployment, with deployment documentation in docs/deploy.md.

- NSQ (Message Queue): Place a central intermediary component to route data between nodes.
- BeeKeeper (Management Platform): Position as an orchestration and monitoring console.
- Clickhouse (Database): Represent the data storage service.
- External Plugin System & Emulation Modules: Optionally add annotations to the POT nodes to indicate integrated plugin support and protocol-specific emulation (HTTP, TLS, etc.).
– Data flows from multiple POT nodes to the NSQ queue.
– NSQ forwards data to one or multiple hunter nodes.
– Processed results are then stored to Clickhouse.
– BeeKeeper interacts with Clickhouse for data visualization and system management.
- External elements or notes to indicate integration with additional deployment scripts (e.g., iptables.sh from tool) and configuration management through TOML files (e.g., config.toml, hunter.toml).

##### Architectural Patterns and Design Principles
- Modular Design: The separation into packages (emulation, analysis, ingress, logger, etc.) hints at a clean, modular design that separates concerns.
- Distributed Architecture: The system is designed to operate in a distributed manner across multiple nodes (POT, hunter) with a central messaging system (NSQ).
- Extensibility: The use of a plugin system (via yaegi) enables dynamic extension of HTTP functionalities without restarting the services.
- Protocol-agnostic Handling: By modularizing protocol handling (each protocol has its own emulation and logging modules), the system can be easily extended to support additional protocols in the future.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Ingestion Layer
    subgraph "Data Ingestion"
        subgraph "POT Node – Protocol Emulation"
            potExec["Honeypot Executable"]:::pot
            http["HTTP Emulation"]:::pot
            tls["TLS Emulation"]:::pot
            ssh["SSH Emulation"]:::pot
            redis["REDIS Emulation"]:::pot
        end
    end

    %% Message Transportation Layer
    subgraph "Message Transportation"
        subgraph "NSQ Message Queue"
            nsqQueue["NSQ Message Queue"]:::nsq
            nsq_msg["Messaging Utils"]:::nsq
            nsq_log["NSQ Logging"]:::nsq
            nsq_conf["NSQ Configuration"]:::nsq
        end
    end

    %% Data Analysis Layer
    subgraph "Data Analysis"
        subgraph "Analysis Nodes"
            analysisHandler["Analysis Handler"]:::hunter
            hunterExec["Hunter Executable"]:::hunter
            httpAnalysis["HTTP Analysis"]:::hunter
            sessionAnalysis["Session Analysis"]:::hunter
        end
    end

    %% Management & Storage Layer
    subgraph "Management & Storage"
        beekeep["BeeKeeper Management"]:::management
        clickhouse["Clickhouse Database"]:::storage
    end

    %% Ancillary Services
    subgraph "Ancillary Services"
        configMgmt["Configuration Management"]:::ancillary
        configFile["config.toml"]:::ancillary
        hunterConfig["hunter.toml"]:::ancillary
        ingress["Ingress Proxy Handling"]:::ancillary
        plugin["Plugin System"]:::ancillary
    end

    %% Data Flow Connections
    http --> potExec
    tls  --> potExec
    ssh  --> potExec
    redis --> potExec

    potExec --> nsqQueue

    nsq_msg --> nsqQueue
    nsq_log --> nsqQueue
    nsq_conf --> nsqQueue

    nsqQueue -->|"data"| analysisHandler

    analysisHandler --> hunterExec
    hunterExec -->|"processed data"| clickhouse
    httpAnalysis --> clickhouse
    sessionAnalysis --> clickhouse

    beekeep -->|"visualizes"| clickhouse

    %% Ancillary dotted connections
    configMgmt -.-> potExec
    configMgmt -.-> nsqQueue
    configMgmt -.-> analysisHandler
    configMgmt -.-> beekeep

    configFile --> configMgmt
    hunterConfig --> configMgmt

    ingress -.-> potExec
    plugin -.-> potExec

    %% Click Events
    click potExec "https://github.com/burpheart/hachimi/blob/main/cmd/honeypot/main.go"
    click http "https://github.com/burpheart/hachimi/tree/main/pkg/emulation/http"
    click tls "https://github.com/burpheart/hachimi/tree/main/pkg/emulation/tls"
    click ssh "https://github.com/burpheart/hachimi/tree/main/pkg/emulation/ssh"
    click redis "https://github.com/burpheart/hachimi/tree/main/pkg/emulation/redis"
    click nsq_msg "https://github.com/burpheart/hachimi/blob/main/pkg/mq/utils.go"
    click nsq_log "https://github.com/burpheart/hachimi/blob/main/pkg/logger/nsq.go"
    click nsq_conf "https://github.com/burpheart/hachimi/blob/main/pkg/config/mq.go"
    click analysisHandler "https://github.com/burpheart/hachimi/blob/main/pkg/analysis/handler.go"
    click hunterExec "https://github.com/burpheart/hachimi/blob/main/cmd/hunter/main.go"
    click httpAnalysis "https://github.com/burpheart/hachimi/blob/main/pkg/analysis/model/http.go"
    click sessionAnalysis "https://github.com/burpheart/hachimi/blob/main/pkg/analysis/model/session.go"
    click beekeep "https://github.com/burpheart/hachimi/blob/main/cmd/beekeeper/main.go"
    click configMgmt "https://github.com/burpheart/hachimi/tree/main/pkg/config"
    click configFile "https://github.com/burpheart/hachimi/blob/main/config.toml"
    click hunterConfig "https://github.com/burpheart/hachimi/blob/main/hunter.toml"
    click ingress "https://github.com/burpheart/hachimi/tree/main/pkg/ingress"
    click plugin "https://github.com/burpheart/hachimi/tree/main/pkg/plugin"

    %% Styles
    classDef pot fill:#F4A261,stroke:#000,stroke-width:2px;
    classDef nsq fill:#2A9D8F,stroke:#000,stroke-width:2px;
    classDef hunter fill:#E76F51,stroke:#000,stroke-width:2px;
    classDef management fill:#264653,stroke:#000,stroke-width:2px;
    classDef storage fill:#E9C46A,stroke:#000,stroke-width:2px;
    classDef ancillary fill:#A8DADC,stroke:#000,stroke-width:2px;
```
