# orange-cyberdefense/keepwn architecture

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

- Interactive diagram: https://gitdiagram.com/orange-cyberdefense/keepwn
- Repository: https://github.com/orange-cyberdefense/keepwn

## Overview

##### Project Type and Purpose
- KeePwn is a Python-based command-line tool for red teamers/pen testers. It provides modules to:
- Discover remote KeePass installations via SMB/C$ and Impacket/RPC
- Abuse KeePass plugins (add/remove malicious DLLs)
- Abuse KeePass triggers (inject export triggers)
- Parse local memory dumps to extract master‐password candidates
- Convert KDBX databases to John/Hashcat-compatible hashes
- It is not a distributed microservice, but a single executable with modular subcommands.

##### File Structure Analysis
Top-level:
- KeePwn.py & keepwn/__main__.py – entry point and CLI parser
- setup.py & requirements.txt – packaging & dependencies (e.g., Impacket)
- keepwn/
– core/ (five modules: search.py, plugin.py, trigger.py, parse_dump.py, convert.py)
– utils/ (SMB routines, parsers, logging, threading helpers)
– data/export_database_trigger.xml (payload template for trigger abuse)

##### README Insights
- Confirms five functional areas (search, plugin, trigger, parse_dump, convert)
- Emphasizes multi-threading in search, CSV export, and use of Impacket for RPC/SMB
- Mentions external PoCs and libraries reused

##### Components
a. CLI Layer
- KeePwn.py / keepwn.__main__: argument parsing, subcommand dispatch
b. Core Modules Layer
- Search Module: multi-threaded SMB/C$, Impacket RPC calls
- Plugin Module: enumerates, adds/removes DLLs via SMB
- Trigger Module: reads/writes KeePass.config.xml via SMB (uses XML template in data/)
- ParseDump Module: local memory dump parser + brute-force stage
- Convert Module: local KDBX parser → John/Hashcat hash generator
c. Utility Layer
- SMB Utilities: SMB session management, file operations
- Parser Utilities: XML, binary data extraction
- Logging & Threading Tools
d. External Dependencies
- Impacket library (RPC, SMB)
- Python standard library (argparse, threading, csv, xml.etree)
- Remote Target Hosts: Windows hosts exposing C$ share, running KeePass
e. Outputs
- CSV files (search results)
- Exported XML (trigger/plugin exports)
- Hash files or stdout prints

##### Relationships and Data Flows
- CLI Layer dispatches to one core module per invocation
- Core modules call Utility functions
- SMB Utils ↔ Remote Host C$ share (file enumeration, read/write)
- Impacket RPC ↔ Remote Host for process checks
- Parser Utils process XML config or memory dump blobs
- Outputs flow back to CLI for console output or to written files (CSV, .xml, .hash)

##### Architectural Patterns & Principles
- Modular CLI with subcommands (akin to Git’s plumbing/porcelain)
- Layered separation: Presentation (CLI) → Core Business Logic → Utilities → External I/O
- Reuse of external PoC code via utility modules
- Thread pool in search module for parallelism
- Plugin pattern: each core module exposes check/add/remove/poll actions

##### Essential Details to Capture
- Multi-threading in search
- Impacket dependency for RPC and SMB operations
- XML payload usage in trigger (export_database_trigger.xml)
- Two I/O domains: Networked (remote host) vs. Local File System
- Extensibility: each core module follows a similar “check/add/remove/poll” flow

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "KeePwn Application"
        subgraph "CLI Layer"
            CLI1["KeePwn.py"]:::cli
            CLI2["keepwn/__main__.py"]:::cli
        end
        subgraph "Core Modules Layer"
            Search["Search Module\n(smb discovery)"]:::core
            Plugin["Plugin Module\n(DLL abuse)"]:::core
            Trigger["Trigger Module\n(XML triggers)"]:::core
            ParseDump["ParseDump Module\n(memory dump)"]:::core
            Convert["Convert Module\n(KDBX→hash)"]:::core
        end
        subgraph "Utility Layer"
            SMBUtils["SMB Utilities"]:::util
            ParserUtils["Parser Utilities"]:::util
            Logging["Logging Utilities"]:::util
            ThreadTools["Threading Tools"]:::util
            JohnHelper["KDBX→John Helper"]:::util
            XMLTemplate["export_database_trigger.xml"]:::util
        end
    end

    RemoteHost(("Remote Hosts\n(Windows C$ share)")):::ext
    LocalFS(("Local File System")):::ext

    CLI1 -->|dispatch| Search
    CLI1 -->|dispatch| Plugin
    CLI1 -->|dispatch| Trigger
    CLI1 -->|dispatch| ParseDump
    CLI1 -->|dispatch| Convert

    CLI2 -->|dispatch| Search
    CLI2 -->|dispatch| Plugin
    CLI2 -->|dispatch| Trigger
    CLI2 -->|dispatch| ParseDump
    CLI2 -->|dispatch| Convert

    Search -->|uses| SMBUtils
    Search -->|threads| ThreadTools
    Plugin -->|uses| SMBUtils
    Trigger -->|uses| SMBUtils
    Trigger -->|template| XMLTemplate
    ParseDump -->|parses| ParserUtils
    Convert -->|parses| ParserUtils
    Convert -->|generates| JohnHelper

    SMBUtils -->|SMB/C$| RemoteHost
    ParserUtils -->|file I/O| LocalFS
    JohnHelper -->|output hashes| LocalFS

    classDef cli fill:#cce5ff,stroke:#004085,color:#004085
    classDef core fill:#d4edda,stroke:#155724,color:#155724
    classDef util fill:#fff3cd,stroke:#856404,color:#856404
    classDef ext fill:#e2e3e5,stroke:#6c757d,color:#6c757d

    click CLI1 "https://github.com/orange-cyberdefense/keepwn/blob/main/KeePwn.py"
    click CLI2 "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/__main__.py"
    click Search "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/core/search.py"
    click Plugin "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/core/plugin.py"
    click Trigger "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/core/trigger.py"
    click ParseDump "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/core/parse_dump.py"
    click Convert "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/core/convert.py"
    click SMBUtils "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/utils/smb.py"
    click ParserUtils "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/utils/parser.py"
    click Logging "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/utils/logging.py"
    click ThreadTools "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/utils/tstools.py"
    click JohnHelper "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/utils/keepass2john.py"
    click XMLTemplate "https://github.com/orange-cyberdefense/keepwn/blob/main/keepwn/data/export_database_trigger.xml"
```
