Contagious Interview: Tracking the VS Code Tasks Infection Vector
Detection stack
- AIDR
- Alert
- ETL
- Query
Summary
The report details a North Korea–attributed campaign that weaponizes Visual Studio Code task definitions (tasks.json) to gain initial code execution on developer endpoints. Malicious task entries run commands that fetch additional payloads from hosting platforms such as Vercel, Render, and similar services, or they pull in malicious NPM dependencies. This execution chain ultimately enables deployment of backdoors including BeaverTail and InvisibleFerret.
Investigation
Researchers leveraged GitHub code search to identify repositories containing tasks.json files with embedded curl or wget execution. They analyzed payload-hosting domains, documented obfuscation methods that hide scripts inside image and font files, and uncovered a malicious NPM package named jsonwebauth. The study also correlated commit-author email addresses and expanded infrastructure mapping beyond Vercel-based delivery.
Mitigation
Disable automatic task execution in VS Code, and review tasks.json contents before trusting or opening a workspace. Use the in-browser github.dev environment to inspect repositories without running local tasks. Monitor for suspicious VS Code child processes, unexpected network requests to known payload domains, and Node.js execution paths that attempt to run non-JavaScript files.
Response
If identified, isolate the endpoint, terminate suspicious VS Code–spawned processes, and block outbound traffic to the associated malicious domains. Collect and analyze downloaded payloads, and perform forensic validation for persistence and backdoor activity linked to BeaverTail and InvisibleFerret.
graph TB %% Class Definitions classDef technique fill:#ffcc99 classDef action fill:#c2f0c2 %% Nodes – Techniques node_initial_access[“<b>Technique</b> – <b>T1195.001 Supply Chain Compromise</b><br><b>Description</b>: Adversaries compromise the software supply chain to deliver the malicious NPM package \”jsonwebauth\”.”] class node_initial_access technique node_ide_abuse[“<b>Technique</b> – <b>T1176.002 IDE Extension Abuse: VS Code Tasks</b><br><b>Description</b>: A malicious VS Code extension leverages tasks.json to run actions when a folder is opened.”] class node_ide_abuse technique node_execution[“<b>Technique</b> – <b>T1202 Indirect Command Execution</b><br><b>Description</b>: Commands are executed indirectly via VS Code tasks triggered on the folderOpen event.”] class node_execution technique node_command_exec[“<b>Technique</b> – <b>T1059.004 Unix Shell / T1059.003 Windows Command Shell</b><br><b>Description</b>: Uses curl or wget pipelines in Unix or Windows shells to retrieve additional code.”] class node_command_exec technique node_obfuscation[“<b>Technique</b> – <b>T1027.009 Obfuscated Payloads Embedded in Fonts/Images</b><br><b>Description</b>: Malicious payloads are hidden inside font or image files to evade detection.”] class node_obfuscation technique node_masquerading[“<b>Technique</b> – <b>T1036.008 Masquerading File Types</b><br><b>Description</b>: Files are disguised as legitimate types to blend in with normal content.”] class node_masquerading technique %% Nodes – Actions node_download[“<b>Action</b> – Download Payloads<br><b>Details</b>: Retrieves malicious payloads from Vercel or JSON storage services.”] class node_download action node_persistence[“<b>Action</b> – Further Execution / Persistence<br><b>Details</b>: Executes and persists the malicious code on the compromised system.”] class node_persistence action %% Connections node_initial_access –>|leads_to| node_ide_abuse node_ide_abuse –>|enables| node_execution node_execution –>|executes| node_command_exec node_command_exec –>|downloads| node_download node_download –>|contains| node_obfuscation node_obfuscation –>|uses| node_masquerading node_masquerading –>|leads_to| node_persistence
Attack Flow
Simulation Execution
Prerequisite: The Telemetry & Baseline Pre‑flight Check must have passed.
Rationale: This section details the precise execution of the adversary technique (TTP) designed to trigger the detection rule. The commands and narrative MUST directly reflect the TTPs identified and aim to generate the exact telemetry expected by the detection logic. Abstract or unrelated examples will lead to misdiagnosis.
-
Attack Narrative & Commands:
An attacker who has already compromised the user’s workstation leverages VS Code’s tasks.json feature to run a malicious Windows executable (payload.exe) via Node.js. The attacker crafts a task that invokescmd.exe /c node payload.exe, thereby satisfying the rule’s three‑keyword requirement (tasks.json,node,cmd). After saving the malicious task definition under the user’s.vscodefolder, the attacker executes the task through VS Code’s command palette, causingcmd.exeandnode.exeprocesses to appear in the Windows security log with a command line that contains the three required strings. -
Regression Test Script: (PowerShell – self‑contained)
# --------------------------------------------------------- # Malicious VS Code Task Simulation – Triggers Sigma Rule # --------------------------------------------------------- # 1. Prepare a dummy malicious payload (non‑JS executable) $payloadPath = "$env:USERPROFILEDesktoppayload.exe" # Create a tiny executable using PowerShell’s Add-Type (for demo) Add-Type -TypeDefinition @" using System; public class Dummy { public static void Main() { System.Console.WriteLine("Payload executed"); } } "@ -Language CSharp [Dummy]::Main() | Out-File -FilePath $payloadPath -Encoding ascii # 2. Build the VS Code tasks.json with malicious command $vscodeDir = "$env:USERPROFILE.vscode" if (-not (Test-Path $vscodeDir)) { New-Item -ItemType Directory -Path $vscodeDir | Out-Null } $tasksJson = @{ version = "2.0.0" tasks = @( @{ label = "Run Malicious Payload" type = "shell" command = "cmd.exe" args = @("/c", "node", "`"$payloadPath`"") } ) } | ConvertTo-Json -Depth 5 $tasksFile = Join-Path $vscodeDir "tasks.json" $tasksJson | Set-Content -Path $tasksFile -Encoding UTF8 # 3. Trigger the task via VS Code CLI # (Assumes `code` is in PATH) Write-Host "Executing malicious VS Code task..." code --folder-uri "$env:USERPROFILE" --command "workbench.action.tasks.runTask" --args "Run Malicious Payload" # 4. Wait a few seconds for the processes to appear in the log Start-Sleep -Seconds 5 # 5. OPTIONAL: Query local event log to verify (for demonstration) Get-WinEvent -FilterHashtable @{ LogName='Security'; Id=4688; Data='node.exe'; } | Where-Object {$_.Message -match 'tasks.json'} | ft TimeCreated, Message -AutoSize -
Cleanup Commands: (PowerShell)
# Remove malicious payload and VS Code task definition Remove-Item -Path "$env:USERPROFILEDesktoppayload.exe" -Force -ErrorAction SilentlyContinue Remove-Item -Path "$env:USERPROFILE.vscodetasks.json" -Force -ErrorAction SilentlyContinue # Optional: restart VS Code to clear any cached tasks Get-Process -Name "Code" -ErrorAction SilentlyContinue | Stop-Process -Force