Autonomous AI Proxy Firewall with CNN-based threat detection. Acts as a transparent reverse proxy between clients and your backend server. Every request AND every reply is inspected in real-time.
Attacker / Client
β
βΌ
βββββββββββββββββββββββββββββββββββββββ
β NEURAL-GATE PROXY β β FastAPI on port 8000
β β
β 1. PCAP Capture (raw packet bytes) β
β 2. IDS Engine (Snort-style rules) β
β 3. SIEM Correlator (event store) β
β 4. AI Multi-Agent CNN Analysis β
β βββ CNN Header Inspector β
β βββ CNN Body Inspector β
β βββ GRU Temporal Tracker β
β βββ Entropy Analyzer β
β 5. SOAR Automation (playbooks) β
β 6. Firewall (block / allow / deny) β
β 7. Egress Reply Inspector β
βββββββββββββββββββββββββββββββββββββββ
β β
βΌ βΌ
Backend Server SOC Dashboard
(your app) WebSocket ws://localhost:8000/ws/soc
- Reverse Proxy: Forwards traffic from clients to your target backend server
- Ingress Pipeline: Analyzes incoming requests with multi-stage inspection
- IDS Engine: Signature-based detection (SQLi, XSS, DDoS, path traversal, etc.)
- CNN Detection: Deep learning PyTorch model for threat classification
- SIEM Logging: Event storage, correlation, and search
- SOAR Automation: Automated threat response (blocking, alerting, playbooks)
- Egress Pipeline: Response analysis for data exfiltration detection
- Blocklist API: Auto-blocking of malicious IPs with configurable TTL
- Dual AI Agents: Reflex (reactive) and Planning (proactive) agents
- Pre-trained Model: PyTorch CNN+GRU model ready to use
- RESTful API: Full CRUD for IDS rules, SOAR policies, SIEM events, blocklist
- SOC Dashboard: Real-time WebSocket event monitoring at
/soc
- Raw Packet Capture: Uses Scapy for network-level inspection
- BPF Filtering: Efficient packet filtering at capture time
- PCAP Export: Save traffic dumps for forensic analysis
- TCP/IP Analysis: Layer 3/4 network traffic inspection
π Phase 2 Setup Guide | π§ Quick Start Script | β Verification Tool | π Quick Reference
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txtpython scripts/train_model.pyThis generates app/models/neural_gate_cnn.pt
Edit config.py:
TARGET_SERVER = "http://localhost:3001" # internal backend in transparent mode
PROXY_PORT = 8000uvicorn app.main:app --host 0.0.0.0 --port 8000 --reloadIf startup fails with Errno 98 (address already in use):
bash scripts/fix_error_98.sh 8000 3000 3001Note: For Phase 2 PCAP capture, see PHASE2_PCAP.md for setup instructions.
Instead of hitting http://your-server:3000 directly,
clients hit http://your-server:8000 β Neural-Gate proxies everything.
Open neural-gate-siem.html in your browser.
It connects to ws://localhost:8000/ws/soc automatically.
In this mode, attackers target the vulnerable app port (3000), but traffic is invisibly redirected through Neural-Gate:
- Public attack target:
127.0.0.1:3000 - Neural-Gate proxy:
127.0.0.1:8000 - Real backend app:
127.0.0.1:3001
Start transparent mode:
chmod +x start_transparent.sh scripts/transparent_on.sh scripts/transparent_off.sh
./start_transparent.shRun attacks against the public app port (not the proxy):
NG_ATTACK_BASE_URL=http://127.0.0.1:3000 ./run_attack_test.shDisable transparent redirect when done:
sudo bash scripts/transparent_off.sh 3000 8000localhost by default. Set NG_ALLOW_ATTACK_DEMOS=1 and NG_ATTACK_ALLOWLIST=your-staging-host environment variables for authorized staging tests only.
The scripts/ folder contains attack scripts you can run against the proxy:
# SQL Injection
python scripts/attack_sqli.py
# XSS
python scripts/attack_xss.py
# DDoS flood
python scripts/attack_ddos.py
# Data exfiltration simulation (triggers egress check)
python scripts/attack_exfil.py
# Run all attacks in sequence
python scripts/attack_all.pyOr use the end-to-end attack runner:
# Through transparent public app port (recommended)
NG_ATTACK_BASE_URL=http://127.0.0.1:3000 ./run_attack_test.sh
# Directly through Neural-Gate proxy (debug mode)
NG_ATTACK_BASE_URL=http://127.0.0.1:8000 ./run_attack_test.sh
# Directly against vulnerable server (comparison mode)
NG_ATTACK_BASE_URL=http://127.0.0.1:3001 ./run_attack_test.shManual analyst feedback (adaptive RL-style learning):
# Inspect recent events and copy a fingerprint value
curl "http://127.0.0.1:8000/api/siem/events?limit=50"
# Mark traffic pattern as legit
curl -X POST http://127.0.0.1:8000/api/adaptive/feedback \
-H "Content-Type: application/json" \
-d '{"fingerprint":"<PASTE_FINGERPRINT>","label":"legit","source_ip":"127.0.0.1"}'
# Mark traffic pattern as malicious
curl -X POST http://127.0.0.1:8000/api/adaptive/feedback \
-H "Content-Type: application/json" \
-d '{"fingerprint":"<PASTE_FINGERPRINT>","label":"malicious","source_ip":"127.0.0.1"}'
# Check adaptive memory stats
curl http://127.0.0.1:8000/api/adaptive/stats| Method | Endpoint | Description |
|---|---|---|
| GET | /api/logs | All incident logs (paginated) |
| GET | /api/logs?type=sqli | Filter by attack type |
| GET | /api/logs?sev=critical | Filter by severity |
| GET | /api/stats | Live counters (blocked, denied...) |
| GET | /api/blocklist | Currently blocked IPs |
| DELETE | /api/blocklist/{ip} | Unblock an IP |
| POST | /api/killswitch | Kill all traffic |
| DELETE | /api/killswitch | Re-enable traffic |
| GET | /api/agents | Current CNN agent scores |
| GET | /api/siem/events | SIEM event stream (REST view) |
| GET | /api/adaptive/stats | Adaptive learning memory stats |
| POST | /api/adaptive/feedback | Manual analyst feedback (legit/malicious) |
| POST | /api/adaptive/reset | Reset adaptive memory/state |
| GET | /health | Health check |
Connect to ws://localhost:8000/ws/soc
Every event is JSON:
{
"event": "threat_blocked",
"timestamp": "2026-03-07T20:45:12Z",
"source_ip": "185.220.101.47",
"attack_type": "sqli",
"severity": "critical",
"phase": "CNN β SOAR",
"agents": {
"header_score": 0.91,
"body_score": 0.97,
"gru_score": 0.88,
"entropy": 7.2
},
"confidence": 0.97,
"action": "BLOCKED",
"message": "SQL injection detected in POST body targeting /api/login"
}Event types: threat_blocked, reply_denied, request_allowed,
ids_alert, soar_action, kill_switch, agent_update
Input: 1024-byte packet payload as float32 vector
β
βββ Conv1D(32 filters, kernel=8, ReLU)
βββ MaxPool1D(4)
βββ Conv1D(64 filters, kernel=4, ReLU)
βββ MaxPool1D(4)
βββ Conv1D(128 filters, kernel=3, ReLU)
βββ AdaptiveAvgPool
βββ GRU(hidden=64, layers=2, bidirectional)
βββ Dropout(0.4)
βββ Linear β Sigmoid β P(malicious) [0..1]
Threshold: P > 0.85 β BLOCK
Located in app/pipeline/ids_rules.py
Rules cover: SQLi, XSS, LFI, RFI, Command Injection, XXE, SSRF,
Port Scans, DDoS patterns, Shellcode, Reverse shells
neural-gate/
βββ app/
β βββ main.py # FastAPI app, proxy logic, WebSocket
β βββ config.py # All configuration
β βββ agents/
β β βββ cnn_model.py # PyTorch CNN+GRU model definition
β β βββ header_agent.py # CNN Header Inspector
β β βββ body_agent.py # CNN Body Inspector
β β βββ gru_agent.py # GRU Temporal Tracker
β β βββ entropy_agent.py # Entropy Analyzer
β β βββ egress_agent.py # Reply Inspector (exfiltration)
β βββ pipeline/
β β βββ pcap_capture.py # Packet capture & feature extraction
β β βββ ids_engine.py # Snort-style signature matching
β β βββ siem.py # Event correlation & log store
β β βββ soar.py # Automated response playbooks
β βββ api/
β βββ routes.py # REST API routes
β βββ websocket.py # SOC WebSocket manager
βββ scripts/
β βββ train_model.py # Train CNN on synthetic data
β βββ attack_sqli.py # SQLi attack demo
β βββ attack_xss.py # XSS attack demo
β βββ attack_ddos.py # DDoS attack demo
β βββ attack_exfil.py # Exfiltration attack demo
β βββ attack_all.py # Run all attacks
βββ config.py # Root config
βββ requirements.txt
βββ neural-gate-siem.html # SOC Dashboard (WebSocket frontend)
βββ README.md
Phase 1 (HTTP-level): Default mode, analyzes HTTP requests/responses Phase 2 (PCAP): Advanced mode with raw packet capture
Enable Phase 2:
export NG_ENABLE_PHASE2_PCAP=true
export NG_PCAP_INTERFACE=lo # or eth0, wlan0, etc.See PHASE2_PCAP.md for complete Phase 2 documentation.
Create a .env file in the repository root to override defaults:
NG_ENVIRONMENT=production
NG_TARGET_SERVER=http://localhost:3001
NG_PROXY_HOST=0.0.0.0
NG_PROXY_PORT=8000
NG_REQUEST_TIMEOUT_SECONDS=15.0
NG_MALICIOUS_THRESHOLD=0.85
NG_ENTROPY_THRESHOLD=7.0
NG_EXFILTRATION_ENTROPY_THRESHOLD=7.5
NG_ENABLE_PHASE2_PCAP=false
NG_ENABLE_ADAPTIVE_LEARNING=true
NG_ADAPTIVE_LEARNING_RATE=0.15
NG_ADAPTIVE_INFLUENCE=0.12
NG_ADAPTIVE_MEMORY_SIZE=5000
NG_ADAPTIVE_PERSIST_PATH=app/models/adaptive_memory.json
NG_ADAPTIVE_AUTOSAVE_EVERY=50
NG_BLOCKLIST_TTL_SECONDS=1800
NG_DDOS_WINDOW_SECONDS=10
NG_DDOS_MAX_REQUESTS=120
# Attack demo safety controls (for testing only)
NG_ALLOW_ATTACK_DEMOS=0
NG_ATTACK_ALLOWLIST=localhost,127.0.0.1The current implementation runs as a single FastAPI process. To split into independent services:
- Proxy Gateway: Keep
app/main.pybut remove pipeline/agent initialization. - Analytics Worker: Run IDS/SIEM/SOAR pipeline with message queue (e.g. RabbitMQ, Redis Streams).
- SOAR Service: Extract
app/pipeline/soar.pyto standalone decision service. - Agents Service: Extract
app/agents/into inference pool with gRPC or REST API.
Currently, the system uses HTTP-level feature extraction (app/pipeline/pcap_capture.py β extract_request_features).
To enable real packet capture:
- Set
NG_ENABLE_PHASE2_PCAP=truein.env. - Implement a packet capture backend in
pcap_capture.pyusingscapyorpyshark. - Extract raw bytes before FastAPI framework sees the request (via middleware or raw socket layer).
- Map captured packets to session/flow tracking for temporal GRU agent.
MIT License - use at your own risk. This is a defensive security research project.