KQLHunting query: tune before alertingShadow AI and AI-powered attackers
Endpoint process talking to an AI API that is not on the approved list
Shadow AI on endpoints shows up as scripts, CLIs, IDE extensions and unknown binaries calling model APIs directly with personal keys, bypassing an approved gateway. GTIG also reports malware that calls Gemini and Hugging Face APIs at runtime. This hunt summarises processes that connect to major AI API hosts, Azure OpenAI (*.openai.azure.com) and Bedrock runtime endpoints, excluding an approved-process list you maintain.
- Log source
- Microsoft Defender for Endpoint: DeviceNetworkEvents
- Techniques
- LLM02 Sensitive Information Disclosure · AML.T0096 AI Service API
- MITRE ATT&CK
- T1567Exfiltration Over Web Service
- Reviewed
- 2026-11-10
Query
let ai_api_hosts = dynamic(["api.openai.com", "api.anthropic.com", "generativelanguage.googleapis.com", "api.deepseek.com",
"openrouter.ai", "router.huggingface.co"]);
let approved_processes = dynamic(["chrome.exe", "msedge.exe", "firefox.exe", "Google Chrome Helper", "Safari",
"claude", "Claude", "Claude.exe", "Cursor", "Cursor.exe", "Code", "Code.exe"]);
DeviceNetworkEvents
| where Timestamp > ago(7d)
| where ActionType == "ConnectionSuccess" and isnotempty(RemoteUrl)
| extend RemoteHost = tolower(tostring(parse_url(iff(RemoteUrl contains "://", RemoteUrl, strcat("https://", RemoteUrl))).Host))
| where RemoteHost in (ai_api_hosts) or RemoteHost endswith ".openai.azure.com"
or RemoteHost matches regex @"^bedrock-runtime\.[a-z0-9-]+\.amazonaws\.com$"
| where InitiatingProcessFileName !in~ (approved_processes)
| summarize Connections = count(), Devices = dcount(DeviceName), Hosts = make_set(RemoteHost),
FirstSeen = min(Timestamp), SampleCommandLine = take_any(InitiatingProcessCommandLine)
by InitiatingProcessFileName, InitiatingProcessFolderPath, InitiatingProcessVersionInfoCompanyName
| order by Devices asc, Connections desc Expected false positives
- Approved internal tools and SDK-based apps not yet in the allowlist
- Developer workstations testing integrations with company keys
Sources
- OpenAI API reference (api.openai.com/v1)
- Claude API overview (api.anthropic.com)
- Gemini API reference (generativelanguage.googleapis.com)
- DeepSeek API docs (api.deepseek.com)
- OpenRouter quickstart (openrouter.ai/api/v1)
- Hugging Face Inference Providers (router.huggingface.co)
- Azure OpenAI REST reference (endpoint format and api-key header)
- Google GTIG: AI threat tracker — advances in threat actor usage of AI tools (Nov 2025)
- Defender XDR: DeviceNetworkEvents table
- Elastic rule: Connection to common LLM endpoints by scripting utilities
Reviewed against vendor documentation, not tested in your environment. Defensive use only.