How pwn3rx0/simple-c2 works
Project Type and Purpose
• This is a lightweight Command-and-Control (C2) tool.
• It consists of a Flask-based Python server (c2.py + templates/index.html) that provides a web UI and HTTP APIs, plus two Go agents (linux.go, windows.go) that register with the server, pull commands, execute them locally, and push back output.
File Structure
• Top level:
• README.md – project overview, setup & usage
• c2.py – Flask server entry point and API definitions
• templates/index.html – single-page UI for issuing commands and viewing output
• agents/ directory:
• linux.go & windows.go – Go source code for cross-platform agents
• No external database or persistent store; client state is likely held in memory within the Flask app.
README Insights
• Server: Python 3.8+, Flask
• Agents: Go 1.18+, compile per target OS
• Features: client registration, command dispatch (to one/all), real-time output streaming, auto cleanup
• Communication: HTTP(S) between server and agents; UI uses standard Flask rendering, possibly Server-Sent Events or polling for real-time updates.
Main Components
a. Web Browser (Operator UI)
b. Flask Server
• HTTP API endpoints
• In-memory data structures (client registry, command queue)
c. Agents
• Windows Agent (windows.go)
• Linux Agent (linux.go)
d. External Interfaces (optional)
• HTTP(S) network boundary
• cmd.exe on Windows / shell on Linux
Relationships & Data Flows
1. Operator uses Web Browser → HTTP GET/POST → Flask Server UI/API
2. Flask Server enqueues command(s) in memory, tagged by client ID or “broadcast”
3. Agent polls or opens a persistent connection (e.g., long-poll/SSE) → HTTP GET → Flask Server retrieves pending commands
4. Agent executes command locally (cmd.exe or shell) → captures stdout/stderr
5. Agent sends execution output → HTTP POST → Flask Server
6. Flask Server pushes output to the Web Browser (via HTTP long-poll, SSE or WebSocket channel)
Architectural Patterns & Principles
• Client–Server pattern over HTTP
• Publish/Subscribe at a basic level: agent “subscribes” to commands, operator subscribes to output streams
• In-memory state store (no persistent database) for simplicity
• Clear separation of concerns: UI layer (templates), API layer (c2.py routing), agent logic