# risksense/zerologon architecture

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

- Interactive diagram: https://gitdiagram.com/risksense/zerologon
- Repository: https://github.com/risksense/zerologon

## Overview

##### Project type and purpose
- This is a small Python-based command-line security tool (exploit script) targeting CVE-2020-1472 (“ZeroLogon”).
- It provides two main operations:
- set_empty_pw.py – forces the Domain Controller (DC) machine account password to an empty value via the Netlogon RPC interface
- reinstall_original_pw.py – restores the original machine account NT hash to avoid breaking the domain
- It depends on the Impacket library for RPC operations and uses standard Windows tooling (secretsdump, wmiexec) to extract registry hives.

##### File structure
- Top-level files:
- set_empty_pw.py and reinstall_original_pw.py – the two CLI entry points
- requirements.txt – declares Impacket and any other Python dependencies
- README.md – describes usage and workflow
- LICENSE – license terms
- No conventional “src” or “lib” directories—this is a single-module, script-driven project.

##### README for additional insights
- Describes a multi-step workflow:
a. invoke set_empty_pw.py → forces empty machine password via Impacket RPC
b. run secretsdump.py and wmiexec.py → pull SYSTEM, SAM, SECURITY hives from the DC
c. extract original NT hash locally from those hive files
d. invoke reinstall_original_pw.py → restore the DC’s original machine account password
- Relies on external tools (Impacket scripts, reg save, WMExec)

##### Diagramming the architecture
a. Main components
- CLI Scripts (Python): set_empty_pw.py, reinstall_original_pw.py
- Python runtime + Impacket library (RPC client)
- Network boundary → Target Domain Controller’s Netlogon RPC service
- Windows Domain Controller internals: Registry (SYSTEM/SAM/SECURITY hives)
- External tools invoked by the scripts: secretsdump.py, wmiexec.py
- Local filesystem for temporary hive files and original-hash storage
b. Relationships & interactions
- set_empty_pw.py → calls Impacket RPC client → sends Netlogon messages over TCP to DC
- On success, operator invokes secretsdump.py / wmiexec.py → RPC calls to DC → retrieves hive files
- Hive files stored locally → processed to extract original NT hash
- reinstall_original_pw.py → calls Impacket RPC client → sends RPC messages to set machine account back to original hash
c. Architectural patterns / design principles
- Separation of concerns: two focused CLI tools (one to manipulate DC password, one to restore it)
- Reliance on an external RPC-client library (Impacket) for Netlogon protocol implementation
d. Significant technologies / libraries
- Python 3 runtime
- Impacket (RPC, DCE/RPC, NTLM)
- Windows RPC endpoint for Netlogon (MS-RPC)
- Windows registry hive extraction via reg.exe and secretsdump.py

##### Detail
- Call out dependencies (Impacket commit hash in requirements.txt)
- Don’t over-simplify—list every actor, tool, and data store involved in the exploit and restore processes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Attacker Workstation Components
    subgraph "Attacker Workstation"
        direction TB
        A1["set_empty_pw.py"]:::script
        A2["reinstall_original_pw.py"]:::script
        A3["Python 3 Runtime"]:::runtime
        A4["Impacket RPC Client"]:::library
        subgraph "External Tools"
            direction TB
            A5["secretsdump.py"]:::tool
            A6["wmiexec.py"]:::tool
            A7["reg.exe"]:::tool
        end
        subgraph "Local Filesystem"
            direction TB
            A8["system.save"]:::storage
            A9["sam.save"]:::storage
            A10["security.save"]:::storage
            A11["original_hash.txt"]:::storage
        end
    end

    %% Target Domain Controller Components
    subgraph "Target Domain Controller"
        direction TB
        B1["Netlogon RPC Service"]:::target
        subgraph "Registry Hives"
            direction TB
            B2["SYSTEM Hive"]:::target
            B3["SAM Hive"]:::target
            B4["SECURITY Hive"]:::target
        end
    end

    %% Workflow Connections
    A1 -->|"RPC Call"| A4
    A4 -->|"Netlogon Messages"| B1
    B1 -->|"Response"| A4
    A1 -->|"writes logs"| A11
    A2 -->|"RPC Call"| A4
    A4 -->|"Netlogon Messages"| B1
    B1 -->|"Response"| A4

    A1 -->|"trigger"| A5
    A1 -->|"trigger"| A6
    A5 -->|"RPC Dump"| B2
    A5 -->|"RPC Dump"| B3
    A5 -->|"RPC Dump"| B4
    A6 -->|"RPC Exec"| B1
    B2 -.->|"file save"| A8
    B3 -.->|"file save"| A9
    B4 -.->|"file save"| A10
    A8 -->|"extract NT hash"| A11
    A9 -->|"extract NT hash"| A11
    A10 -->|"extract NT hash"| A11

    %% Documentation and Config Files
    subgraph "Project Files"
        direction TB
        F1["requirements.txt"]:::config
        F2["README.md"]:::doc
        F3["LICENSE"]:::doc
    end

    %% Connections to Project Files
    A3 -->|"declares deps"| F1
    A1 -->|"usage docs"| F2
    A2 -->|"usage docs"| F2

    %% Legend
    subgraph "Legend"
        direction TB
        L1["CLI Scripts"]:::script
        L2["Python Runtime"]:::runtime
        L3["Impacket Library"]:::library
        L4["External Tools"]:::tool
        L5["Local Files"]:::storage
        L6["Target System"]:::target
        L7["Config"]:::config
        L8["Docs/License"]:::doc
    end

    %% Click Events
    click A1 "https://github.com/risksense/zerologon/blob/master/set_empty_pw.py"
    click A2 "https://github.com/risksense/zerologon/blob/master/reinstall_original_pw.py"
    click F1 "https://github.com/risksense/zerologon/blob/master/requirements.txt"
    click F2 "https://github.com/risksense/zerologon/blob/master/README.md"
    click F3 "https://github.com/risksense/zerologon/tree/master/LICENSE"

    %% Styles
    classDef script fill:#f9f,stroke:#333,stroke-width:1px
    classDef runtime fill:#bbf,stroke:#333,stroke-width:1px
    classDef library fill:#bdf,stroke:#333,stroke-width:1px
    classDef tool fill:#ffb,stroke:#333,stroke-width:1px
    classDef storage fill:#fea,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef target fill:#afa,stroke:#333,stroke-width:1px
    classDef config fill:#ddf,stroke:#333,stroke-width:1px
    classDef doc fill:#eef,stroke:#333,stroke-width:1px
```
