# tw1sm/pysqlrecon architecture

> Architecture diagram of the GitHub repository tw1sm/pysqlrecon, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tw1sm/pysqlrecon
- Repository: https://github.com/tw1sm/pysqlrecon

## Overview

##### Main Components

a. Core Components:
- Command Line Interface (Entry Point)
- Module System
- Library Components
- SQL Server Interaction Layer
- Logging System

b. Module Categories:
- Information Gathering Modules
- Privilege Escalation Modules
- Command Execution Modules
- SCCM-specific Modules

**┌─ User Interface Layer ─────────────────────┐**
- CLI Interface (__main__.py)                │
- Command Processing & Argument Handling     │
- ┬─────────────────────────┘
- ↓
**┌─ Core Library Layer ──────────────────────┐**
- ┌─────────────┐ ┌──────────┐ ┌─────────┐ │
- Query Handler│ │CLR Engine│ │Logger   │ │
- ┘ └──────────┘ └─────────┘ │
- ┬─────────────────────────┘
- ↓
**┌─ Module Layer ────────────────────────────┐**
- ┌─────────────┐ ┌──────────┐ ┌─────────┐ │
- Basic Modules│ │Priv Mods │ │SCCM Mods│ │
- ┘ └──────────┘ └─────────┘ │
- ┬─────────────────────────┘
- ↓
**┌─ External Integration Layer ──────────────┐**
- SQL Server Connection                     │
- Active Directory Integration             │
- SMB Interaction                          │
- ┘

##### Key Relationships to Highlight

a. Command Flow:
- How commands flow from CLI through the module system
- Privilege requirements for different paths

b. Data Flow:
- SQL query execution paths
- Authentication and impersonation flows
- Command execution paths

##### Special Features to Emphasize

- Impersonation capabilities [I]
- Linked server execution [L]
- CLR integration
- SCCM interaction
- Authentication methods

##### Implementation Details

a. Core Components:
- Module system (pysqlrecon/modules/)
- Library components (pysqlrecon/lib/)
- Resource handling (resources/)

b. Key Interfaces:
- SQL Server communication
- Command execution methods (xp_cmdshell, CLR, OLE, Agent)
- SCCM interaction points

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef module fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef priv fill:#e74c3c,stroke:#c0392b,color:white
    classDef sccm fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#bdc3c7,stroke:#95a5a6,color:black

    %% User Interface Layer
    CLI["CLI Interface"]:::ui
    click CLI "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/__main__.py"

    %% Core Library Layer
    subgraph CoreLib["Core Library Components"]
        QueryHandler["Query Handler"]:::core
        CLREngine["CLR Engine"]:::core
        Logger["Logger"]:::core
        ModuleBase["Module System"]:::core
        SQLAgent["SQL Agent"]:::core
    end
    click QueryHandler "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/lib/query.py"
    click CLREngine "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/lib/clr.py"
    click Logger "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/logger.py"
    click ModuleBase "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/lib/module.py"
    click SQLAgent "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/lib/sqlagent.py"

    %% Module Layer
    subgraph InfoModules["Information Gathering"]
        Info["Info Module"]:::module
        Databases["Databases"]:::module
        Tables["Tables"]:::module
        WhoAmI["WhoAmI"]:::module
    end
    click Info "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/info.py"
    click Databases "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/databases.py"
    click Tables "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/tables.py"
    click WhoAmI "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/whoami.py"

    subgraph PrivModules["Privilege Escalation"]
        Impersonate["Impersonate"]:::priv
        EnableCLR["Enable CLR"]:::priv
        EnableOLE["Enable OLE"]:::priv
        EnableXP["Enable XP"]:::priv
    end
    click Impersonate "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/impersonate.py"
    click EnableCLR "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/enableclr.py"
    click EnableOLE "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/enableole.py"
    click EnableXP "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/enablexp.py"

    subgraph ExecModules["Command Execution"]
        XPCmd["XP_CMD"]:::priv
        OLECmd["OLE_CMD"]:::priv
        AgentCmd["Agent_CMD"]:::priv
    end
    click XPCmd "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/xpcmd.py"
    click OLECmd "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/olecmd.py"
    click AgentCmd "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/agentcmd.py"

    subgraph SCCMModules["SCCM Modules"]
        SCCMCore["SCCM Core"]:::sccm
        SCCMCreds["Credentials"]:::sccm
        SCCMAdmin["Add Admin"]:::sccm
        SCCMUsers["Users"]:::sccm
    end
    click SCCMCore "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/lib/sccm.py"
    click SCCMCreds "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/sccm/credentials.py"
    click SCCMAdmin "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/sccm/addadmin.py"
    click SCCMUsers "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/sccm/users.py"

    %% External Integration Layer
    subgraph External["External Integration"]
        SQLServer["SQL Server"]:::external
        AD["Active Directory"]:::external
        SMB["SMB"]:::external
    end
    click AD "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/adsi.py"
    click SMB "https://github.com/Tw1sm/PySQLRecon/blob/main/pysqlrecon/modules/smb.py"

    %% Relationships
    CLI --> ModuleBase
    ModuleBase --> QueryHandler
    ModuleBase --> CLREngine
    ModuleBase --> Logger
    ModuleBase --> SQLAgent

    QueryHandler --> SQLServer
    CLREngine --> SQLServer
    SQLAgent --> SQLServer

    ModuleBase --> InfoModules
    ModuleBase --> PrivModules
    ModuleBase --> ExecModules
    ModuleBase --> SCCMModules

    SCCMCore --> SQLServer
    AD --> SQLServer
    SMB --> SQLServer

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Normal Modules"]:::module
        L3["Privileged Modules"]:::priv
        L4["SCCM Modules"]:::sccm
        L5["External Systems"]:::external
    end
```
