npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xh4h/loki

v1.0.8

Published

The dependency confusion vulnerability scanner and autoexploitation tool

Downloads

36

Readme

About

Loki helps to identify NodeJS projects that are vulnerable to Dependency Confusion supply chain attacks.

Loki has been created with the goal of helping developers to scan their projects and identifying possible attack vectors that could take advantage of vulnerabilities in the dependency supply chain.

Loki is a god in Norse mithology. Among other powers, he is an adept shapeshifter and people impersonator.

Disclaimer

Loki is a defensive tool. The attack mode simply inserts a payload opening a listener service to allow the developer to connect to the compromised dependency with the sole purpose of showing the impact of a misconfigured module.

When may a Dependency Confusion supply chain attack happen?

Dependency Confusion attacks may occur if:

  • A company uses a hybrid approach to download their dependencies from both their internal repositories and public repositories.
  • A developer has not properly configured a project's npm registry. A lightweight private npm proxy registry such as Verdaccio can be configured.
  • A typo in the name of a dependency may lead to an untrusted dependency being downloaded from the wrong repository. Better known as typosquatting.
  • The version specified of the wanted dependency in the package.json file allows downloading newer versions. Having such "loki-this-dependency-does-not-exist": "^1.1.0" dependency allows downloading the latest version of the dependency from 1.1.0 up to, but not including, 2.0.0. Similar interaction happens with tilde ~. If a project has a hybrid setup, if the public repository such as npmjs.org contains a higher version compared with the private repository, the public one will be downloaded.
  • A package name has a different import name. If a junior developer, by reading the code, expects the installation name of a package used in the repository is the same as the import. As an example, we can have a look at the Python image processing library OpenCV whose import name is cv2 but the correct pip install command to install it is pip install opencv-python.

Mitigation

  • Strict internal dependency management by configuring the private repository to never go beyond (access the public realm) when it does not contain the wanted dependency. As previously said, Verdaccio is a nice tool to achieve this.
  • Using dependency scopes or namespaces to avoid typosquatting.
  • Using version pinning. This technique does not index whether your current dependencies have been compromised, but it will prevent from downloading newer untrusted versions.
  • Integrity checking.

Features

  • Dependency scanning
  • npmjs package publishing
  • Configurable reverse shell generation
  • Payload injection in vulnerable projects
  • Attack mode (PoC after successful payload injection)
  • Inspector mode (display hash of the commit that introduced the vulnerable package if the directory to scan is a git repository)

Usage

Prerequisite

To use this tool, it is expected that you have the following available in your environment:

  • Node.js and npm in stable and recent versions
  • The Git binary available in your path

If downloaded from the repository:

$ node bin/loki.js [options]

Using npx:

$ npx @xh4h/loki [options]

Options

Options
--directory   -d   Path to directory to scan
--entrypoint  -e   Path to file to execute if directory is vulnerable (defaults to index.js)
--inspect     -i   Enable inspector mode
--accesstoken -a   Access token for npmjs.com
--attack           Whether to attack the project
--host             Host IP where the reverse shell lister is running (defaults to localhost)
--port             Port where the reverse shell lister is running (defaults to 1456)

Example

Contributing

Contributing Guide

License

MIT

Credits

Big thanks to the Snyk team for their work on snync as Loki uses a modified version of their tool.