A educational Command and Control (C2C) server implementation written in Python 3.12, designed for cybersecurity learning and research purposes.
This project is for educational and research purposes only. It should only be used in controlled environments with proper authorization. The authors are not responsible for any misuse of this software.
- Web-based Dashboard: Real-time monitoring of active sessions
- RESTful API: Easy integration with various clients
- Multiple Client Examples: Bash, PowerShell, and Python implementations
- Docker Support: Easy deployment and isolation
- Session Management: Track and manage multiple client connections
- Real-time Updates: WebSocket-based live updates in the dashboard
- Cross-platform: Works on Linux, macOS, and Windows
- Authentication & Authorization: JWT-based authentication with role-based access
- HTTPS/TLS Support: End-to-end encryption for all communications
- Database Persistence: PostgreSQL backend for reliable data storage
- Redis Caching: High-performance session and command caching
- Rate Limiting: Protection against abuse and DoS attacks
- API Versioning: Backward compatibility and API evolution
- Comprehensive Logging: Structured logging with multiple levels
- Health Monitoring: Prometheus metrics and health checks
- Input Validation: Comprehensive input sanitization and validation
- CORS Configuration: Secure cross-origin resource sharing
- Environment Configuration: Flexible configuration management
- Docker Production Setup: Multi-stage builds and security hardening
graph TB
subgraph "Client Side"
C1[Client Agent 1]
C2[Client Agent 2]
CN[Client Agent N]
end
subgraph "Server Side"
LB[Load Balancer/Nginx]
API[Flask API Server]
WS[WebSocket Handler]
DB[(Database)]
REDIS[(Redis Cache)]
end
subgraph "Admin Interface"
WEB[Web Dashboard]
ADMIN[Admin Panel]
end
C1 -->|HTTPS REST API| LB
C2 -->|HTTPS REST API| LB
CN -->|HTTPS REST API| LB
LB --> API
API --> DB
API --> REDIS
WEB -->|WebSocket| WS
ADMIN -->|WebSocket| WS
WS --> API
API -->|Real-time updates| WS
sequenceDiagram
participant C as Client Agent
participant API as C2C Server API
participant DB as Database
participant WS as WebSocket
participant DASH as Dashboard
Note over C,DASH: Session Registration
C->>+API: POST /api/register
API->>+DB: Store session data
DB-->>-API: Session created
API-->>-C: Session ID + Auth token
API->>WS: New session event
WS->>DASH: Update session list
Note over C,DASH: Heartbeat Loop
loop Every 30 seconds
C->>API: POST /api/heartbeat/{session_id}
API->>DB: Update last_seen
API->>WS: Session update
WS->>DASH: Update session status
end
Note over C,DASH: Command Execution
DASH->>+API: POST /api/command/{session_id}
API->>+DB: Store command
DB-->>-API: Command queued
API->>WS: Command sent event
WS->>DASH: Show command sent
API-->>-DASH: Command queued
C->>+API: GET /api/commands/{session_id}
API->>+DB: Get pending commands
DB-->>-API: Command list
API-->>-C: Pending commands
C->>C: Execute command
C->>+API: POST /api/response/{session_id}
API->>+DB: Store response
DB-->>-API: Response saved
API->>WS: Response received event
WS->>DASH: Show command output
API-->>-C: Response acknowledged
Note over C,DASH: Session Cleanup
DASH->>+API: DELETE /api/session/{session_id}
API->>+DB: Delete session
DB-->>-API: Session deleted
API->>WS: Session deleted event
WS->>DASH: Remove from session list
API-->>-DASH: Session deleted
-
Clone the repository:
git clone <your-repo-url> cd simple-c2c
-
Build and run with Docker Compose:
docker-compose up --build
-
Access the dashboard: Open your browser and navigate to
http://localhost:8080
-
Install dependencies:
pip install -r requirements.txt
-
Run the server:
python app.py
-
Access the dashboard: Open your browser and navigate to
http://localhost:8080
- Docker and Docker Compose
- SSL certificates (or use self-signed for testing)
- Proper firewall configuration
- Backup strategy for data
-
Clone and configure:
git clone <your-repo-url> cd simple-c2c cp .env.example .env
-
Edit environment variables:
nano .env
Update the following critical values:
POSTGRES_PASSWORD: Strong database passwordREDIS_PASSWORD: Strong Redis passwordSECRET_KEY: Long random secret keyJWT_SECRET_KEY: JWT signing secretCORS_ORIGINS: Your domain(s)
-
Deploy with production script:
./deploy-prod.sh
-
Access services:
- Dashboard:
https://localhost - Prometheus:
http://localhost:9090 - Grafana:
http://localhost:3000
- Dashboard:
# Start infrastructure
docker-compose -f docker-compose.prod.yml up -d postgres redis
# Wait for services and run migrations
docker-compose -f docker-compose.prod.yml run --rm c2c-app python migrate.py upgrade
# Create admin user
docker-compose -f docker-compose.prod.yml run --rm c2c-app python migrate.py create-admin
# Start all services
docker-compose -f docker-compose.prod.yml up -d# Make the script executable
chmod +x examples/client.sh
# Run with default server (localhost:8080)
./examples/client.sh
# Run with custom server
./examples/client.sh http://192.168.1.100:8080# Run with default server
.\examples\client.ps1
# Run with custom server
.\examples\client.ps1 -ServerUrl "http://192.168.1.100:8080"# Install requirements first
pip install requests
# Run with default server
python examples/client.py
# Run with custom server
python examples/client.py http://192.168.1.100:8080curl -X POST http://localhost:8080/api/register \
-H "Content-Type: application/json" \
-d '{"hostname":"test-host","username":"testuser","os":"Linux","arch":"x86_64"}'curl -X POST http://localhost:8080/api/heartbeat/YOUR_SESSION_IDcurl http://localhost:8080/api/commands/YOUR_SESSION_IDcurl -X POST http://localhost:8080/api/response/YOUR_SESSION_ID \
-H "Content-Type: application/json" \
-d '{"command":"ls","response":"file1.txt\nfile2.txt"}'| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Web dashboard |
| POST | /api/register |
Register new client session |
| POST | /api/heartbeat/<session_id> |
Update session activity |
| GET | /api/commands/<session_id> |
Get pending commands |
| POST | /api/command/<session_id> |
Send command to session |
| POST | /api/response/<session_id> |
Submit command response |
| GET | /api/sessions |
List all active sessions |
| GET | /api/session/<session_id> |
Get session details |
| DELETE | /api/session/<session_id> |
Delete session |
| GET | /health |
Health check |
SECRET_KEY: Flask secret key (change in production)FLASK_ENV: Flask environment (development/production)C2C_SERVER_URL: Default server URL for clients
Edit docker-compose.yml to customize:
- Port mapping
- Environment variables
- Volume mounts
- JWT-based authentication with configurable token expiration
- Role-based access control (admin, operator, viewer)
- Password hashing using bcrypt
- Session management with secure cookies
- HTTPS/TLS encryption for all communications
- Rate limiting to prevent abuse and DoS attacks
- CORS configuration for secure cross-origin requests
- Nginx reverse proxy with security headers
- IP-based session limits to prevent session flooding
- Schema validation using Marshmallow
- Command length limits to prevent large payloads
- SQL injection protection via SQLAlchemy ORM
- XSS protection with secure templating
- Comprehensive audit logging of all actions
- Structured logging with configurable levels
- Prometheus metrics for monitoring
- Health checks for service monitoring
- Database persistence for audit trails
- Docker security with non-root user and minimal images
- Environment-based configuration for secrets
- Database isolation with dedicated users
- Redis authentication for cache security
- Multi-stage Docker builds for smaller attack surface
- Secret management via environment variables
- SSL certificate configuration
- Firewall recommendations for port restrictions
- Educational purposes only - Implement additional security measures for real production use
- Regular security updates - Keep all dependencies and base images updated
- Network isolation - Use proper network segmentation in production
- Backup security - Encrypt backups and store securely
- Access control - Implement proper user management and access controls
- Monitoring - Set up alerting for suspicious activities
simple-c2c/
├── app.py # Development Flask application
├── app_prod.py # Production Flask application
├── config.py # Environment-based configuration
├── models.py # Database models
├── migrate.py # Database migration utilities
├── requirements.txt # Development dependencies
├── requirements-prod.txt # Production dependencies
├── Dockerfile # Development Docker configuration
├── Dockerfile.prod # Production Docker configuration
├── docker-compose.yml # Development Docker Compose
├── docker-compose.prod.yml # Production Docker Compose
├── nginx.conf # Nginx reverse proxy configuration
├── prometheus.yml # Prometheus monitoring configuration
├── deploy-prod.sh # Production deployment script
├── .env.example # Environment variables template
├── templates/
│ └── index.html # Web dashboard
├── examples/
│ ├── client.sh # Bash client
│ ├── client.ps1 # PowerShell client
│ └── client.py # Python client
├── docs/
│ ├── API.md # API documentation
│ └── TESTING.md # Testing guide
├── ssl/ # SSL certificates directory
├── logs/ # Application logs
├── data/ # Persistent data
└── README.md # This file
- New API endpoints: Add routes in
app.py - Client functionality: Modify client scripts in
examples/ - Dashboard features: Update
templates/index.html - Dependencies: Update
requirements.txt
-
Port already in use:
# Change port in docker-compose.yml or kill existing process lsof -ti:8080 | xargs kill -9
-
Client connection issues:
- Verify server is running:
curl http://localhost:8080/health - Check firewall settings
- Verify correct server URL
- Verify server is running:
-
Permission denied on scripts:
chmod +x examples/client.sh
- Docker logs:
docker-compose logs -f - Application logs: Check console output when running locally
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This software is provided for educational and research purposes only. Users must:
- Only use this software in authorized environments
- Comply with all applicable laws and regulations
- Not use this software for malicious purposes
- Take full responsibility for their use of this software
This project is licensed under the MIT License - see the LICENSE file for details.
- Flask and Flask-SocketIO for the web framework
- Bootstrap for the responsive UI
- Font Awesome for icons
- Basic C2C server functionality
- Web dashboard with real-time updates
- Multiple client implementations
- Docker support
- Basic session management
- Authentication and authorization
- Database persistence (PostgreSQL)
- Redis caching and session management
- Rate limiting and security headers
- Comprehensive logging and monitoring
- Docker production deployment
- Nginx reverse proxy
- SSL/TLS support
- Input validation and sanitization
- Audit logging
- File upload/download capabilities
- Command scheduling and queuing
- Plugin system for extensibility
- Multi-user collaboration
- Advanced client management
- Encrypted client communications
- Mobile-responsive dashboard
- Backup and recovery tools
- High availability setup
- Load balancing support
- Advanced threat detection
- Integration with SIEM systems
- Custom alerting rules
- API versioning and documentation
- Kubernetes deployment
- Advanced analytics and reporting