# alexevgmart/pwn_defense_for_ctf architecture

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

- Interactive diagram: https://gitdiagram.com/alexevgmart/pwn_defense_for_ctf
- Repository: https://github.com/alexevgmart/pwn_defense_for_ctf

## Overview

##### Project Overview and Purpose
- The README makes it clear that this system is built to secure binary services in a CTF setting. Its purpose is to monitor and restrict non-printable characters in system I/O (via a Linux kernel module) while also providing a networked monitoring and control interface.
- The system is divided into multiple pieces: a kernel-space module that adds syscall monitoring, a user-space component that interacts with this low-level module, a set of server-side components (including a TCP server and a web application built with Docker), and a lightweight HTTP proxy (implemented in Go) for routing traffic.

##### Main Architectural Components
a. Kernel Module (kernel_module directory):
- Contains a Linux kernel module (with files like read_and_write.c, ftrace_helper.h, user.c, and the Makefile).
- It intercepts sys_read and sys_write to filter non-printable characters.
- Runs on a dedicated host, isolated from general network access.
b. User-Space Binary:
- Located within the kernel_module folder (the “user” binary).
- It sends data to the server (using the provided server IP/port) from the same host where the kernel module runs.
c. Server Components (server directory):
- Contains environment settings (.env), docker-compose configuration, and sub-components.
- Rules:
- The “rules” folder holds multiple JSON files that define formatting or validation rules (e.g., addr.json, flag.json, etc.), which likely configure or inform both data validation and potential filtering mechanisms.
- TCP Server:
- In the folder server/tcp_server, a Dockerfile and tcp_server.py are included – this component likely handles network communications for binary services.
- Web Application:
- In server/web_app, there’s a Dockerfile, various static assets (CSS/JS), and templates (for rendering the editor, login, etc.).
- Also includes a services.json file which is crucial for configuring redirection (pointing to real backend services).
- The web server (web_server.py) serves the monitoring/control interface.
d. Proxy (proxy directory):
- Contains a Go module (proxy/go.mod, proxy/proxy.go).
- Acts as a “pseudo_http_proxy” that accepts HTTP requests from hosts in the general network and routes them to the internal web application’s host/port.
- This component is set up so that external access is funneled safely to the dedicated web services.

##### Relationships and Data Flow
- The kernel module runs on an isolated host, monitoring system calls. Its associated “user” binary sends monitoring data from this host to the central server.
- The central server has at least two main parts:
– A TCP server designed to handle specific binary service communications.
– A web application deployed via Docker (along with its associated configuration/settings and static/dynamic files) that presents the monitoring dashboard or control UI.
- The Go-based proxy sits on a host exposed to the public network. It receives HTTP traffic and routes it to the web application (using configuration from services.json).
- The system is partitioned based on security: the internal host (running kernel module and user binary) is isolated, while web access occurs on a separate, controlled host with the proxy mediating public access.

##### Architectural Patterns and Technologies
- Separation of Concerns / Tiered Architecture: The system clearly separates kernel-space monitoring, user-level data sending, service processing (via TCP server and web app), and external HTTP proxying.
- Containerization: The web app and TCP server use Docker for isolation and deployment, as shown by Dockerfiles and docker-compose.yml.
- Modular Design: Each module is self-contained (kernel module, proxy, server components) and interacts with others via defined interfaces (e.g., sending data over the network or via configuration JSONs).
- Use of configuration files (such as JSON rule sets and services.json) shows an emphasis on flexible, pluggable components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Internal Host Zone
    subgraph "Internal Host Zone"
        A["Kernel Module (syscall interceptor)"]:::internal
        B["User Application (data sender)"]:::internal
    end

    %% Server Zone
    subgraph "Server Zone"
        C["TCP Server (containerized binary service)"]:::server
        D["Web Application (Dockerized Python server)"]:::server
        E["Rules/Configuration Sources"]:::server
    end

    %% External/Public Zone
    subgraph "External/Public Zone"
        G["External Client"]:::external
        F["HTTP Proxy (Go-based external routing proxy)"]:::external
    end

    %% Connections/Flow
    A -->|"triggers"| B
    B -->|"sends_data"| C
    B -->|"sends_data"| D
    D -->|"uses_config"| E
    G -->|"requests"| F
    F -->|"routes_to"| D

    %% Click Events
    click A "https://github.com/alexevgmart/pwn_defense_for_ctf/tree/main/kernel_module/"
    click B "https://github.com/alexevgmart/pwn_defense_for_ctf/blob/main/kernel_module/user.c"
    click C "https://github.com/alexevgmart/pwn_defense_for_ctf/tree/main/server/tcp_server/"
    click D "https://github.com/alexevgmart/pwn_defense_for_ctf/tree/main/server/web_app/"
    click E "https://github.com/alexevgmart/pwn_defense_for_ctf/tree/main/server/rules/"
    click F "https://github.com/alexevgmart/pwn_defense_for_ctf/tree/main/proxy/"

    %% Styles
    classDef internal fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef server fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef external fill:#ccccff,stroke:#333,stroke-width:2px;
```
