KQLHunting query: tune before alertingAI coding agents on endpoints
Command spawned by an AI coding agent references credential files
Agents that obey injected instructions read secrets through ordinary shell commands: the SANDWORM_MODE rogue MCP server told agents to collect ~/.ssh keys, ~/.aws/credentials, ~/.npmrc and .env files, and SpecterOps showed a Claude Code allowlist bypass that read ~/.aws/credentials with sed. This hunt looks for processes whose parent or grandparent is an AI agent and whose command line names common credential stores.
- Log source
- Microsoft Defender for Endpoint: DeviceProcessEvents
- Techniques
- AML.T0055 Unsecured Credentials · AML.T0098 AI Agent Tool Credential Harvesting · ASI02 Tool Misuse and Exploitation · ASI03 Identity and Privilege Abuse
- MITRE ATT&CK
- T1552.001Credentials In FilesT1552.004Private Keys
- Reviewed
- 2026-11-10
Query
let ai_agents = dynamic(["claude", "claude.exe", "codex", "codex.exe", "cursor-agent", "Cursor", "Cursor.exe", "Cursor Helper (Plugin)", "gemini", "copilot", "Windsurf", "Windsurf.exe", "q"]);
let ai_package_regex = @"(@anthropic-ai[\\/]claude-code|@google[\\/]gemini-cli|@openai[\\/]codex)";
DeviceProcessEvents
| where Timestamp > ago(7d)
| where InitiatingProcessFileName in~ (ai_agents) or InitiatingProcessParentFileName in~ (ai_agents)
or InitiatingProcessCommandLine matches regex ai_package_regex
or InitiatingProcessFolderPath contains "/.local/share/claude/versions/"
| where ProcessCommandLine matches regex @"(\.aws[\\/]credentials|\.ssh[\\/]id_|\.npmrc|\.git-credentials|\.netrc|\.docker[\\/]config\.json|\.kube[\\/]config|gh\s+auth\s+token|(^|[\s/\\=])\.env(\s|$|\.))"
| project Timestamp, DeviceName, AccountName, InitiatingProcessParentFileName, InitiatingProcessFileName,
FileName, ProcessCommandLine
| order by Timestamp desc Expected false positives
- Developers asking an agent to debug their own cloud, npm or Docker configuration
- Agents loading .env files for local test runs
Sources
- Socket: SANDWORM_MODE npm worm poisons AI toolchains (Feb 2026)
- SpecterOps: An evening with Claude Code (CVE-2025-64755)
- Defender XDR: DeviceProcessEvents table
- Elastic rule: GenAI process accessing sensitive files
Reviewed against vendor documentation, not tested in your environment. Defensive use only.