npm Supply Chain Attack Forensics: Two-Stage C2 Decoded
How a stolen npm credential weaponized Axios into a two-stage C2 trojan. Forensic analysis of a real supply chain attack affecting millions.
A Single Compromised Credential, Millions of Downstream Apps
A maintainer's stolen credentials. One phantom dependency. Forty minutes of access. That is all it took to turn a trusted npm package into a cross-platform remote access trojan delivery system.
The npm ecosystem hosts over 2.5 million packages with billions of weekly downloads. When an attacker compromises a package near the top of that dependency graph, the blast radius is not theoretical — it is immediate. As Picus Security put it in their analysis, "a single compromised credential can weaponize an entire dependency graph affecting millions of downstream applications, with no modification to the target library's source code required."
This article dissects a real-world npm supply chain attack — the Axios compromise — step by step. Not from a purely academic angle, but from the perspective of teams that ship production code and need to understand exactly what happened, how to detect it, and what to change in their workflows.
How the Attack Was Staged: The 18-Hour Setup
Every sophisticated attack has a preparation phase. This one started nearly 18 hours before the malicious release, when the attacker published a benign package called plain-crypto-js to the npm registry. According to Loginsoft's technical analysis, this package existed solely to establish a publishing history and avoid triggering automated checks that flag brand-new packages with suspicious behavior.
Put simply: the attacker built a clean reputation first, then weaponized it.
Once the trust-building phase was complete, the attacker used compromised maintainer credentials to publish malicious versions of Axios. Both active and legacy release branches were compromised within approximately 40 minutes. The speed matters — it suggests automation, not manual tampering.
The Phantom Dependency Trick
Here is where the technical elegance (and danger) of this attack becomes clear. The malicious Axios version added plain-crypto-js@^4.2.1 as a dependency. But according to Trend Micro's forensic investigation, a grep across all 86 files in the Axios package confirmed zero imports or references to this dependency. It was never used in the source code.
The dependency existed for one reason only: to trigger npm's automatic dependency resolution and execute the postinstall hook inside plain-crypto-js. npm lifecycle hooks — preinstall, install, postinstall — run with the privileges of the installing user. As Splunk's detection guide explains, these hooks "provide execution points where malicious code can run" and are particularly dangerous in build systems and CI/CD pipelines that "often run with elevated credentials and access to production secrets."
So the Axios source code itself looked completely clean. The attack lived entirely inside a dependency that no code ever referenced.
Stage One: The Dropper and Platform Detection
Once the postinstall hook fired, it executed node setup.js — the first-stage dropper. This script performed platform detection and deployed environment-specific payloads for Windows, macOS, and Linux.
According to Huntress's supply chain analysis, the Windows attack chain followed this sequence:
node setup.js → cmd.exe → cscript.exe → cmd.exe → curl (POST to C2)
The C2 server at sfrclak[.]com (IP: 142.11.206.73, port 8000) received POST requests with platform-specific identifiers. Picus Security documented the routing logic:
/product0— macOS payload (delivered via AppleScript dropper)/product1— Windows payload/product2— Linux payload
This single-endpoint, multi-platform approach is efficient from an attacker's perspective. One C2 server, three operating systems covered. The server inspects the POST body identifier and returns the appropriate second-stage payload.
The Windows EDR Bypass
One detail stands out in the Windows attack chain. The attacker renamed powershell.exe to wt.exe — the filename normally associated with Windows Terminal. As Chad Hudson identified during the incident response, "wt.exe is just Windows Terminal — being used as a PowerShell bypass."
This is a deliberate EDR (Endpoint Detection and Response) evasion technique. Many EDR solutions monitor for powershell.exe process creation with suspicious arguments. By renaming the binary, the attacker sidesteps signature-based detections while maintaining full PowerShell functionality.
Honest take: this technique is not novel, but it remains effective against a surprising number of security tools that rely on process name matching rather than deeper behavioral analysis.
Stage Two: The Full-Featured RAT
The second-stage payload was not a simple data exfiltrator. According to Huntress, it was a full-featured PowerShell RAT (Remote Access Trojan) that established persistence through a straightforward but effective mechanism:
The RAT created %PROGRAMDATA%\system.bat containing a download cradle that re-fetches the RAT from the C2 server on every login. This means even if the initial payload is detected and removed, the persistence mechanism re-downloads it the next time the user logs in.
CI/CD Environment Awareness
The malware was not blind to its execution context. Cymulate's research documented how similar npm supply chain attacks detect CI/CD environments by checking for variables like GITHUB_ACTIONS, BUILDKITE, and CIRCLE_SHA1. The malware differentiates between a developer's workstation and a CI/CD runner, then adjusts its behavior accordingly.
In CI/CD environments, the malware uses synchronous execution — keeping the runner process alive just long enough to harvest secrets before the build fails or times out. On developer workstations, it can afford persistence and stealth.
Real numbers: CI/CD pipelines typically have access to npm tokens, AWS credentials, SSH keys, database connection strings, and deployment secrets. A single compromised build can expose every secret in the pipeline's environment.
Anti-Forensics: Cleaning Up the Evidence
This is where the attack moves from clever to genuinely concerning for incident response teams.
After deploying the RAT payload, the dropper executed three cleanup operations to erase evidence of the infection chain, as documented by both Picus Security and Trend Micro:
t.unlink(__filename)— deletessetup.js(the dropper)t.unlink("package.json")— deletes the malicious manifestt.rename("package.md", "package.json")— swaps in a clean stub
Every callback in this anti-forensics routine was (x => {}) — silently swallowing errors. The entire _entry function was wrapped in try/catch {} for the same reason. If any cleanup step failed, it failed silently and moved on to the next.
The result: a post-incident inspection of node_modules/plain-crypto-js/ would show "a clean, innocuous-looking package with no trace of the dropper mechanism." The malicious setup.js is gone. The manifest points to nothing suspicious. The only evidence lives in memory, network logs, or on the C2 server.
Obfuscation Layers
The attack also employed significant code obfuscation. As multiple sources noted, critical strings, URLs, and commands were stored in encoded arrays and decoded only at runtime. The only unobfuscated call in the entire dropper was _entry("6202033") — the initial execution trigger.
The constant 6202033 is worth noting. Forensic analysts who successfully decoded the position-dependent XOR step still faced an additional XOR operation using this constant, which served as a secondary layer preventing straightforward static analysis.
Forensic Indicators: How to Tell Clean from Compromised
Trend Micro's investigation surfaced a critical forensic signal for distinguishing legitimate from malicious package versions. The legitimate [email protected] had a trustedPublisher field with an oidcConfigId in the npm registry metadata. The malicious [email protected] had "name": "jasonsaayman" with "email": "[email protected]" and no trustedPublisher field.
This is a concrete, automatable check. Any package version published without a trustedPublisher when previous versions had one should trigger an alert.
YARA Detection Rules
Loginsoft published YARA detection rules for this specific campaign, including signature strings:
$c2 = "sfrclak"— the C2 domain$pkg = "plain-crypto-js"— the malicious dependency$key = "OrDeR_7077"— an internal key used by the payload
These rules can be deployed in file scanning pipelines and endpoint detection systems to catch artifacts from this specific campaign.
Behavioral Indicators
Beyond signatures, the behavioral patterns are what matter for detecting variants:
- Phantom dependencies: packages listed in
package.jsonbut never imported in source code - Postinstall hooks that execute standalone scripts: especially those running
nodeon a separate.jsfile - Platform detection in install scripts: checking
process.platformoros.type()during installation - Network connections during installation: any outbound HTTP request during
npm installis suspicious - Process renaming: executables running under names that do not match their actual binary
Data Exfiltration Techniques
The exfiltration methods used in npm supply chain attacks have evolved beyond simple HTTP POST requests. Cymulate documented a technique where the malware creates a JSON payload of harvested secrets and performs exfiltration using curl -d to the C2 server.
More concerning, some variants use double Base64 encoding and print exfiltrated data to stdout, effectively hiding stolen secrets in CI/CD job logs. This is a significant detection gap because outbound network monitoring would not catch data leaving through the build system's own logging infrastructure.
Another technique documented by Cymulate involves injecting a workflow configured to "extract and execute the body of a GitHub Discussion or Issue as code on the runner." This turns GitHub's own infrastructure into a command-and-control channel — traffic that network security tools are unlikely to flag.
What this means for your project: if your CI/CD logs are accessible to anyone with repository read access, they could become an exfiltration channel. Treat build logs with the same sensitivity as environment variables.
Detection Tools and Scanning Approaches
Several tools address npm supply chain threats at different points in the development lifecycle.
Splunk's Package-Inferno makes "the invisible visible" by revealing malicious behavior such as network connections to suspicious infrastructure, obfuscated code patterns, and credential access attempts. It includes C2 analysis that can surface Discord and Telegram-based exfiltration channels.
NPMScan offers a browser-based analysis tool that uses heuristics for detecting drainers, obfuscation, and exfiltration patterns. It requires no login, no tokens, and no repository access — paste a package.json and get results. The tool is privacy-first and does not store package source code or uploaded tarballs.
Automated scanning tools that integrate into CI/CD pipelines can scan packages during installation, at commit time, and before deployment. As noted by Kusari, these tools "analyze package contents for known malicious patterns, credential theft attempts, and suspicious network communications."
Here is what we recommend for a layered detection strategy:
- Pre-install: lock files with integrity hashes (
package-lock.jsonwithintegrityfields), reviewpostinstallhooks before adding new dependencies - During install: network monitoring for unexpected outbound connections, process monitoring for unusual child processes
- Post-install: file integrity monitoring on
node_modules, periodic comparison against registry metadata fortrustedPublisherchanges - In CI/CD: isolated build environments with no access to production secrets, short-lived credentials, audit logs for all secret access
Incident Response: What to Rotate and When
If a system has been exposed to a compromised npm package, the credential rotation scope is extensive. Huntress explicitly recommends rotating all credentials accessible from affected systems, including:
- npm tokens
- AWS keys
- SSH keys
- CI/CD secrets
.envvalues- Cloud credentials
- OAuth tokens
- API keys
This is not an overreaction. The RAT had full access to the file system and environment variables. Any secret that existed on the machine — in memory, in files, in environment variables — should be considered compromised.
In our experience with 11 projects running on production infrastructure, we track every .env file, every API key, and every deployment credential. When an npm advisory triggers, the response is not "check if we are affected" — it is "assume compromise, rotate, then verify."
Key takeaway for business: the cost of rotating credentials proactively is hours of engineering time. The cost of a breached production environment is measured in weeks, reputation damage, and potential regulatory consequences. The math is straightforward.
Prevention: What Actually Works
No single tool eliminates the risk. As industry practitioners consistently emphasize, npm malware detection relies on a combination of automated tools, policy enforcement, and human oversight. Layered security is the only approach that holds up.
Practical measures that reduce attack surface:
- Pin dependency versions exactly (no
^or~ranges) in production applications. Version ranges are what allowed the malicious Axios release to propagate automatically. - Audit postinstall scripts for every new dependency. The
npm packcommand lets teams inspect what a package actually contains before it runs any hooks. - Monitor for phantom dependencies — packages in the dependency tree that no source file imports. This was the single most obvious indicator in the Axios attack.
- Use
--ignore-scriptsduring CI when possible, then run install scripts explicitly for packages that need them. This breaks the automatic execution chain. - Check
trustedPublishermetadata when evaluating package updates. A version published without it when previous versions had it is a clear red flag. - Review download history and contributor activity. A sudden surge in updates or a long period of inactivity followed by a major release warrants closer inspection.
Frequently Asked Questions
How does the postinstall hook execute malicious code before npm finishes resolving the entire dependency tree?
npm executes lifecycle hooks for each package as it is installed, not after the entire tree is resolved. This means a malicious postinstall script runs with full system privileges the moment its package is extracted, before the parent project's install process completes. The attacker's code has already executed before any downstream integrity check could flag it.
How can you detect C2 communication when all critical strings, URLs, and commands are stored in encoded arrays and only decoded at runtime?
Static analysis alone will not catch runtime-decoded strings. The effective approach combines behavioral monitoring (watching for unexpected network connections during npm install), sandboxed execution (running installs in isolated environments with network logging), and heuristic detection tools like Package-Inferno or NPMScan that flag obfuscation patterns themselves as suspicious signals — regardless of what the obfuscated code actually does.
What detection gaps allow exfiltration via public GitHub repositories to bypass network security filters?
Most corporate firewalls and network security tools whitelist GitHub domains. When attackers use GitHub Discussions, Issues, or repository contents as C2 channels, the traffic appears as normal HTTPS requests to github.com. Similarly, double Base64-encoded secrets printed to stdout in CI/CD logs bypass network monitoring entirely because the data never leaves through a flagged channel — it exits through the build system's own logging infrastructure.
How does the malware use stolen npm tokens to automatically identify and re-infect other packages maintained by the same developer?
Once an npm authentication token is exfiltrated, the attacker can query the npm API to list all packages associated with that account. Packages where the compromised account has publish rights become targets for the same injection technique — adding a phantom dependency with a malicious postinstall hook. This creates a cascading compromise where one stolen token can weaponize dozens of packages across the ecosystem.
This article is based on publicly available sources and may contain inaccuracies.


