# Typosquatting
> Registering malicious packages under names that are near-misses of popular ones (misspellings, swapped/repeated characters, added prefixes/suffixes, lookalike scopes) and waiting for humans or tooling to install the wrong name.
## How it works
Like [[Dependency Confusion]], it exploits registries identifying packages by name only, but it is **opportunistic** rather than organization-targeted: the attacker squats many typo variants of high-download packages and waits. Name sources include common typos, package names popular in other ecosystems, Linux-distro naming variants, and LLM-hallucinated names ([[Slopsquatting]]).
Execution paths:
- **Install-time** — npm `preinstall`/`install`/`postinstall` hooks fire on `npm install`, before the app runs.
- **Import/call-time** — code runs when the module is loaded or a function is called (e.g. `rustdecimal`'s `Decimal::new`), which evades `--ignore-scripts`.
- **Delayed / targeted** — a fully working trojanized fork that only misbehaves in a specific environment.
Sonatype argues "typosquatting" is now too narrow: the broader pattern is **manufactured legitimacy** (brandjacking) — prefix/suffix addition, version mimicry, embedded target terms, altered scopes/namespaces, and names that describe the function of a legit package.
## Techniques / payloads
Common name mutations (TypoGard's detection features):
| Mutation | Example |
|---|---|
| Swapped characters | `reqeusts` → `requests` |
| Repeated characters | `rustdeciimal`, `Newtonsoftt.Json.Net` |
| Separator change | `rustdecimal` vs `rust_decimal` |
| Dropped character | `lodas` → `lodash` |
| Suffix/prefix | `react-router-doms`, `Newtonsoftt.Json.Net` (`.Net` suffix), `opensearch-setup-tool` |
| Keyboard-adjacent typo | layout-based substitutions |
Metadata forgery: the NuGet `Newtonsoftt.Json.Net` nuspec claimed author `James Newton-King`, `projectUrl` `https://www.newtonsoft.com/json`, title `Json.NET`, MIT license, version `11.0.x` (real line is `13.x`) — plausible in a dependency graph.
Payload example (Microsoft, `vpmdhaj` cluster, May 2026, 14 npm packages imitating OpenSearch/Elastic tooling):
- Gen-1: `preinstall.js` POSTs base64 host context to C2 with header `X-Supply: 1`, drops `payload.bin`; `index.js` relaunches it on every `require()` for persistence across CI stages.
- Gen-2: `setup.mjs` downloads the legitimate Bun v1.3.13 runtime from GitHub Releases and runs a ~195 KB Bun-compiled stealer — no install-time C2 round trip.
- Targets: IMDSv2 `169.254.169.254` + ECS `169.254.170.2` creds, STS `GetCallerIdentity`/`AssumeRole`, Secrets Manager `ListSecrets`/`GetSecretValue` across 16+ regions, `VAULT_TOKEN`, npm tokens via `/-/whoami` and `/-/npm/v1/tokens`; sets `CI=false` to fool build-aware code. Stolen npm publish tokens enable a downstream pivot (see [[Malicious Packages]], [[Shai-Hulud Worm]]).
## Notable cases
- **`rustdecimal` (crates.io, 2022)** — mimicked `rust_decimal`; `Decimal::new` executed a malicious binary.
- **`Newtonsoftt.Json.Net` (NuGet, Aug–Oct 2025)** — JFrog: a working Json.NET fork that, after `JsonConvert.DefaultSettings` init and a delay, rigged results on the Digitain betting platform and exfiltrated them with header `X-Seq-ApiKey: theperfectheist2025`. Seven versions; unlisted but still downloadable.
- **`vpmdhaj` npm cluster (May 2026)** — `opensearch-setup`, `opensearch-config-utility`, `elastic-opensearch-helper`, `env-config-manager`, `@vpmdhaj/devops-tools`; cloud/CI credential theft.
- **`reqnest` (PyPI, Nov 2026)** — typosquat of `requests`; on import exfiltrates Telegram files (GHSA malware advisory, campaign `2026-11-reqnest`).
- **~800-package npm RAT campaign** — "AI slop squatted or randomly generated typo-squatting" names; README instructs `require()` (no lifecycle hook) to trigger the WEL1DROPPER downloader pulling payloads from Cloudflare Workers.
- **`@isaacs/cliui` lookalikes** — Snyk found `string-width-cjs`/`strip-ansi-cjs`/`wrap-ansi-cjs`-style squats near legitimate aliased dependencies.
- Since 2022, typosquat campaigns have targeted packages with a combined 1.2B weekly downloads (Trail of Bits, citing Phylum).
## Defenses
- **Detection at add-time** — Levenshtein checks are noisy; TypoGard (npm) uses context-aware metrics + popularity thresholds; its Rust port **Typomania** is deployed in crates.io and has caught malicious crates.
- **Scanners** — GuardDog (`uvx guarddog pypi scan <pkg>`, also npm, Go, crates, RubyGems, GitHub Actions, VS Code extensions) correlates capability + threat indicators via YARA/Semgrep-style rules and metadata heuristics.
- **Minimum package age** — a 48h (or longer) release-age gate blocks same-day squats and fast-moving campaigns.
- **Show metadata at install** — dependents, downloads, age, maintainer history; verify publisher, not download count.
- **Disable install scripts** (`--ignore-scripts`) — necessary but insufficient given import-time payloads.
- Pin exact versions, commit lockfiles with hashes, route installs through a curated proxy registry.
## Related
- [[Software Supply Chain Security]]
- [[Dependency Confusion]] · [[Slopsquatting]] · [[Malicious Packages]]
- [[Shai-Hulud Worm]] · [[Leaked Cloud Credentials]] · [[Cloud Metadata Service Exploitation]]
## Sources
- [[raw/slsa.dev/defender-s-perspective-dep-confusion-and-typosquatting-slsa-4470|Defender's Perspective: Dep Confusion and Typosquatting (SLSA)]]
- [[raw/blog.trailofbits.com/supply-chain-attacks-are-exploiting-our-assumptions-3747|Supply chain attacks are exploiting our assumptions (Trail of Bits)]]
- [[raw/jfrog.com/the-perfect-heist-nuget-typosquat-targets-betting-platform-to-rig-resu-10675|The Perfect Heist: NuGet Typosquat Targets Betting Platform to Rig Results]]
- [[raw/microsoft.com/typosquatted-npm-packages-used-to-steal-cloud-and-ci-cd-secrets-8364|Typosquatted npm packages used to steal cloud and CI/CD secrets]]
- [[raw/thehackernews.com/malicious-sicoob-nuget-steals-banking-credentials-as-npm-packages-targ-8365|Malicious Sicoob NuGet Steals Banking Credentials as npm Packages Target...]]
- [[raw/github.com/malicious-code-in-reqnest-pypi-typosquat-13753|Malicious code in reqnest (PyPI typosquat)]]
- [[raw/thehackernews.com/nearly-800-malicious-npm-packages-deliver-cross-platform-rat-and-infos-11183|Nearly 800 malicious npm packages deliver cross-platform RAT and infostealer]]
- [[raw/snyk.io/the-mysterious-supply-chain-concern-of-string-width-cjs-npm-package-9342|The mysterious supply chain concern of string-width-cjs npm package]]
- [[raw/github.com/guarddog-cli-tool-to-identify-malicious-pypi-and-npm-packages-4339|GuardDog: CLI Tool to Identify Malicious PyPI and npm Packages]]
- [[raw/blogs.jsmon.sh/npm-supply-chain-attacks-explained-dependency-confusion-exploits-and-d-3038|NPM Supply Chain Attacks Explained]]
- [[raw/aikido.dev/the-practical-checklist-for-defending-against-supply-chain-attacks-10487|The practical checklist for defending against supply chain attacks (Aikido)]]