# garrettfoster13/pre2k architecture

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

- Interactive diagram: https://gitdiagram.com/garrettfoster13/pre2k
- Repository: https://github.com/garrettfoster13/pre2k

## Overview

##### Project Type and Purpose
- Pre2k is a Python-based CLI security tool for red-team/pen-testing purposes. It queries Active Directory for pre-Windows 2000 computer objects and performs password sprays, optionally obtaining Kerberos TGTs.
- It is an open-source command-line utility, not a full-stack web app.

##### File Structure Analysis
- Top-level packaging:
- pyproject.toml, README.md, LICENSE.md, .github/ → CI and docs
- pre2k/__main__.py → CLI entrypoint (`python -m pre2k` or `pre2k` console script)
- pre2k/logger.py → centralized logging utility
- pre2k/lib/commands/
- auth.py → implements the “authenticated” password-spray command
- unauth.py → implements the “unauthenticated” enumeration + spray command
- pre2k/lib/
- ldap.py → LDAP client for null-bind and authenticated binds
- machine_hunter.py → logic to discover pre-2000 computer objects
- gettgt.py → Kerberos TGT retrieval and ccache writing
- pre_2k.py → core orchestrator combining modules above

##### README Insights
- Uses Poetry for dependency management
- Two main operational modes: unauthenticated (null-bind) vs authenticated
- Outputs TGT in `.ccache` format
- References to external services: LDAP/AD Domain Controller, Kerberos KDC

##### Main Components
a. CLI Layer (pre2k/__main__.py)
b. Command Dispatcher
– Commands: UnauthCommand, AuthCommand (pre2k/lib/commands)
c. Core Libraries
– LDAPClient (pre2k/lib/ldap.py)
– MachineHunter (pre2k/lib/machine_hunter.py)
– TGTFetcher (pre2k/lib/gettgt.py)
– Orchestrator (pre2k/lib/pre_2k.py)
– Logger (pre2k/logger.py)
d. External Systems
– Active Directory LDAP service
– Kerberos KDC
e. Local File System
– ccache file output

##### Relationships and Interactions
- User invokes CLI → argparse/Click parses mode → dispatches to AuthCommand or UnauthCommand
- UnauthCommand → LDAPClient performs null bind → MachineHunter enumerates computer objects → password spray attempts (via LDAPClient or RPC)
- AuthCommand → LDAPClient binds with credentials → MachineHunter enumerates/filters targets → optionally stop on first success → password spray
- Both modes can call TGTFetcher to request a Kerberos TGT → writes `.ccache` locally
- All modules log events via Logger

##### Architectural Patterns and Principles
- Command Pattern: separate command modules for different modes
- Layered Architecture: CLI → Command → Core Services → External Systems
- Single Responsibility: each module handles one concern (e.g., LDAP, TGT, hunting)
- Dependency Injection: Logger and LDAPClient passed into command handlers

##### Key Technologies and Libraries
- Python 3.x, Poetry (pyproject.toml)
- ldap3 or Impacket under the hood (in ldap.py)
- Kerberos libraries (e.g., Impacket’s KRB5) in gettgt.py
- CLI parsing (argparse or Click) in __main__.py
- File I/O for `.ccache` output

– LDAPClient → AD LDAP (cloud)

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User (CLI Invocation)"]:::external

    subgraph "CLI Layer"
        CLI["CLI Layer\n__main__.py"]:::internal
    end

    subgraph "Command Layer"
        Unauth["UnauthCommand\n(unauth.py)"]:::internal
        Auth["AuthCommand\n(auth.py)"]:::internal
    end

    Orchestrator["Orchestrator\n(pre_2k.py)"]:::internal
    LDAP["LDAPClient\n(ldap.py)"]:::internal
    Hunter["MachineHunter\n(machine_hunter.py)"]:::internal
    TGT["TGTFetcher\n(gettgt.py)"]:::internal
    Logger["Logger\n(logger.py)"]:::internal

    AD["Active Directory LDAP Service"]:::external
    KDC["Kerberos KDC"]:::external
    CCache[".ccache File"]:::storage

    User --> CLI
    CLI --> Unauth
    CLI --> Auth

    Unauth --> Orchestrator
    Auth --> Orchestrator

    Orchestrator --> Hunter
    Orchestrator --> LDAP
    Orchestrator --> TGT

    Hunter --> LDAP
    LDAP -->|null bind/search| AD
    TGT -->|request TGT| KDC
    TGT -->|write TGT| CCache

    Unauth --> Logger
    Auth --> Logger
    Orchestrator --> Logger
    LDAP --> Logger
    Hunter --> Logger
    TGT --> Logger

    click CLI "https://github.com/garrettfoster13/pre2k/blob/main/pre2k/__main__.py"
    click Unauth "https://github.com/garrettfoster13/pre2k/blob/main/pre2k/lib/commands/unauth.py"
    click Auth "https://github.com/garrettfoster13/pre2k/blob/main/pre2k/lib/commands/auth.py"
    click LDAP "https://github.com/garrettfoster13/pre2k/blob/main/pre2k/lib/ldap.py"
    click Hunter "https://github.com/garrettfoster13/pre2k/blob/main/pre2k/lib/machine_hunter.py"
    click TGT "https://github.com/garrettfoster13/pre2k/blob/main/pre2k/lib/gettgt.py"
    click Orchestrator "https://github.com/garrettfoster13/pre2k/blob/main/pre2k/lib/pre_2k.py"
    click Logger "https://github.com/garrettfoster13/pre2k/blob/main/pre2k/logger.py"

    classDef internal fill:#ADD8E6,stroke:#0000FF,color:#000000
    classDef external fill:#90EE90,stroke:#008000,color:#000000
    classDef storage fill:#F5DEB3,stroke:#A0522D,color:#000000
```
