KQLHunting query: tune before alertingAI coding agents on endpoints
Shell startup file modified by a script runtime or by an AI agent's child process
s1ngularity's telemetry.js appended `sudo shutdown -h 0` to ~/.bashrc and ~/.zshrc, and SpecterOps showed an agent-reachable `sed 'w ~/.zshenv'` primitive that plants commands run by every new zsh. Editors and installers rarely write these files; node, python, sed or a process spawned by an AI agent writing them is unusual.
- Log source
- Microsoft Defender for Endpoint: DeviceFileEvents (macOS / Linux)
- Techniques
- AML.T0142 Event Triggered Execution · ASI05 Unexpected Code Execution · LLM03 Supply Chain · AML.T0010 Supply Chain Compromise
- MITRE ATT&CK
- T1546.004Unix Shell Configuration Modification
- 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 startup_files = dynamic([".zshrc", ".zshenv", ".zprofile", ".bashrc", ".bash_profile", ".profile"]);
let script_writers = dynamic(["node", "bun", "deno", "python", "python3", "perl", "ruby", "sed", "tee"]);
DeviceFileEvents
| where Timestamp > ago(14d)
| where ActionType in ("FileCreated", "FileModified", "FileRenamed")
| where FileName in (startup_files)
| where InitiatingProcessFileName in~ (script_writers) or InitiatingProcessParentFileName in~ (ai_agents)
| project Timestamp, DeviceName, FolderPath, ActionType, InitiatingProcessFileName,
InitiatingProcessCommandLine, InitiatingProcessParentFileName, InitiatingProcessAccountName
| order by Timestamp desc Expected false positives
- Version managers and installers (nvm, pyenv, conda, rustup) that add PATH lines via scripts
- Dotfile managers written in Python or Node
Sources
- StepSecurity: Nx build system package compromised with data-stealing malware
- SpecterOps: An evening with Claude Code (CVE-2025-64755)
- Wiz: s1ngularity — Nx supply chain attack (Aug 2025)
- Defender XDR: DeviceFileEvents table
Reviewed against vendor documentation, not tested in your environment. Defensive use only.