# barriuso/smbghost_automateexploitation architecture

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

- Interactive diagram: https://gitdiagram.com/barriuso/smbghost_automateexploitation
- Repository: https://github.com/barriuso/smbghost_automateexploitation

## Overview

##### Project Type and Purpose
- This is a security tool (Python CLI application) comprised of two main functions:
– Scanner: Detects whether a Windows host is vulnerable to SMBGhost.
– Exploit: Crafts or loads shellcode, triggers the vulnerability, and delivers a reverse shell or custom payload.
- The project also bundles example shellcodes and helper modules under RCE/, Scanner/, and Custom_Shellcodes/.

##### File Structure
Top-level:
- Smb_Ghost.py           — main CLI entry point
- requirements.txt       — Python dependencies
- Smb_Ghost.py depends on:
– Scanner/scanner.py & logless_scanner.py
– RCE/exploit.py, kernel_shellcode.asm, smb_win.py, lznt1.py
– Custom_Shellcodes/*.txt
Secondary:
- Scanner/               — vulnerability detection sub-module
- RCE/                   — exploit payload generator & helper modules
- Custom_Shellcodes/     — user-provided shellcode examples
- README files           — documentation for each sub-module

##### Key Components
a. CLI Interface
– Input parser (argparse) in Smb_Ghost.py
– Options: --check (scan), -e (exploit), --shellcode/load-shellcode
b. Scanner Module
– scanner.py: crafts benign SMBv3 packets, analyzes responses
– logless_scanner.py: silent mode, batch scanning
c. Exploit Module
– exploit.py: assembles RCE payload, invokes kernel_shellcode.asm via smb_win.py
– kernel_shellcode.asm & lznt1.py: low-level SMB compression/decompression and shellcode stager
d. Custom Shellcode Loader
– Loads .txt from Custom_Shellcodes/, or directly via --load-shellcode
e. Network Target
– Windows SMBv3.1.1 endpoint
– Vulnerable service responds to malformed compression packets
f. Reverse Shell Listener
– Uses LHOST/LPORT to catch the ephemeral TCP connection from the compromised host

##### Relationships and Data Flows
1) User issues CLI command → Smb_Ghost.py
2a) If --check: invoke Scanner
→ send SMBv3 probe → receive status → report vulnerability
2b) If -e (exploit):
– (Optional) Load or select shellcode
– Assemble exploit packet via the Exploit module
– Send malicious SMB packet → target decompresses → executes shellcode
– Target connects back to attacker on LHOST:LPORT
3) Final output: shell or custom action (e.g., new user creation)

##### Architectural Patterns / Design Principles
- Modular layering:
– CLI layer → Orchestration layer (Smb_Ghost.py) → Functional sub-modules (Scanner, Exploit) → Helper libraries
- Single Responsibility: each sub-directory handles a distinct aspect (scanning vs. exploitation)
- Extensibility: shellcode loader interface allows plugging in new payloads

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    CLI["CLI Parser & Orchestration"]:::local
    Req["requirements.txt"]:::local
    DocsProj["README.md"]:::local

    %% Scanner Subgraph
    subgraph "Scanner Module"
        Scanner["scanner.py"]:::local
        Logless["logless_scanner.py"]:::local
        DocsScan["README.md"]:::local
    end

    %% Exploit Subgraph
    subgraph "Exploit Module"
        Exploit["exploit.py"]:::local
        SMBHelper["smb_win.py"]:::local
        Compression["lznt1.py"]:::local
        KernelSC["kernel_shellcode.asm"]:::local
        DocsExploit["README.md"]:::local
    end

    %% Custom Shellcode Loader
    subgraph "Custom Shellcode Loader"
        ShellcodeDir["Custom_Shellcodes/"]:::local
        ExampleSC["x64_add_user.txt"]:::local
    end

    %% External Entities
    Target["SMBv3 Target (Windows)"]:::external
    Listener["Reverse Shell Listener"]:::external

    %% Flows
    CLI -->|"--check"| Scanner
    CLI -->|"-e / --exploit"| Exploit
    CLI -->|"--load-shellcode"| ShellcodeDir
    Scanner -->|"SMB Probe (port 445)"| Target
    Target -->|"Response"| Scanner
    ShellcodeDir --> ExampleSC
    Exploit --> Compression
    Exploit --> SMBHelper
    Exploit --> KernelSC
    Exploit -->|"Malicious SMB Packet"| Target
    Target -->|"Reverse Shell (LHOST:LPORT)"| Listener

    %% Dependencies & Docs
    CLI --> Req
    CLI --> DocsProj
    Scanner --> DocsScan
    Exploit --> DocsExploit

    %% Click Events
    click CLI "https://github.com/barriuso/smbghost_automateexploitation/blob/master/Smb_Ghost.py"
    click Scanner "https://github.com/barriuso/smbghost_automateexploitation/blob/master/Scanner/scanner.py"
    click Logless "https://github.com/barriuso/smbghost_automateexploitation/blob/master/Scanner/logless_scanner.py"
    click Exploit "https://github.com/barriuso/smbghost_automateexploitation/blob/master/RCE/exploit.py"
    click SMBHelper "https://github.com/barriuso/smbghost_automateexploitation/blob/master/RCE/smb_win.py"
    click Compression "https://github.com/barriuso/smbghost_automateexploitation/blob/master/RCE/lznt1.py"
    click KernelSC "https://github.com/barriuso/smbghost_automateexploitation/blob/master/RCE/kernel_shellcode.asm"
    click ShellcodeDir "https://github.com/barriuso/smbghost_automateexploitation/tree/master/Custom_Shellcodes/"
    click ExampleSC "https://github.com/barriuso/smbghost_automateexploitation/blob/master/Custom_Shellcodes/x64_add_user.txt"
    click Req "https://github.com/barriuso/smbghost_automateexploitation/blob/master/requirements.txt"
    click DocsProj "https://github.com/barriuso/smbghost_automateexploitation/blob/master/README.md"
    click DocsScan "https://github.com/barriuso/smbghost_automateexploitation/blob/master/Scanner/README.md"
    click DocsExploit "https://github.com/barriuso/smbghost_automateexploitation/blob/master/RCE/README.md"

    %% Styles
    classDef local fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef network stroke:#32CD32,stroke-width:2px,stroke-dasharray: 5 5;
```
