# vanhauser-thc/thc-hydra architecture

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

- Interactive diagram: https://gitdiagram.com/vanhauser-thc/thc-hydra
- Repository: https://github.com/vanhauser-thc/thc-hydra

## Overview

##### Main Components
- User Interfaces:
- Command Line Interface: Represents the entry point where users supply parameters (target, protocol, logins, passwords, etc.).
- GTK GUI (xhydra): A separate UI component in the hydra-gtk directory for Linux desktop users.
- Core Engine:
- Responsible for parsing arguments (via the “configure” script and Makefiles), managing the overall session, including session restore from “hydra.restore,” and coordinating attacks.
- Implements the central scheduling and parallelization (using the task count parameter “-t”) to manage concurrent connection attempts.
- Module Engine:
- A modular design where each file (e.g., hydra-ftp.c, hydra-ssh.c, hydra-http.c, etc.) implements a specific protocol’s attack logic.
- These modules are integrated with the core engine. They take in parameters from the input, perform protocol-specific network interactions, and report success or failure.
- Crypto/Support Libraries:
- Contains crypto and checksum routines (e.g., crc32.c, d3des.c, hmacmd5.c, ntlm.c) which are used by various modules to implement secure and protocol-specific operations.
- Output Manager:
- Handles the reporting of results to the console (stdout) or to a file (with text or JSON format as described in the readme).
- Manages error reporting (via error message arrays in the JSON results).

##### Relationships and Interactions
- Data Flow begins at the User Interface (either command-line or GTK) where parameters are gathered. These are fed to the Core Engine.
- The Core Engine orchestrates the attack flow and dispatches work to the Module Engine.
- The Module Engine then calls out to the appropriate protocol module based on the user-selected protocol.
- Each module uses the underlying network layer (sockets, built-in parallelization) and crypto routines when performing authentication attempts.
- Results from each module are returned to the Core Engine, then passed on to the Output Manager for presentation.
- Logging, error handling, and support functions (like session restoration) are also part of the Core Engine.

##### Architectural Patterns and Design Principles
- Modular Design: Each protocol is implemented as its own module—making it easier to add or enhance new protocols.
- Separation of Concerns: There is a clear division between the UI (CLI/GUI), core scheduling and control, protocol-specific module logic, and supporting libraries.
- Parallelization: The system employs concurrent processing (thread/task pool) to speed up connection attempts.

##### Technologies and Frameworks
- C as the programming language, using tools like autoconf/automake for configuration.
- GTK+ for the graphical interface, found in the hydra-gtk directory with associated Glade files (xhydra.glade).
- Standard UNIX build tools (Makefile, configure, Dockerfile for containerization) are provided.

- Clear labels for each component, such as “User Input (CLI/GTK)”, “Core Execution Engine”, “Protocol Modules” (listing examples: SSH, FTP, HTTP, etc.), “Parallel Task Manager”, and “Crypto/Helper Libraries.”
- External dependencies like system libraries (libssl, libssh, etc.) used for optional modules.

##### Additional Details
- Explicitly note that the core design accommodates both an interactive mode (xhydra) and a scripted command line mode.
- That the tool’s high modularity and extensibility (e.g., “module engine for new services”) is a key architectural element.
- Annotating configuration files (configure, Makefile.am, etc.) as part of the build and deployment pipeline, showing how the application is compiled and deployed (including Docker support).

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interfaces
    subgraph "User Interfaces"
        CLI["Command Line Interface"]:::ui
        GTK["GTK GUI (xhydra)"]:::ui
    end

    %% Core Components
    subgraph "Core Components"
        CORE["Core Engine"]:::core
        OUTPUT["Output Manager"]:::output
    end

    %% Module Engine
    subgraph "Module Engine"
        MODULE["Protocol Modules"]:::module
        MODULE_FTP["FTP Module"]:::moduleSub
        MODULE_SSH["SSH Module"]:::moduleSub
        MODULE_HTTP["HTTP Module"]:::moduleSub
        MODULE_HTTP_FORM["HTTP-Form Module"]:::moduleSub
        MODULE_SMB["SMB Module"]:::moduleSub
        MODULE_IMAP["IMAP Module"]:::moduleSub
        MODULE_SMTP["SMTP Module"]:::moduleSub
    end

    %% Supporting Libraries
    subgraph "Supporting Libraries"
        CRYPTO["Crypto/Support Libraries"]:::crypto
    end

    %% Relationships
    CLI -->|"SupplyParameters"| CORE
    GTK -->|"SupplyParameters"| CORE
    CORE -->|"DispatchModules"| MODULE
    MODULE -->|"UsesCryptoAndParallelTasks"| CRYPTO
    MODULE -->|"ReturnResults"| CORE
    CORE -->|"PresentResults"| OUTPUT

    %% Module breakdown connections
    MODULE --> MODULE_FTP
    MODULE --> MODULE_SSH
    MODULE --> MODULE_HTTP
    MODULE --> MODULE_HTTP_FORM
    MODULE --> MODULE_SMB
    MODULE --> MODULE_IMAP
    MODULE --> MODULE_SMTP

    %% Click Events for User Interfaces
    click CLI "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra.c"
    click CLI "https://github.com/vanhauser-thc/thc-hydra/tree/master/configure"
    click CLI "https://github.com/vanhauser-thc/thc-hydra/tree/master/Makefile"
    click CLI "https://github.com/vanhauser-thc/thc-hydra/blob/master/Makefile.am"
    
    click GTK "https://github.com/vanhauser-thc/thc-hydra/tree/master/hydra-gtk"
    click GTK "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra-gtk/src/main.c"
    click GTK "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra-gtk/xhydra.glade"

    %% Click Events for Core Engine
    click CORE "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra.c"
    click CORE "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra-mod.c"
    click CORE "https://github.com/vanhauser-thc/thc-hydra/tree/master/configure"
    click CORE "https://github.com/vanhauser-thc/thc-hydra/tree/master/Makefile"
    click CORE "https://github.com/vanhauser-thc/thc-hydra/blob/master/Makefile.am"
    click CORE "https://github.com/vanhauser-thc/thc-hydra/blob/master/Makefile.unix"
    
    %% Click Events for Module Engine
    click MODULE_FTP "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra-ftp.c"
    click MODULE_SSH "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra-ssh.c"
    click MODULE_HTTP "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra-http.c"
    click MODULE_HTTP_FORM "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra-http-form.c"
    click MODULE_SMB "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra-smb.c"
    click MODULE_IMAP "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra-imap.c"
    click MODULE_SMTP "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra-smtp.c"
    click MODULE "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra-mod.h"
    
    %% Click Events for Crypto/Support Libraries
    click CRYPTO "https://github.com/vanhauser-thc/thc-hydra/blob/master/crc32.c"
    click CRYPTO "https://github.com/vanhauser-thc/thc-hydra/blob/master/crc32.h"
    click CRYPTO "https://github.com/vanhauser-thc/thc-hydra/blob/master/d3des.c"
    click CRYPTO "https://github.com/vanhauser-thc/thc-hydra/blob/master/d3des.h"
    click CRYPTO "https://github.com/vanhauser-thc/thc-hydra/blob/master/hmacmd5.c"
    click CRYPTO "https://github.com/vanhauser-thc/thc-hydra/blob/master/hmacmd5.h"
    click CRYPTO "https://github.com/vanhauser-thc/thc-hydra/blob/master/ntlm.c"
    click CRYPTO "https://github.com/vanhauser-thc/thc-hydra/blob/master/ntlm.h"
    
    %% Click Events for Output Manager
    click OUTPUT "https://github.com/vanhauser-thc/thc-hydra/blob/master/hydra.1"

    %% Styles
    classDef ui fill:#dff0d8,stroke:#3c763d,stroke-width:2px;
    classDef core fill:#d9edf7,stroke:#31708f,stroke-width:2px;
    classDef module fill:#fcf8e3,stroke:#8a6d3b,stroke-width:2px;
    classDef moduleSub fill:#faf2cc,stroke:#c09853,stroke-width:2px;
    classDef crypto fill:#f2dede,stroke:#a94442,stroke-width:2px;
    classDef output fill:#d9edf7,stroke:#31708f,stroke-width:2px;
```
