d1368b1877906275c6bdae2faf8f8a07396420bf
A/D Infrastructure Control System
A comprehensive infrastructure control system for Attack/Defense CTF competitions. Manages services, monitors attacks, sends alerts, and provides a unified web dashboard.
Features
🎮 Service Controller
- Start/stop/restart docker-compose services via API
- Auto-pull changes from git repositories
- Real-time service logs viewing
- Service action history tracking
🎯 Scoreboard Injector
- Real-time monitoring of ForcAD scoreboard WebSocket
- Automatic attack detection and classification
- Point loss threshold alerts
- Attack statistics by service
📱 Telegram Bot
- Automatic critical alert notifications
- Manual message sending via API
- Message delivery tracking
- Group chat integration
🌐 Web Dashboard
- Unified control panel for all services
- Real-time attack visualization
- Service management interface
- Alert monitoring and testing
Quick Start
One-Line Installation
curl -sSL https://raw.githubusercontent.com/YOUR-REPO/main/install.sh | bash
Manual Installation
- Clone the repository
git clone https://github.com/YOUR-USERNAME/attack-defence-infr-control.git
cd attack-defence-infr-control
- Configure environment
cp .env.example .env
# Edit .env with your configuration
nano .env
- Start the infrastructure
docker-compose up -d
- Access the dashboard
Open http://localhost:8000 in your browser (default password:
admin123)
Configuration
Required Environment Variables
Edit .env file:
# Database
POSTGRES_PASSWORD=your_secure_password
# Authentication
SECRET_TOKEN=your_random_secret_token
WEB_PASSWORD=your_web_password
# Telegram
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
# Game Settings
OUR_TEAM_ID=1
SCOREBOARD_WS_URL=ws://scoreboard:8080/api/events
Getting Telegram Credentials
- Create a bot with @BotFather
- Get your chat ID from @userinfobot
- Add bot to your group and make it admin
Service Setup
After starting the infrastructure, setup your A/D services:
cd setuper
./setup.sh
This will guide you through setting up:
- Packmate: Traffic analysis (https://gitlab.com/packmate/Packmate)
- moded_distructive_farm: Attack/Defense farm (https://github.com/ilyastar9999/moded_distructive_farm)
- Firegex: Flag regex checker (https://github.com/Pwnzer0tt1/firegex)
API Documentation
Controller API (Port 8001)
# List services
curl -H "Authorization: Bearer YOUR_TOKEN" http://localhost:8001/services
# Start a service
curl -X POST -H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"action": "start"}' \
http://localhost:8001/services/1/action
# Get service logs
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8001/services/1/logs?lines=100
Scoreboard Injector API (Port 8002)
# Get attack statistics
curl -H "Authorization: Bearer YOUR_TOKEN" http://localhost:8002/stats
# Get recent attacks
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8002/attacks?limit=50&attacks_to_us=true
# Get alerts
curl -H "Authorization: Bearer YOUR_TOKEN" http://localhost:8002/alerts
Telegram Bot API (Port 8003)
# Send message
curl -X POST -H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"message": "Test alert"}' \
http://localhost:8003/send
# Get message history
curl -H "Authorization: Bearer YOUR_TOKEN" http://localhost:8003/messages
Architecture
┌─────────────────────────────────────────────────────┐
│ Web Dashboard :8000 │
│ (Flask + Bootstrap + jQuery) │
└─────────────────────────────────────────────────────┘
│
┌────────────────┼────────────────┐
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Controller │ │ Scoreboard │ │ Telegram │
│ API :8001 │ │ Injector │ │ Bot :8003 │
│ │ │ :8002 │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
│ │ │
└────────────────┼────────────────┘
│
▼
┌──────────────┐
│ PostgreSQL │
│ Database │
└──────────────┘
Directory Structure
.
├── controler/ # Service controller API
│ ├── main.py
│ ├── requirements.txt
│ └── Dockerfile
├── scoreboard_injector/ # Attack monitor
│ ├── main.py
│ ├── requirements.txt
│ └── Dockerfile
├── tg-bot/ # Telegram notifications
│ ├── main.py
│ ├── requirements.txt
│ └── Dockerfile
├── web/ # Web dashboard
│ ├── app.py
│ ├── templates/
│ ├── requirements.txt
│ └── Dockerfile
├── setuper/ # Service setup scripts
│ ├── setup.sh
│ └── README.md
├── services/ # Managed services directory
├── docker-compose.yaml # Main compose file
├── init-db.sql # Database schema
└── .env.example # Configuration template
Database Schema
The system uses a single PostgreSQL instance with tables for:
services- Registered servicesservice_logs- Action historyattacks- Attack eventsattack_alerts- Generated alertstelegram_messages- Message logsettings- System configuration
Management Commands
# View all logs
docker-compose logs -f
# View specific service logs
docker-compose logs -f web
docker-compose logs -f controller
# Restart all services
docker-compose restart
# Stop all services
docker-compose down
# Stop and remove volumes
docker-compose down -v
# Rebuild after code changes
docker-compose up -d --build
Troubleshooting
Services won't start
# Check logs
docker-compose logs
# Verify .env configuration
cat .env
# Ensure ports are available
netstat -tulpn | grep -E '8000|8001|8002|8003'
Database connection errors
# Check PostgreSQL is running
docker-compose ps postgres
# Verify database credentials in .env
# Restart PostgreSQL
docker-compose restart postgres
WebSocket connection to scoreboard fails
- Verify
SCOREBOARD_WS_URLin.env - Check scoreboard is accessible
- Ensure firewall allows WebSocket connections
Security Considerations
- Change default passwords in
.env - Use strong random tokens for
SECRET_TOKEN - Restrict network access to API ports in production
- Enable HTTPS for web dashboard in production
- Regularly update Docker images
Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Submit a pull request
License
MIT License - see LICENSE file for details
Support
For issues and questions:
- Open an issue on GitHub
- Check existing documentation
- Review logs:
docker-compose logs -f
Credits
Built for Attack/Defense CTF competitions. Integrates with:
- ForcAD - CTF platform
- Packmate - Traffic analysis
- moded_distructive_farm - Attack farm
- Firegex - Flag checker
Languages
Python
61.9%
HTML
21.6%
Shell
13.5%
Makefile
2.4%
Dockerfile
0.6%