Suspicious Command Execution from Visual Studio Code
Description
Detects Visual Studio Code ("Code.exe" on Windows or "Code Helper" on macOS) spawning a shell or downloader whose command line contains an encoded command, a download cradle, or a reverse-shell pattern. Malicious IDE extensions use the editor process to run these commands after install.
Query · esql
FROM logs-endpoint.events.process-* METADATA _id, _version, _index
| WHERE KQL("""event.category:process and event.type:start""")
AND process.parent.name IN ("Code Helper (Plugin)", "Code Helper", "Code.exe", "code")
AND process.name IN (
"cmd.exe", "powershell.exe", "sh", "bash", "zsh",
"dash", "nohup", "curl.exe", "curl", "wget",
"wget.exe", "pwsh.exe"
)
AND TO_LOWER(process.command_line) RLIKE """.*(-ec |-enc|-encodedcommand|-nop |-w hidden|https|/dev/tcp|echo|irm |iwr |base64|nohup|http:|iex |invoke-expression|downloadstring|downloadfile|frombase64string|chmod \+|nc -e|ncat|certutil|bitsadmin|invoke-restmethod|curl.*\|.*sh|wget.*\|.*sh).*"""
AND NOT TO_LOWER(process.command_line) RLIKE """.*(docker.internal|localhost|127.0.0.1|aka.ms/vscode-powershell).*"""
| KEEP
_id,
_version,
_index,
data_stream.namespace,
@timestamp,
host.name,
host.id,
agent.id,
host.os.type,
user.name,
user.domain,
process.name,
process.parent.name,
process.parent.executable,
process.command_line,
process.executable,
process.parent.command_line,
process.parent.args
Investigation fields
Pivot points the source recommends for triage.
host.os.typeprocess.parent.nameprocess.parent.executableprocess.parent.command_lineprocess.parent.argsprocess.command_lineprocess.executable
Implementation guide
This rule is designed for data generated by Elastic Defend, which provides native endpoint detection and response, along with event enrichments designed to work with our detection rules.
Setup instructions: https://ela.st/install-elastic-defend
Analyst notes
Investigating Suspicious Command Execution from Visual Studio Code
Code.exe or Code Helper started cmd, PowerShell, a Unix shell, curl, or wget, and the command line matches
an encoded-command, download, or remote-shell pattern. That is common when a malicious VS Code extension, task, or
workspace script runs through the editor.
Possible investigation steps
- Review
process.command_linefor the URL, encoded payload, or shell pipe (curl | sh,wget | sh,Invoke-Expression). - Review
process.parent.command_lineandprocess.parent.argsforextensionHostor a path under.vscode/extensionsor.vscode/tasks.json. - Identify the extension id from that parent path and compare it with the installed extension.
- On the same host and user, look for the downloaded file, follow-on processes, and outbound connections.
False positive analysis
- Developer tasks and integrated terminals often run
curl,wget,echo, orhttpsURLs.echoandhttpsin the pattern match many legitimate commands. Confirm the parent is an extension host or an unexpected workspace task before excluding. - The rule already excludes command lines containing
docker.internal,localhost,127.0.0.1, oraka.ms/vscode-powershell. - Scope exceptions to a known command line, extension path, host, or user. Do not broadly exclude
Code.exeorCode Helper.
Response and remediation
- If the command is unapproved, stop the child process, uninstall the extension, and remove any dropped file.
- Quarantine the payload, collect its hash, and hunt the command line on other hosts.
- Rotate tokens or credentials the command could have read from the user profile or workspace.