Architecture Overview
The traffic capture system consists of three main components:- ProxyController - WebSocket proxy endpoint that bridges TCP connections
- RecordableNetworkStream - Wrapper that captures traffic to storage
- PCAP Writer - Generates standard PCAP files for analysis tools
Platform Proxy Mode
Configuration
Enable platform proxy inappsettings.json:
PortMappingType options:
Default- Direct port mapping (Docker) or NodePort (K8s)PlatformProxy- WebSocket proxy through GZCTFRandomize- Direct mapping with randomized ports
/src/GZCTF/Controllers/ProxyController.cs:50-53
Proxy Endpoints
Standard Proxy (with game instance)
Standard Proxy (with game instance)
- Connection limiting (max 32 concurrent connections)
- Traffic capture with metadata
- Container validation caching
- Automatic timeout (30 minutes)
/src/GZCTF/Controllers/ProxyController.cs:56-116Test Proxy (no instance)
Test Proxy (no instance)
- Admin access only
- No game instance association required
- No connection limits
- No traffic recording
/src/GZCTF/Controllers/ProxyController.cs:119-163Connection Flow
Container Validation
Before establishing a proxy connection, the controller validates:Container Validation
-1 to prevent repeated database queries during attacks.
Reference: /src/GZCTF/Controllers/ProxyController.cs:316-330
Connection Limiting
Each container has a connection limit to prevent abuse:/src/GZCTF/Controllers/ProxyController.cs:337-352
TCP Socket Creation
TCP Connection Establishment
/src/GZCTF/Controllers/ProxyController.cs:168-181
WebSocket Proxy
Bidirectional Forwarding
The proxy runs two concurrent tasks for bidirectional forwarding:Proxy Implementation
- 4KB buffer size for optimal throughput
- ArrayPool for reduced allocations
- 30-minute connection timeout
- Binary WebSocket frames
- Graceful close on TCP disconnect
/src/GZCTF/Controllers/ProxyController.cs:229-308
Traffic Capture
RecordableNetworkStream
TheRecordableNetworkStream wraps a TCP socket and captures all traffic:
Stream Configuration
/src/GZCTF/Controllers/ProxyController.cs:109-115
Metadata Injection
Each PCAP file starts with JSON metadata:Metadata Generation
/src/GZCTF/Controllers/ProxyController.cs:103-104
PCAP File Format
Traffic is captured in standard PCAP format compatible with Wireshark:Storage Path Convention
Traffic File Path
capture/42/101/abc123-def456/conn_789.pcap
Traffic Analysis
Downloading Captures
Admins can download PCAP files via the game monitor:Download Traffic
Wireshark Analysis
PCAP files can be opened directly in Wireshark:Filtering Traffic
Wireshark display filters for common analysis:Security Considerations
Connection Limits
Default limits prevent abuse:- 32 concurrent connections per container
- 30-minute timeout per connection
- 10-minute validation cache to prevent DoS
ProxyController.cs if needed:
IP Address Handling
Client IPs are captured for traffic analysis:/src/GZCTF/Controllers/ProxyController.cs:95-99
Storage Integration
Traffic captures work with all GZCTF storage backends:Local Storage
Stores PCAP files in
files/capture/Best for testing and small competitions.S3/MinIO
Stores captures in S3-compatible object storage.Recommended for production with automatic cleanup.
Azure Blob
Stores in Azure Blob Storage containers.Integrates with Azure ecosystem.
Performance Optimization
Buffer Tuning
Default buffer size is 4KB. Increase for high-throughput scenarios:Connection Pooling
The proxy reuses WebSocket connections efficiently:- Uses
ArrayPool<byte>to reduce GC pressure - Async I/O prevents thread blocking
- Cancellation tokens enable clean shutdown
Capture Overhead
Traffic capture adds minimal overhead:- Async writes to storage (non-blocking)
- Buffered I/O reduces syscalls
- No packet parsing (raw capture)
Debugging Proxy Issues
Enable Debug Logging
appsettings.json
Common Issues
Connection Refused
Connection Refused
Symptoms:
SocketException: Connection refusedCauses:- Container not running or not ready
- Wrong port configuration
- Network policy blocking traffic
WebSocket Upgrade Failed
WebSocket Upgrade Failed
Symptoms: HTTP 400/403 on WebSocket upgradeCauses:
- Platform proxy disabled
- Container validation failed
- Connection limit reached
Traffic Capture Not Working
Traffic Capture Not Working
Symptoms: PCAP files not createdCauses:
EnableTrafficCapture = false- Storage backend not configured
- Insufficient storage permissions
Client-Side Integration
Players connect via WebSocket from their browser:Client-Side Connection
Next Steps
Container Providers
Configure Docker/K8s for platform proxy mode
Integrations
Set up external storage for traffic captures