# hash3lizer/sillyrat architecture

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

- Interactive diagram: https://gitdiagram.com/hash3lizer/sillyrat
- Repository: https://github.com/hash3lizer/sillyrat

## Overview

##### Project type and purpose
- This is a cross-platform Remote Access Trojan (RAT) tool written in pure Python.
- It has two main roles:
a. server.py – the command-and-control server that binds to an IP:port, listens for incoming clients, and exposes a CLI to manage sessions.
b. client payloads – generated via the “generate” command (using pyinstaller or as a raw .py), which connect back to the server and execute remote commands (shell, sysinfo, screenshot, persistence, etc.).

##### File structure
- Top-level:
- server.py – entry point for server/C2 commands (bind, generate, sessions, connect, help).
- requirements.txt – dependencies (e.g., pyinstaller).
- mods/ – client‐side modules:
– main.py – client entry point (connects to server, dispatches commands).
– client.py – handles low-level network I/O and base64 encoding.
– sysinfo.py, screenshot.py, persistence.py – feature plugins.
– consts.py, imports.py – shared constants and dynamic imports.
- No database or external storage; all session info is in memory.

##### Key insights from README
- Two modes: “generate” (build payload) and “bind” (launch C2).
- Uses base64 over TCP, built-in shell, sysinfo dump, screenshot capture, persistence hooks.
- Pure Python, cross-platform – payloads must be built on target OS for executables.

##### Main components
a. Payload Generator
- Input: server.py CLI “generate” command + address/port flags
- Uses pyinstaller (or direct .py) to produce the client binary or script
b. C2 Server (server.py)
- CLI layer (bind, sessions, connect, help)
- Network listener (TCP socket)
- Session Manager (in-memory list of connected clients)
- Command Dispatcher (routes admin commands to specific client)
c. Client Payload (mods/main.py + mods/*.py)
- Network client (connects to server address:port, reconnect loop)
- Base64 encode/decode layer
- Plugin system (shell, sysinfo, screenshot, persistence)
d. External Libraries & Tools
- pyinstaller – for compiling payloads
- Python 3 stdlib – sockets, subprocess, system APIs
e. Network Layer
- TCP socket channel (bidirectional)
- Base64-encoded command/response protocol

##### Relationships & interactions
1. Admin runs `server.py generate` → Payload Generator → Output: payload.py or payload executable.
2. Admin runs `server.py bind` → C2 Server listens on TCP.
3. Payload launched on target host → mods/main.py connects back to C2.
4. C2 Server registers session → Session Manager tracks client ID.
5. Admin uses `sessions` / `connect` → Dispatches command via Network layer.
6. Client receives command → Plugin loader (imports.py → dispatches to the correct module) → Executes then returns result.
7. C2 displays output in admin CLI.

##### Architectural patterns & design principles
- Modular plugin architecture for client features (each feature in its own module).
- Single-threaded, event-loop style in both server and client (serialize commands over a socket).
- Separation of concerns: generator vs C2 vs client.
- In-memory session management (no persistence).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Admin actions
    AdminCLI["Admin CLI"]:::external
    AdminCLI -->|"generate"| PayloadGen
    AdminCLI -->|"bind"| C2CLI

    %% Payload Generator
    subgraph "Payload Generator" 
        PayloadGen["PyInstaller / Raw .py"]:::generator
        Dependencies["requirements.txt"]:::external
    end
    click PayloadGen "https://github.com/hash3lizer/sillyrat/blob/master/server.py"
    click Dependencies "https://github.com/hash3lizer/sillyrat/blob/master/requirements.txt"

    PayloadGen -->|"output payload"| PayloadArtifact["Payload Artifact (.py / exe)"]:::generator
    PayloadArtifact -->|"deployed to target host"| TargetHost["Target Host"]:::external

    %% Client Payload
    subgraph "Client Payload" 
        Main["mods/main.py"]:::client
        ClientNet["mods/client.py"]:::client
        Consts["mods/consts.py"]:::client
        Imports["mods/imports.py"]:::client
        subgraph "Client Plugins"
            Sysinfo["mods/sysinfo.py"]:::client
            Screenshot["mods/screenshot.py"]:::client
            Persistence["mods/persistence.py"]:::client
        end
    end
    click Main "https://github.com/hash3lizer/sillyrat/blob/master/mods/main.py"
    click ClientNet "https://github.com/hash3lizer/sillyrat/blob/master/mods/client.py"
    click Consts "https://github.com/hash3lizer/sillyrat/blob/master/mods/consts.py"
    click Imports "https://github.com/hash3lizer/sillyrat/blob/master/mods/imports.py"
    click Sysinfo "https://github.com/hash3lizer/sillyrat/blob/master/mods/sysinfo.py"
    click Screenshot "https://github.com/hash3lizer/sillyrat/blob/master/mods/screenshot.py"
    click Persistence "https://github.com/hash3lizer/sillyrat/blob/master/mods/persistence.py"

    TargetHost -->|"TCP + Base64"| Main
    Main --> ClientNet
    Main --> Consts
    Main --> Imports
    Imports --> Sysinfo
    Imports --> Screenshot
    Imports --> Persistence

    %% C2 Server
    subgraph "C2 Server" 
        C2CLI["server.py CLI"]:::server
        NetListener["TCP Listener"]:::server
        SessionMgr["In-Memory Session Store"]:::database
        CmdDispatcher["Command Dispatcher"]:::server
    end
    click C2CLI "https://github.com/hash3lizer/sillyrat/blob/master/server.py"

    PayloadArtifact --- C2CLI

    NetListener --> SessionMgr
    C2CLI --> NetListener
    C2CLI --> SessionMgr
    SessionMgr --> CmdDispatcher

    Main -->|"TCP + Base64"| NetListener
    CmdDispatcher -->|"route commands"| Main
    Main -->|"return output"| CmdDispatcher
    CmdDispatcher --> C2CLI

    %% Styles
    classDef server fill:#B3CDE3,stroke:#034F84,color:#034F84;
    classDef client fill:#C7E9B4,stroke:#2E8B57,color:#2E8B57;
    classDef generator fill:#FDB462,stroke:#E66101,color:#E66101;
    classDef external fill:#F0F0F0,stroke:#A9A9A9,color:#696969;
    classDef database fill:#DECBE4,stroke:#7B3294,color:#7B3294;
```
