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

cwe-tool

v1.4.2

Published

A command line CWE discovery tool based on OWASP / CAPSEC database of Common Weakness Enumeration.

Downloads

135

Readme

Install

Executable with Node.js tooling

If you have a Node.js environment, you can invoke cwe-tool using the npx tool as follows:

npx cwe-tool [...command-line options...]

Docker

Pull the image from Docker Hub

docker pull lirantal/cwe-tool
docker run --rm lirantal/cwe-tool --search test

Local build instructions

git clone https://github.com/OWASP/cwe-tool
docker build -t docker.pkg.github.com/owasp/cwe-tool/cwe-tool . 

-t image name above can be an image name of your choosing!

Run examples with Docker

docker run --rm docker.pkg.github.com/owasp/cwe-tool/cwe-tool --id 22
docker run --rm docker.pkg.github.com/owasp/cwe-tool/cwe-tool --search test

Do not want to build locally? Pull the image down

Pull image from Github package registry and run a search

docker pull docker.pkg.github.com/owasp/cwe-tool/cwe-tool:latest
docker run --rm docker.pkg.github.com/owasp/cwe-tool/cwe-tool:latest --search test

Usage

The CWE Tool output is JSON to allow processing of the data or later investigations.

Command-line options blueprint:

| command-line argument | description | implemented | | --------------------- | --------------------------------------------------------------------------------------------------- | -------------- | | --id | Get a CWE data by its ID. | ✅ | | --parent-id | When both --id and --parent-id are provided, returns only CWE ids which satisfy the parent id. | ✅ PRs welcome | | --indirect | When specified along with --parent-id, retrieves all indirect parents up to the root of the tree. | ✅ | | --search | String search returns all the matching CWEs titles | ✅ | | --show-membership | Returns all the CWE IDs along with their CWE Category membership relations | ❌ PRs welcome |

Example

Get CWE By ID

npx cwe-tool --id 22

Filter for CWE IDs that satisfy a parent relationship

The following command filters all CWE IDs based on whether they satisfy any direct or indirect relationship across the tree to a given parent ID.

npx cwe-tool --id 22 --parent-id 167 --indirect

The output is the following JSON:

{
  "attr": {
    "@_ID": "242",
    "@_Name": "Use of Inherently Dangerous Function",
    "@_Abstraction": "Base",
    "@_Structure": "Simple",
    "@_Status": "Draft"
  },
  "Description": "The program calls a function that can never be guaranteed to work safely.",
  "Extended_Description": "Certain functions behave in dangerous ways regardless of how they are used. Functions in this category were often implemented without taking security concerns into account. The gets() function is unsafe because it does not perform bounds checking on the size of its input. An attacker can easily send arbitrarily-sized input to gets() and overflow the destination buffer. Similarly, the >> operator is unsafe to use when reading into a statically-allocated character array because it does not perform bounds checking on the size of its input. An attacker can easily send arbitrarily-sized input to the >> operator and overflow the destination buffer.",
  "Related_Weaknesses": {
    "Related_Weakness": {
      "attr": {
        "@_Nature": "ChildOf",
        "@_CWE_ID": "1177",
        "@_View_ID": "1000",
        "@_Ordinal": "Primary"
      }
    }
  },
  "Weakness_Ordinalities": { "Weakness_Ordinality": { "Ordinality": "Primary" } },
  "Applicable_Platforms": {
    "Language": [
      { "attr": { "@_Name": "C", "@_Prevalence": "Undetermined" } },
      { "attr": { "@_Name": "C++", "@_Prevalence": "Undetermined" } }
    ]
  },
  "Modes_Of_Introduction": { "Introduction": { "Phase": "Implementation" } },
  "Likelihood_Of_Exploit": "High",
  "Common_Consequences": { "Consequence": { "Scope": "Other", "Impact": "Varies by Context" } },
  "Potential_Mitigations": {
    "Mitigation": [
      {
        "Phase": ["Implementation", "Requirements"],
        "Description": "Ban the use of dangerous functions. Use their safe equivalent."
      },
      {
        "Phase": "Testing",
        "Description": "Use grep or static analysis tools to spot usage of dangerous functions."
      }
    ]
  },
  "Demonstrative_Examples": {
    "Demonstrative_Example": [
      {
        "Intro_Text": "The code below calls gets() to read information into a buffer.",
        "Example_Code": {
          "attr": { "@_Nature": "bad", "@_Language": "C" },
          "xhtml:div": { "#text": "char buf[BUFSIZE];gets(buf);", "xhtml:br": "" }
        },
        "Body_Text": "The gets() function in C is inherently unsafe."
      },
      {
        "attr": { "@_Demonstrative_Example_ID": "DX-5" },
        "Intro_Text": "The code below calls the gets() function to read in data from the command line.",
        "Example_Code": {
          "attr": { "@_Nature": "bad", "@_Language": "C" },
          "xhtml:div": {
            "#text": "}",
            "xhtml:div": {
              "#text": "char buf[24];printf(\"Please enter your name and press <Enter>\\n\");gets(buf);...",
              "attr": { "@_style": "margin-left:10px;" },
              "xhtml:br": ["", "", ""]
            }
          }
        },
        "Body_Text": "However, the programmer uses the function gets() which is inherently unsafe because it blindly copies all input from STDIN to the buffer without checking size. This allows the user to provide a string that is larger than the buffer size, resulting in an overflow condition."
      }
    ]
  },
  "Taxonomy_Mappings": {
    "Taxonomy_Mapping": [
      {
        "attr": { "@_Taxonomy_Name": "7 Pernicious Kingdoms" },
        "Entry_Name": "Dangerous Functions"
      },
      {
        "attr": { "@_Taxonomy_Name": "CERT C Secure Coding" },
        "Entry_ID": "POS33-C",
        "Entry_Name": "Do not use vfork()",
        "Mapping_Fit": "CWE More Abstract"
      },
      {
        "attr": { "@_Taxonomy_Name": "Software Fault Patterns" },
        "Entry_ID": "SFP3",
        "Entry_Name": "Use of an improper API"
      }
    ]
  },
  "References": {
    "Reference": [
      { "attr": { "@_External_Reference_ID": "REF-6" } },
      {
        "attr": { "@_External_Reference_ID": "REF-194", "@_Section": "Chapter 5. Working with I/O" }
      },
      {
        "attr": {
          "@_External_Reference_ID": "REF-7",
          "@_Section": "Chapter 5, "gets and fgets" Page 163"
        }
      }
    ]
  },
  "Content_History": {
    "Submission": { "Submission_Name": "7 Pernicious Kingdoms", "Submission_Date": "2006-07-19" },
    "Modification": [
      {
        "Modification_Name": "Sean Eidemiller",
        "Modification_Organization": "Cigital",
        "Modification_Date": "2008-07-01",
        "Modification_Comment": "added/updated demonstrative examples"
      },
      {
        "Modification_Name": "Eric Dalci",
        "Modification_Organization": "Cigital",
        "Modification_Date": "2008-07-01",
        "Modification_Comment": "updated Potential_Mitigations"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2008-09-08",
        "Modification_Comment": "updated Applicable_Platforms, Relationships, Other_Notes, Taxonomy_Mappings, Type, Weakness_Ordinalities"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2008-11-24",
        "Modification_Comment": "updated Relationships, Taxonomy_Mappings"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2009-10-29",
        "Modification_Comment": "updated Description, Other_Notes, References"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2010-02-16",
        "Modification_Comment": "updated Demonstrative_Examples, References, Relationships"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2010-04-05",
        "Modification_Comment": "updated Relationships"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2011-06-01",
        "Modification_Comment": "updated Common_Consequences"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2011-06-27",
        "Modification_Comment": "updated Common_Consequences"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2012-05-11",
        "Modification_Comment": "updated Relationships"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2012-10-30",
        "Modification_Comment": "updated Potential_Mitigations"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2014-07-30",
        "Modification_Comment": "updated Demonstrative_Examples, Relationships, Taxonomy_Mappings"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2017-11-08",
        "Modification_Comment": "updated Causal_Nature, References, Relationships, Taxonomy_Mappings"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2018-03-27",
        "Modification_Comment": "updated References"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2019-01-03",
        "Modification_Comment": "updated Relationships"
      },
      {
        "Modification_Name": "CWE Content Team",
        "Modification_Organization": "MITRE",
        "Modification_Date": "2020-02-24",
        "Modification_Comment": "updated References, Relationships"
      }
    ],
    "Previous_Entry_Name": [
      { "#text": "Dangerous Functions", "attr": { "@_Date": "2008-01-30" } },
      { "#text": "Use of Inherently Dangerous Functions", "attr": { "@_Date": "2008-04-11" } }
    ]
  }
}

Contributing

Please consult CONTRIBUTING for guidelines on contributing to this project.

Author

cwe-tool © Liran Tal, Released under the Apache-2.0 License.