AI-Powered KQL Query Generator for Azure Sentinel & Defender
Generateur de requetes KQL avec IA pour Azure Sentinel & Defender
+---------------------------+
| Natural Language |
| Description / MITRE ID |
+------------+--------------+
|
v
+------------+--------------+
| KQL Generator |
| - LLM (OpenAI GPT-4) |
| - Keyword matching |
| - MITRE ATT&CK mapping |
| - 15+ technique templates |
+------------+--------------+
|
v
+------------+--------------+ +-------------------+
| KQL Query Library | | KQL Optimizer |
| - 30+ pre-built queries | | - Anti-patterns |
| - 7 categories | | - Performance tips |
| - Search / Filter / Export | | - Cost estimation |
+------------+--------------+ +--------+----------+
| |
+---------------+--------------+
|
v
+---------------+--------------+
| FastAPI REST API |
| POST /generate |
| POST /optimize |
| GET /library |
| GET /search |
+------------------------------+
KQLHunter generates KQL (Kusto Query Language) hunting queries for Azure Sentinel and Microsoft Defender from:
- Natural language descriptions - "Detect brute force attacks" generates a complete KQL query
- MITRE ATT&CK technique IDs - T1110, T1003, T1059.001, etc.
- Structured components - Table, columns, conditions, joins
- Pre-built library - 30+ production-ready queries across 7 categories
- 15+ MITRE ATT&CK techniques mapped to KQL queries
- 30+ pre-built queries organized by category
- Query optimizer with anti-pattern detection and performance scoring
- FastAPI REST API for integration with SOAR platforms
- CLI for quick generation and library browsing
- LLM-powered (OpenAI) for complex natural language queries
git clone https://github.com/ayinedjimi/KQLHunter.git
cd KQLHunter
pip install -e ".[dev]"
# Optional: Set OpenAI API key for AI features
export OPENAI_API_KEY="sk-..."# Generate from description
kqlhunter generate -d "Detect brute force attacks"
# Generate from MITRE technique
kqlhunter generate -m T1110 --timeframe 24h --threshold 20
# Optimize a query
kqlhunter optimize -q "SigninLogs | where ResultType != '0'" --show-optimized
# Browse library
kqlhunter library -l # List categories
kqlhunter library -c identity_attacks # Show category
kqlhunter library -i IDT-001 # Show specific query
kqlhunter library -s "powershell" # Search
# Export
kqlhunter export -c identity_attacks -o identity.kql
# Start API server
kqlhunter serve --port 8000# Generate query
curl -X POST http://localhost:8000/generate \
-H "Content-Type: application/json" \
-d '{"description": "Detect credential dumping"}'
# Generate from MITRE
curl -X POST http://localhost:8000/generate/mitre \
-H "Content-Type: application/json" \
-d '{"technique_id": "T1003", "timeframe": "24h"}'
# Optimize query
curl -X POST http://localhost:8000/optimize \
-H "Content-Type: application/json" \
-d '{"query": "SigninLogs | where ResultType != 0"}'
# Search library
curl "http://localhost:8000/search?keyword=powershell&severity=high"| Category | Queries | Description |
|---|---|---|
| identity_attacks | 7 | Brute force, spraying, MFA bypass, impossible travel |
| malware_execution | 4 | PowerShell, LOLBins, credential dumping, ransomware |
| lateral_movement | 3 | RDP, PsExec, WMI remote execution |
| persistence | 3 | Scheduled tasks, registry run keys, services |
| data_exfiltration | 3 | Large uploads, cloud storage, DNS exfiltration |
| defense_evasion | 2 | Security tool tampering, log clearing |
| office365 | 2 | Mail forwarding, mass file download |
| ID | Technique | KQL Table |
|---|---|---|
| T1110 | Brute Force | SigninLogs |
| T1110.003 | Password Spraying | SigninLogs |
| T1078 | Valid Accounts | SigninLogs |
| T1059.001 | PowerShell | DeviceProcessEvents |
| T1003 | Credential Dumping | DeviceProcessEvents |
| T1071 | Application Layer Protocol | DeviceNetworkEvents |
| T1486 | Ransomware | DeviceFileEvents |
| T1048 | Data Exfiltration | DeviceNetworkEvents |
| T1053 | Scheduled Tasks | DeviceProcessEvents |
| T1547.001 | Registry Run Keys | DeviceRegistryEvents |
| T1136 | Create Account | AuditLogs |
| T1556 | Modify Authentication | AuditLogs |
| T1534 | Internal Spearphishing | EmailEvents |
| T1550.001 | Access Token | SigninLogs |
| T1562.001 | Disable Security Tools | DeviceProcessEvents |
KQLHunter genere des requetes KQL de chasse aux menaces pour Azure Sentinel et Microsoft Defender a partir de descriptions en langage naturel, de techniques MITRE ATT&CK, ou de composants structures.
- 15+ techniques MITRE ATT&CK mappees vers KQL
- 30+ requetes pre-construites dans 7 categories
- Optimiseur de requetes avec detection d'anti-patterns
- API REST FastAPI pour integration SOAR
- CLI pour generation et consultation rapide
pytest tests/ -v --cov=kqlhunter- ADBloodHound-AI - AD attack path analysis
- YaraGen-AI - AI-powered YARA rule generator
- KVortex - VRAM to RAM Offloader
Ayi NEDJIMI - Cybersecurity & AI Consultant
- Website: ayinedjimi-consultants.fr
- HuggingFace: AYI-NEDJIMI
- GitHub: ayinedjimi
MIT License - see LICENSE