# samratashok/nishang architecture

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

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

## Overview

##### Project Type & Purpose
- This is an offensive-security framework implemented as a PowerShell module plus a directory of standalone scripts.
- It’s not a traditional client-server or web app, but a plugin-style library of payloads, backdoors, enumeration and exploitation scripts, and “clients” that generate malicious docs or webshells.

##### File-Structure Analysis
- Top‐level “nishang.psm1” (PowerShell module) exports all functions.
- Folders represent functional categories:
- ActiveDirectory – AD-focused backdoors and privilege modifications
- Antak-WebShell – a .NET webshell for in-memory PS execution
- Backdoors – multiple C2 techniques (HTTP, DNS TXT, screen-saver, etc.)
- Bypass – anti-AMSI evasion
- Client – payload generators (CHM, Word, Excel, JS, HTA, etc.)
- Escalation, Execution, Gather, MITM, Pivot, Scan – each group of PS scripts for a phase of a red-team engagement
- Shells – reverse shells over HTTP, HTTPS, ICMP, TCP, UDP, WMI
- Utility – common helpers (encode/decode, persistence, exfiltration, download, DNS TXT generator, key parser, etc.)
- powerpreter – monolithic version of many functions in one module

##### Key Insights from README
- The “module” (nishang.psm1) is the central loader.
- Scripts are meant to be dot-sourced or loaded in memory via WebClient or -EncodedCommand.
- Many scripts interact with external C2 channels (HTTP(S) servers, DNS servers, Gmail, Pastebin, SMB shares).
- Persistence points (registry, scheduled tasks, ADS, etc.) and evasion (AMSI bypass).

##### Diagramming the Architecture
a. Main Components
1. Target Host (Windows PowerShell v3+)
2. Nishang Module Loader (nishang.psm1)
3. Functional Script Groups (represented as sub-systems/packages):
– AD Module
– Backdoors Module
– Bypass Module
– Client Payload Generator Module
– Escalation Module
– Execution Module
– Gathering Module
– MITM Module
– Pivoting Module
– Scanning Module
– Shells Module
– Utility Module
4. powerpreter Monolith (optional single-module alternative)
5. External Services/C2 Channels:
– HTTP/HTTPS Server, DNS TXT Server, Email (Gmail), Pastebin, SMB/NTLM Collector, DCOM/WMI Remoting, Domain Controller, MSSQL Server, etc.

b. Relationships & Data Flow
- From individual scripts → External C2 channels (HTTP(S), DNS, ICMP, email, SMB)
- From scripts → Windows subsystems (Registry, ADS, Scheduled Tasks, WMI, DCOM)
- From “Client” module → Social-engineering docs/web pages generated, then delivered to victim

c. Architectural Patterns & Principles
- Plugin/Module pattern – central loader with many loosely-coupled script files
- Layered by engagement phase (Recon, Exploitation, Persistence, Exfil, Pivot, Cleanup)
- Extensibility – add new scripts under appropriate category and they auto-export via module manifest
- In-memory execution – minimize disk footprint, evade AV/AMSI

d. Key Technologies & Frameworks
- PowerShell v3+ scripting engine
- .NET WebClient for in-memory download & execution
- Windows APIs for persistence (registry keys, ADS, screen-saver hijack)
- Standard PS Remoting / WMI / DCOM for pivoting
- Networking protocols: HTTP, HTTPS, DNS TXT, ICMP, TCP, UDP

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and Host
    User["User/Operator"]:::external
    User -->|"Import-Module"| PS["PowerShell Session"]:::internal
    PS -->|"Load Module"| Loader["Nishang Module Loader\n(nishang.psm1)"]:::loader

    subgraph "Target Host" 
        direction TB
        PS
        Loader
        subgraph "Modules (Plugin Pattern)"
            direction TB
            AD["ActiveDirectory Module\n(ActiveDirectory/)"]:::ad
            Antak["Antak-WebShell Module\n(Antak-WebShell/)"]:::webshell
            Backdoors["Backdoors Module\n(Backdoors/)"]:::backdoors
            Bypass["Bypass Module\n(AMSI Evasion)\n(Bypass/)"]:::bypass
            Client["Client Payload Generator\n(Client/)"]:::client
            Escalation["Escalation Module\n(Escalation/)"]:::escalation
            Execution["Execution Module\n(Execution/)"]:::execution
            Gather["Gathering Module\n(Gather/)"]:::gather
            MITM["MITM Module\n(MITM/)"]:::mitm
            Pivot["Pivoting Module\n(Pivot/)"]:::pivot
            Scan["Scanning Module\n(Scan/)"]:::scan
            Shells["Shells Module\n(Shells/)"]:::shells
            Utility["Utility Module\n(Utility/)"]:::utility
            Powerpreter["powerpreter Monolith\n(powerpreter/Powerpreter.psm1)"]:::monolith
        end
    end

    %% Plugin relationships
    Loader -->|".\ <function>..."| AD
    Loader -->|".\ <function>..."| Antak
    Loader -->|".\ <function>..."| Backdoors
    Loader -->|".\ <function>..."| Bypass
    Loader -->|".\ <function>..."| Client
    Loader -->|".\ <function>..."| Escalation
    Loader -->|".\ <function>..."| Execution
    Loader -->|".\ <function>..."| Gather
    Loader -->|".\ <function>..."| MITM
    Loader -->|".\ <function>..."| Pivot
    Loader -->|".\ <function>..."| Scan
    Loader -->|".\ <function>..."| Shells
    Loader -->|".\ <function>..."| Utility
    Loader -->|".\ <function>..."| Powerpreter

    %% External C2 Services
    subgraph "External Services / C2 Channels"
        direction TB
        HTTP["HTTP/HTTPS Server"]:::external
        DNS["DNS TXT Server"]:::external
        Email["Email (Gmail)"]:::external
        Pastebin["Pastebin"]:::external
        SMB["SMB/NTLM Collector"]:::external
        DCOMWMI["DCOM/WMI Remoting"]:::external
        ADDS["Domain Controller (AD)"]:::external
        MSSQL["MSSQL Server"]:::external
    end

    %% Data flows to externals
    Backdoors -->|"HTTP/S POST"| HTTP
    Backdoors -->|"DNS TXT Query"| DNS
    Shells -->|"Reverse Shell"| HTTP
    Shells -->|"Reverse Shell"| DNS
    Shells -->|"ICMP/TCP/UDP"| SMB
    Client -->|"Deliver Payload"| HTTP
    Gather -->|"Invoke-WMI Remoting"| DCOMWMI
    Gather -->|"Query AD"| ADDS
    Utility -->|"Generate DNS TXT"| DNS
    Utility -->|"Send Email"| Email
    Utility -->|"Post to Pastebin"| Pastebin

    %% Windows Subsystems
    subgraph "Windows Subsystems"
        Registry["Registry"]:::external
        ADS["Alternate Data Streams"]:::external
        Tasks["Scheduled Tasks"]:::external
        WMI["WMI"]:::external
        DCOM["DCOM"]:::external
    end

    Backdoors -->|"Persistence"| Registry
    Backdoors -->|"Persistence"| ADS
    Bypass -->|"AMSI Evasion"| PS
    Shells -->|"Persistence"| Tasks
    Pivot -->|"PS Remoting"| DCOM
    Pivot -->|"PS Remoting"| WMI

    %% Legend
    subgraph Legend
       direction LR
       L1["Loader"]:::loader
       L2["ActiveDirectory"]:::ad
       L3["Backdoors"]:::backdoors
       L4["Bypass"]:::bypass
       L5["Client"]:::client
       L6["Escalation"]:::escalation
       L7["Execution"]:::execution
       L8["Gather"]:::gather
       L9["MITM"]:::mitm
       L10["Pivot"]:::pivot
       L11["Scan"]:::scan
       L12["Shells"]:::shells
       L13["Utility"]:::utility
       L14["Monolith"]:::monolith
       L15["External"]:::external
    end

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

    %% Styles
    classDef internal fill:#eef,stroke:#333,stroke-width:1px
    classDef loader fill:#f9f,stroke:#333,stroke-width:1px
    classDef ad fill:#fee,stroke:#333,stroke-width:1px
    classDef webshell fill:#ffd,stroke:#333,stroke-width:1px
    classDef backdoors fill:#faa,stroke:#333,stroke-width:1px
    classDef bypass fill:#fdd,stroke:#333,stroke-width:1px
    classDef client fill:#fc9,stroke:#333,stroke-width:1px
    classDef escalation fill:#fce,stroke:#333,stroke-width:1px
    classDef execution fill:#cfc,stroke:#333,stroke-width:1px
    classDef gather fill:#ccf,stroke:#333,stroke-width:1px
    classDef mitm fill:#ddf,stroke:#333,stroke-width:1px
    classDef pivot fill:#def,stroke:#333,stroke-width:1px
    classDef scan fill:#edf,stroke:#333,stroke-width:1px
    classDef shells fill:#fcd,stroke:#333,stroke-width:1px
    classDef utility fill:#cfc,stroke:#333,stroke-width:1px
    classDef monolith fill:#fcc,stroke:#333,stroke-width:1px
    classDef external fill:#eee,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
