KQLHunting query: tune before alertingMCP servers and agent configuration
AI tool MCP or agent configuration written by a process other than the tool
SANDWORM_MODE's McpInject module (February 2026) wrote a rogue MCP server into ~/.claude/settings.json, ~/.cursor/mcp.json, ~/.continue/config.json, Windsurf and Claude Desktop configs so the AI tool would launch it on next start. MCP servers are defined in ~/.claude.json and .mcp.json (Claude Code), ~/.cursor/mcp.json (Cursor), claude_desktop_config.json (Claude Desktop), ~/.gemini/settings.json (Gemini CLI) and ~/.codex/config.toml (Codex). This hunt lists writes to those files by anything other than the owning tools.
- Log source
- Microsoft Defender for Endpoint: DeviceFileEvents
- Techniques
- AML.T0081 Modify AI Agent Configuration · ASI04 Agentic Supply Chain Vulnerabilities · AML.T0110 AI Agent Tool Poisoning · LLM03 Supply Chain
- MITRE ATT&CK
- T1546Event Triggered Execution
- 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)";
DeviceFileEvents
| where Timestamp > ago(14d)
| where ActionType in ("FileCreated", "FileModified", "FileRenamed")
| where FileName in~ ("mcp.json", ".mcp.json", "claude_desktop_config.json", ".claude.json", "mcp_config.json")
or (FileName =~ "settings.json" and (FolderPath contains "/.claude/" or FolderPath contains @"\.claude\"
or FolderPath contains "/.gemini/" or FolderPath contains @"\.gemini\"))
or (FileName =~ "config.json" and (FolderPath contains "/.continue/" or FolderPath contains @"\.continue\"))
or (FileName =~ "config.toml" and (FolderPath contains "/.codex/" or FolderPath contains @"\.codex\"))
| where not(InitiatingProcessFileName in~ (ai_agents)
or InitiatingProcessFileName in~ ("Claude", "Claude.exe", "Code", "Code.exe", "Code Helper (Plugin)")
or InitiatingProcessFolderPath contains "/.local/share/claude/versions/"
or InitiatingProcessCommandLine matches regex ai_package_regex)
| project Timestamp, DeviceName, ActionType, FolderPath, FileName, InitiatingProcessFileName,
InitiatingProcessCommandLine, InitiatingProcessParentFileName, InitiatingProcessAccountName
| order by Timestamp desc Expected false positives
- git clone / checkout of repositories that contain .mcp.json or .claude/settings.json
- Dotfile managers, MDM or configuration management that deploy approved MCP configs
- IDE extensions that register MCP servers during setup
Sources
- Socket: SANDWORM_MODE npm worm poisons AI toolchains (Feb 2026)
- Claude Code docs: MCP (configuration scopes and claude mcp add)
- Cursor docs: MCP configuration locations
- MCP docs: Connect to local MCP servers (claude_desktop_config.json paths)
- Gemini CLI docs: Configuration (--yolo, mcpServers)
- Defender XDR: DeviceFileEvents table
- Elastic rule: Unusual process modifying GenAI configuration file
Reviewed against vendor documentation, not tested in your environment. Defensive use only.