# slachet/nishang architecture

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

- Interactive diagram: https://gitdiagram.com/slachet/nishang
- Repository: https://github.com/slachet/nishang

## Overview

##### Project type and purpose
- This is a script-library framework (“Nishang”) for offensive security, penetration testing, and red teaming using PowerShell. It’s not a client-server application but a modular collection of categorized PowerShell payloads, utilities, and backdoors that an operator imports and invokes during a pentest engagement.

##### File structure
- Top-level:
- nishang.psm1 – the module manifest that imports all functions.
- powerpreter/Powerpreter.psm1 – a “single-script” version wrapping most functionality.
- Directories: ActiveDirectory, Antak-WebShell, Backdoors, Bypass, Client, Escalation, Execution, Gather, MITM, Pivot, Prasadhak, Scan, Shells, Utility, Misc.
- Pattern: “Plugin” architecture. Each directory is a category of payloads or helpers. Scripts expose a function with the same name. Utility contains reusable routines (encoding, exfiltration, download).

##### README insights
- The framework is loaded via `Import-Module .\nishang.psm1`.
- Scripts are dot-sourced or invoked directly.
- No single persistent server component; instead scripts establish outbound channels (HTTP, HTTPS, DNS TXT, ICMP, WMI, etc.) to attacker-controlled services.

a. Main components
1. Module Loader (nishang.psm1 / Powerpreter.psm1)
2. Script Categories (“plugins”):
– ActiveDirectory
– Antak-WebShell
– Backdoors
– Bypass
– Client (document-based payload generators)
– Escalation
– Execution
– Gather
– MITM
– Pivot
– Prasadhak
– Scan
– Shells
– Utility
3. External Interfaces / Services:
– Attacker C2 Servers (HTTP, HTTPS, WebDAV, custom listener)
– DNS Resolver for TXT-based communication
– Email Service (Gmail for PsGcat)
– SMB / File servers (exfil capture)
– Web server (Antak/Webshell host)
4. Target System (Windows host under test)

b. Relationships and interactions
- Within each category, scripts often call Utility routines (Utility → all categories).
- Shells / Backdoors / MITM modules initiate outbound connections to External C2 Services.

c. Architecture patterns and design principles
- Plugin / modular architecture: each feature lives in its own directory as an independent script.
- Utility module provides common services (encoding, exfiltration, persistence) to avoid code duplication.
- “Single entry” via Import-Module; dynamic discovery of functions.
- Separation of payload generation (Client) vs. payload execution (Shells, Backdoors).

d. Key technologies and frameworks
- PowerShell v3+ (module manifests, dot-sourcing)
- .psm1 modules for packaging
- HTTP/HTTPS (Invoke-PoshRatHttp/Https), DNS TXT (DNS_TXT_Pwnage), ICMP (Invoke-PowerShellIcmp), WMI remoting.
- Volume Shadow Copy (Copy-VSS), Mimikatz integration, AD-specific APIs for DCShadow.

##### Detail but avoid overcomplexity
- Every top-level directory as its own component.
- Interdependencies only where they exist (Utility is the only shared dependency).
- Do not break out each script file; group them by category for readability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Loader and Wrapper
    Loader["Loader: nishang.psm1"]:::loader
    Powerpreter["Single-Script Wrapper: Powerpreter.psm1"]:::loader

    %% Utility Hub
    Utility["Shared Utility Routines"]:::utility

    %% Categories
    subgraph "Payload & Plugin Categories"
        direction TB
        AD["Category: ActiveDirectory"]:::categoryAD
        Antak["Category: Antak-WebShell"]:::categoryAntak
        Backdoors["Category: Backdoors"]:::categoryBackdoors
        Bypass["Category: Bypass"]:::categoryBypass
        Client["Category: Client"]:::categoryClient
        Escalation["Category: Escalation"]:::categoryEsc
        Execution["Category: Execution"]:::categoryExec
        Gather["Category: Gather"]:::categoryGather
        MITM["Category: MITM"]:::categoryMITM
        Pivot["Category: Pivot"]:::categoryPivot
        Prasadhak["Category: Prasadhak"]:::categoryPras
        Scan["Category: Scan"]:::categoryScan
        Shells["Category: Shells"]:::categoryShells
    end

    %% Target System
    Target["Target System\n(Windows Host)"]:::target

    %% External Services
    subgraph "External Services"
        direction TB
        C2HTTP["C2 Service: HTTP/HTTPS"]:::external
        C2DNS["C2 Service: DNS TXT Resolver"]:::external
        C2Email["Email Service (Gmail)"]:::external
        C2SMB["SMB/File Server"]:::external
        WebServer["Web Server\n(Antak Host)"]:::external
    end

    %% Import flow
    Loader -->|imports| AD
    Loader -->|imports| Antak
    Loader -->|imports| Backdoors
    Loader -->|imports| Bypass
    Loader -->|imports| Client
    Loader -->|imports| Escalation
    Loader -->|imports| Execution
    Loader -->|imports| Gather
    Loader -->|imports| MITM
    Loader -->|imports| Pivot
    Loader -->|imports| Prasadhak
    Loader -->|imports| Scan
    Loader -->|imports| Shells
    Loader -->|imports| Utility

    Powerpreter -->|wraps| AD
    Powerpreter -->|wraps| Antak
    Powerpreter -->|wraps| Backdoors
    Powerpreter -->|wraps| Bypass
    Powerpreter -->|wraps| Client
    Powerpreter -->|wraps| Escalation
    Powerpreter -->|wraps| Execution
    Powerpreter -->|wraps| Gather
    Powerpreter -->|wraps| MITM
    Powerpreter -->|wraps| Pivot
    Powerpreter -->|wraps| Prasadhak
    Powerpreter -->|wraps| Scan
    Powerpreter -->|wraps| Shells
    Powerpreter -->|wraps| Utility

    %% Utility usage
    AD -->|uses| Utility
    Antak -->|uses| Utility
    Backdoors -->|uses| Utility
    Bypass -->|uses| Utility
    Client -->|uses| Utility
    Escalation -->|uses| Utility
    Execution -->|uses| Utility
    Gather -->|uses| Utility
    MITM -->|uses| Utility
    Pivot -->|uses| Utility
    Prasadhak -->|uses| Utility
    Scan -->|uses| Utility
    Shells -->|uses| Utility

    %% Client payload delivery
    Client -->|generates payloads| Target

    %% Backdoors/Shells/MITM outbound
    Backdoors -->|C2 callback| C2HTTP
    Backdoors -->|C2 callback| C2DNS
    Shells -->|C2 callback| C2HTTP
    Shells -->|C2 callback| C2DNS
    MITM -->|intercepts & forwards| C2HTTP

    %% Email & SMB
    Client -->|drops via email| C2Email
    Client -->|drops via SMB| C2SMB

    %% Antak-WebShell interaction
    Target -->|executes webshell| WebServer
    Antak -->|hosts| WebServer

    %% Internal-only operations
    Gather -->|collects data| Target
    Escalation -->|escalates privileges| Target
    Pivot -->|relays network| Target

    %% Click Events
    click Loader "https://github.com/slachet/nishang/blob/master/nishang.psm1"
    click Powerpreter "https://github.com/slachet/nishang/blob/master/powerpreter/Powerpreter.psm1"
    click AD "https://github.com/slachet/nishang/tree/master/ActiveDirectory/"
    click Antak "https://github.com/slachet/nishang/tree/master/Antak-WebShell/"
    click Backdoors "https://github.com/slachet/nishang/tree/master/Backdoors/"
    click Bypass "https://github.com/slachet/nishang/blob/master/Bypass/Invoke-AmsiBypass.ps1"
    click Client "https://github.com/slachet/nishang/tree/master/Client/"
    click Escalation "https://github.com/slachet/nishang/tree/master/Escalation/"
    click Execution "https://github.com/slachet/nishang/tree/master/Execution/"
    click Gather "https://github.com/slachet/nishang/tree/master/Gather/"
    click MITM "https://github.com/slachet/nishang/blob/master/MITM/Invoke-Interceptor.ps1"
    click Pivot "https://github.com/slachet/nishang/tree/master/Pivot/"
    click Prasadhak "https://github.com/slachet/nishang/blob/master/Prasadhak/Invoke-Prasadhak.ps1"
    click Scan "https://github.com/slachet/nishang/tree/master/Scan/"
    click Shells "https://github.com/slachet/nishang/tree/master/Shells/"
    click Utility "https://github.com/slachet/nishang/tree/master/Utility/"

    %% Styles
    classDef loader fill:#cce5ff,stroke:#004085,color:#004085;
    classDef utility fill:#ffeeba,stroke:#856404,color:#856404;
    classDef categoryAD fill:#d4edda,stroke:#155724,color:#155724;
    classDef categoryAntak fill:#f8d7da,stroke:#721c24,color:#721c24;
    classDef categoryBackdoors fill:#f8d7da,stroke:#721c24,color:#721c24;
    classDef categoryBypass fill:#fff3cd,stroke:#856404,color:#856404;
    classDef categoryClient fill:#d1ecf1,stroke:#0c5460,color:#0c5460;
    classDef categoryEsc fill:#d4edda,stroke:#155724,color:#155724;
    classDef categoryExec fill:#fff3cd,stroke:#856404,color:#856404;
    classDef categoryGather fill:#d1ecf1,stroke:#0c5460,color:#0c5460;
    classDef categoryMITM fill:#f8d7da,stroke:#721c24,color:#721c24;
    classDef categoryPivot fill:#d4edda,stroke:#155724,color:#155724;
    classDef categoryPras fill:#d1ecf1,stroke:#0c5460,color:#0c5460;
    classDef categoryScan fill:#fff3cd,stroke:#856404,color:#856404;
    classDef categoryShells fill:#f8d7da,stroke:#721c24,color:#721c24;
    classDef target fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef external fill:#f0f0f0,stroke-dasharray: 5 5,stroke:#343a40,color:#343a40;
```
