# darkrain2009/redext architecture

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

- Interactive diagram: https://gitdiagram.com/darkrain2009/redext
- Repository: https://github.com/darkrain2009/redext

## Overview

##### Project Overview and Main Components
- The project is a full-stack security tool combining a Chromium Manifest V3 extension (in the ext directory) with a Flask-based C2 server (in the server directory).
- Key components include:
a. Browser Extension:
- Background script (ext/background.js) running as a service worker.
- Content scripts (ext/content_script.js) interacting with the webpage DOM.
- Popup UI (ext/popup.html and ext/popup.js) for user interactions.
- Manifest configuration (ext/manifest.json) that defines permissions and behaviors.
b. Server Component:
- Flask server (server/c2_server.py) handling API requests, task management, and data storage.
- Database setup (server/db_setup.py and usage of SQLite3 as per the README).
- A set of HTML templates (server/templates) that power the dark-themed dashboard UI for managing tasks, viewing collected browser data (cookies, history, screenshots, clipboard, DOM, local storage, system reconnaissance, etc.).
- A requirements file (server/requirements.txt) that details dependencies (Flask, etc.).

##### Relationships and Interactions
- Browser Extension to Server Communication:
- The extension collects browser data (cookies, history, screenshots, etc.) and likely communicates with the server via RESTful JSON endpoints.
- Data flows from the extension (client-side) through network calls to the Flask server.
- Server’s Role:
- The Flask C2 server manages tasks (creation, deployment, monitoring) and processes incoming data, serving it via the dashboard.
- The SQLite database holds collected data which is rendered through multiple HTML templates.
- Client-Server Architecture:
- The extension operates as the distributed data collector.
- The dashboard provides operational control and visualization of the collected data.

##### Architectural Patterns and Design Principles
- Separation of concerns via the split between client (browser extension) and server (Flask application).
- Use of RESTful endpoints to facilitate communication between the extension and the C2 server.
- MVC-like pattern within the server: Templates (View), Python backend logic (Controller), and database operations (Model).
- Security-focused design ensuring that operations are for authorized red team use.

##### Key Technologies and Frameworks
- Python (3.8+) and Flask 2.2.5 for the backend.
- SQLite3 as the database engine.
- Chrome Extension development based on Manifest V3.
- HTML/CSS (and likely JavaScript) for both extension UI and the server’s dashboard.
- Optionally, RESTful API design principles to structure the interaction between the extension and server.

##### Final Advice
- Major data paths, particularly data collection from the browser to the server and the dashboard’s role in task monitoring/management, are clearly represented.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actors
    endUser("End User's Browser"):::external
    operator("Operator"):::external

    %% Browser Extension Components
    subgraph "Browser Extension"
        extManifest("Manifest File"):::client
        extBackground("Background Script"):::client
        extContent("Content Script"):::client
        extPopupHTML("Popup HTML"):::client
        extPopupJS("Popup JS"):::client
        extIcons("Icon Assets"):::client
    end

    %% Server Components
    subgraph "Server Component"
        serverFlask("Flask C2 Server"):::server
        serverReq("Requirements"):::server
        serverDbSetup("Database Setup"):::server
        serverTemplates("Dashboard Templates"):::server
        dbSQLite("SQLite Database"):::database
    end

    %% Relationships and Interactions
    %% End User browsing leads to data collection via Content Script.
    endUser -->|"browsing"| extContent

    %% Manifest configures all extension components.
    extManifest -->|"configures"| extBackground
    extManifest -->|"configures"| extContent
    extManifest -->|"configures"| extPopupHTML
    extManifest -->|"configures"| extPopupJS
    extManifest -->|"configures"| extIcons

    %% Communication within the Extension.
    extContent -->|"sends-data"| extBackground
    extPopupHTML -->|"triggers"| extBackground
    extPopupJS -->|"triggers"| extBackground

    %% Extension to Server Communication.
    extBackground -->|"REST_API"| serverFlask

    %% Server internal dependencies.
    serverReq -->|"dependency"| serverFlask
    serverDbSetup -->|"initializes"| dbSQLite
    serverFlask -->|"stores-data"| dbSQLite
    serverFlask -->|"renders"| serverTemplates

    %% Operator interacts with the Dashboard.
    operator -->|"views-dashboard"| serverTemplates

    %% Styles
    classDef client fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef server fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#1E8449,stroke-width:2px;

    %% Click Events for Browser Extension Components
    click extBackground "https://github.com/darkrain2009/redext/blob/main/ext/background.js"
    click extContent "https://github.com/darkrain2009/redext/blob/main/ext/content_script.js"
    click extPopupHTML "https://github.com/darkrain2009/redext/blob/main/ext/popup.html"
    click extPopupJS "https://github.com/darkrain2009/redext/blob/main/ext/popup.js"
    click extManifest "https://github.com/darkrain2009/redext/blob/main/ext/manifest.json"
    click extIcons "https://github.com/darkrain2009/redext/tree/main/ext/icons"

    %% Click Events for Server Components
    click serverFlask "https://github.com/darkrain2009/redext/blob/main/server/c2_server.py"
    click serverDbSetup "https://github.com/darkrain2009/redext/blob/main/server/db_setup.py"
    click serverReq "https://github.com/darkrain2009/redext/blob/main/server/requirements.txt"
    click serverTemplates "https://github.com/darkrain2009/redext/tree/main/server/templates"
```
