Advanced Threat Detection with Red-Team AI & Cyber DNA Fingerprinting
✅ Red-Team AI - Attacker psychology and intent analysis
✅ Cyber DNA Fingerprinting - Threat similarity detection & lineage tracking
✅ Fraud Recovery Assistant - AI-powered recovery guidance for cyber threat victims ⭐ NEW
✅ Unified FastAPI Backend - Single API for all detection types
✅ Complete Logging - JSONL audit trail with export capabilities
✅ Performance Optimized - Async operations, caching, <3s response times
✅ OTP Email Verification - Secure email-based authentication for all users
- Python 3.8+
- Hugging Face account (free)
- 4GB RAM minimum
# Navigate to backend
cd backend
# Create virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/Mac
# Install dependencies
pip install -r requirements.txt# Copy environment template
copy .env.example .env # Windows
# cp .env.example .env # Linux/Mac
**Required in `.env`:**
```bash
HF_API_TOKEN=hf_YourActualTokenHereOptional - Email Verification (Recommended):
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@gmail.com
SMTP_PASSWORD=your_app_password
FROM_EMAIL=your_email@gmail.comNote: Email verification works in development mode without SMTP configuration. OTP codes will be printed to the console for testing. See OTP_VERIFICATION_GUIDE.md for details.
# Start FastAPI server
python main.py
# Or with uvicorn
uvicorn main:app --reload --host 0.0.0.0 --port 8000Server running at:
- API: http://localhost:8000
- Docs: http://localhost:8000/docs
- Health: http://localhost:8000/health
POST /scan/text
{
"text": "Urgent! Verify your account now!",
"enable_redteam": true,
"enable_dna": true
}POST /scan/url
{
"url": "http://suspicious-site.com",
"enable_redteam": true,
"enable_dna": true
}POST /scan/image
{
"image_base64": "base64_encoded_image_data",
"enable_redteam": true,
"enable_dna": true
}POST /scan/email
{
"subject": "Account Verification Required",
"body": "Click here to verify...",
"sender": "noreply@bank.com",
"enable_redteam": true,
"enable_dna": true
}POST /recovery/analyze
{
"threat_data": {
"scan_id": "abc123",
"detection": { "is_threat": true, "confidence": 85.5, "label": "phishing" },
"redteam_analysis": { "attack_goal": "Credential theft", "severity": 8 }
}
}POST /recovery/track
{
"session_id": "recovery_session_id",
"step_number": 1,
"status": "completed"
}POST /recovery/report
{
"session_id": "recovery_session_id",
"recovery_plan": { ... },
"completed_steps": [1, 2, 3]
}GET /recovery/guidance/phishingGET /history?scan_type=text&limit=50&threat_only=true
GET /stats
GET /healthHuggingFaceH4/zephyr-7b-beta
- Analyzes attacker intent, psychology, exploitation chains
- ~2-3s inference time
- Instruction-tuned for complex reasoning
sentence-transformers/all-MiniLM-L6-v2
- 384-dimensional semantic embeddings
- 15,000 sentences/sec on CPU
- 80MB model size
mrm8488/bert-tiny-finetuned-sms-spam-detection
- Fast spam/scam classification
- Production-ready accuracy
prithivMLmods/DeepFake-Detection
- Deepfake and AI-generated content detection
- High accuracy on synthetic media
{
"scan_id": "a3f8d92e7c1b4f6a",
"timestamp": "2026-01-22T10:30:00Z",
"scan_type": "text",
"detection": {
"is_threat": true,
"confidence": 87.5,
"label": "phishing",
"source": "huggingface"
},
"redteam_analysis": {
"attack_goal": "Credential theft via fake verification",
"victim_profile": "General public with banking accounts",
"psychological_tactics": ["urgency", "authority", "fear"],
"exploitation_chain": "Fake alert → User panic → Credential submission",
"next_step": "Harvest credentials from form",
"severity": 8,
"confidence_score": 87.5
},
"cyber_dna": {
"dna_hash": "a3f8d92e7c1b4f6a",
"scores": {
"linguistic_manipulation": 85.2,
"urgency_pressure": 92.0,
"brand_impersonation": 60.0,
"obfuscation": 45.0,
"visual_deception": 0.0,
"intent_severity": 88.5
},
"overall_threat_score": 78.4
},
"similar_threats": [
{
"dna_hash": "b4e9c03d8a2f5e7b",
"similarity": {
"combined_similarity": 85.3,
"same_actor_probability": 80.0
}
}
],
"recommendation": "⚠️ HIGH RISK DETECTED. Do NOT click links..."
}Analyzes threats from an attacker's perspective:
- Attack Goal: What the attacker wants to achieve
- Victim Profile: Who is being targeted
- Psychological Tactics: Manipulation techniques used
- Exploitation Chain: Step-by-step attack sequence
- Next Step: Predicted attacker actions
Creates unique "DNA" for each threat:
- 6 Feature Scores: Linguistic, urgency, brand impersonation, obfuscation, visual, intent
- 384-dim Embedding: Semantic similarity vector
- DNA Hash: Unique fingerprint identifier
- Similarity Matching: Find related threats (cosine similarity)
- Same-Actor Probability: Likelihood threats share same source
AI-powered recovery guidance for cyber threat victims:
- Personalized Recovery Plans: Tailored to specific threat type (phishing, scam, malware, identity theft, financial fraud)
- Step-by-Step Guidance: Clear, actionable recovery steps with priority levels
- Progress Tracking: Mark steps as completed, in-progress, or skipped
- AI-Powered Advice: Context-aware recommendations using HuggingFace models
- Formal Reports: Generate reports for law enforcement and financial institutions
- Educational Resources: Prevention tips and emergency contacts
- Urgency Prioritization: Critical, high, medium, low based on threat severity
- Seamless Integration: Direct access from threat detection reports
See FRAUD_RECOVERY_ASSISTANT.md for complete documentation.
Every scan is logged to backend/logs/:
scans.jsonl- Complete scan recordscyber_dna.jsonl- DNA fingerprints for matchingredteam_analysis.jsonl- Attack analysis reportsdaily_stats.json- Aggregated metrics
| Operation | Latency |
|---|---|
| Text scan | <2s |
| Text + Red-Team + DNA | <5s |
| URL scan | <2s |
| Image scan | <4s |
| Similarity search | <1s |
Optimizations:
- ✅ Async API calls (aiohttp)
- ✅ Response caching (300s TTL)
- ✅ Batch processing support
- ✅ Lightweight models
- ✅ In-memory embedding cache
CyberSentryAI/
├── backend/
│ ├── main.py # FastAPI unified API ⭐
│ ├── redteam_engine.py # Red-Team AI ⭐
│ ├── cyber_dna_engine.py # Cyber DNA ⭐
│ ├── scan_logger.py # Logging system ⭐
│ ├── performance_optimizations.py # Async & caching ⭐
│ ├── requirements.txt # Dependencies
│ ├── .env.example # Config template
│ ├── models/ # ML models
│ ├── logs/ # Scan logs (auto-created)
│ └── exports/ # Dataset exports
├── datasets/ # Training data
├── IMPLEMENTATION.md # Full documentation ⭐
└── README.md # This file
# Test text scan
curl -X POST http://localhost:8000/scan/text \
-H "Content-Type: application/json" \
-d '{"text": "URGENT! Your account will be suspended in 24 hours!"}'
# Test URL scan
curl -X POST http://localhost:8000/scan/url \
-H "Content-Type: application/json" \
-d '{"url": "http://paypa1-verify.com/login"}'
# Check stats
curl http://localhost:8000/statsimport requests
response = requests.post(
"http://localhost:8000/scan/text",
json={"text": "Congratulations! You won $1,000,000!"}
)
result = response.json()
print(f"Threat: {result['detection']['is_threat']}")
print(f"Attack Goal: {result['redteam_analysis']['attack_goal']}").env Variables:
# Required
HF_API_TOKEN=your_token
# Optional (defaults shown)
HF_TEXT_MODEL=mrm8488/bert-tiny-finetuned-sms-spam-detection
HF_REDTEAM_MODEL=HuggingFaceH4/zephyr-7b-beta
HF_EMBEDDING_MODEL=sentence-transformers/all-MiniLM-L6-v2
HF_TIMEOUT=15
# Server
API_HOST=0.0.0.0
API_PORT=8000- Full Docs: IMPLEMENTATION.md
- API Docs: http://localhost:8000/docs (when running)
- Architecture: ARCHITECTURE.md
Solution: Wait 20s and retry. HuggingFace models warm up on first request.
Solution: Check HF_API_TOKEN in .env file.
Solution: pip install -r requirements.txt
Solutions:
- Check HuggingFace API status
- Reduce
HF_TIMEOUTin.env - Temporarily disable Red-Team:
"enable_redteam": false
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]docker build -t cybersentryai .
docker run -p 8000:8000 --env-file .env cybersentryai- Set strong
ADMIN_PASSWORD - Add HTTPS/TLS
- Implement rate limiting
- Set up monitoring
- Configure log rotation
- Add authentication (JWT/API keys)
- Total scans per day
- Threat detection rate
- Average response time
- API error rate
- Cache hit rate
backend/logs/scans.jsonl- All scansbackend/logs/cyber_dna.jsonl- DNA fingerprintsbackend/logs/redteam_analysis.jsonl- Attack analysisbackend/logs/daily_stats.json- Daily metrics
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
MIT License - See LICENSE file
- Hugging Face: https://huggingface.co/
- FastAPI: https://fastapi.tiangolo.com/
- Documentation: IMPLEMENTATION.md
| Feature | v1.0 | v2.0 |
|---|---|---|
| API Framework | Flask (separate apps) | FastAPI (unified) |
| AI Provider | Mixed (Gemini + HF) | 100% Hugging Face |
| Red-Team Analysis | ❌ None | ✅ Full attacker reasoning |
| Cyber DNA | ❌ None | ✅ Fingerprinting + similarity |
| Logging | Basic feedback | Complete audit trail |
| Performance | Sync only | Async + caching |
| Documentation | Minimal | Comprehensive |
Version: 2.0.0
Status: Production Ready ✅
Last Updated: January 22, 2026
✅ 4 New Production Files:
redteam_engine.py- Attacker AI reasoningcyber_dna_engine.py- Threat fingerprintingscan_logger.py- Unified loggingmain.py- FastAPI unified API
✅ Performance Module:
performance_optimizations.py- Async + caching
✅ Complete Documentation:
IMPLEMENTATION.md- Full technical guideREADME.md- This quick start.env.example- Configuration template
✅ Zero Gemini Dependencies ✅ All Logs Saved ✅ Real Working Code ✅ Production Ready
Start scanning threats in 3 minutes! 🚀