VulnAPI

repository·main·Indexed 42 days ago

https://github.com/cerberauth/vulnapi

An open-source Dynamic Application Security Testing (DAST) tool designed to scan APIs for common security vulnerabilities. It features a CLI for discovering API endpoints, subdomains, and server information, and supports vulnerability scanning via curl-like syntax, OpenAPI contracts, and GraphQL endpoints. The tool also includes utilities for generating and testing JWT tokens with various signing algorithms such as HS256, RS256, and ES256.

Tokens
30.6K
Snippets
112
Records
175
Agent score
54%

What's inside VulnAPI

  1. Overview of VulnAPI CLI commands

    main

    The vulnapi CLI is used for API security vulnerability scanning, API discovery, and JWT utilities.

    Available command categories include:

    • Scanning: scan curl (single endpoint), scan openapi (OpenAPI specifications), and scan graphql (GraphQL endpoints).
    • Discovery: discover api (path and tech fingerprint discovery) and discover domain (subdomain endpoint discovery).
    • JWT Utilities: jwt generate (generating new JWTs from existing tokens).

    Note: The serve command is deprecated and the HTTP server has been removed.

    # General usage patterns
    vulnapi <command> [flags]
    vulnapi --help
    vulnapi version
  2. Use the VulnAPI CLI

    main

    The vulnapi CLI is used for API security scanning, discovery, and JWT utilities. It supports scanning single endpoints via curl-style options, scanning OpenAPI specifications, scanning GraphQL endpoints, discovering API paths/fingerprints, discovering endpoints across subdomains, and generating JWTs.

    Available Command Groups:

    • scan curl: Scan a single API endpoint using curl-style options.
    • scan openapi: Scan all endpoints defined in an OpenAPI specification.
    • scan graphql: Scan a GraphQL endpoint.
    • discover api: Discover well-known paths and technology fingerprints for an API.
    • discover domain: Discover API endpoints across common subdomains.
    • jwt generate: Generate a new JWT from an existing token with a different algorithm or key.
    vulnapi <command> [flags]
  3. Understanding the JWT None Algorithm vulnerability

    main

    The jwt.alg_none vulnerability (related to CVE-2015-9235 and CVE-2015-2951) occurs when a server accepts a JSON Web Token (JWT) that specifies the none algorithm in its header.

    Because the none algorithm implies there is no signature, the server fails to verify the integrity of the token. An attacker can modify the payload (e.g., changing a user ID or role) and present the unsigned token as valid, leading to:

    • Unauthorized Access and Impersonation
    • Privilege Escalation
    • Data Tampering
    • Bypassing Security Controls

    Classification:

    • OWASP Category: API2:2023 Broken Authentication
    • CWEs: CWE-345 (Insufficient Verification of Data Authenticity), CWE-327 (Use of a Broken or Risky Cryptographic Algorithm), CWE-20 (Improper Input Validation)
  4. How VulnAPI handles exit codes and severity thresholds

    main

    VulnAPI uses exit codes and stderr to integrate with CI/CD pipelines:

    1. Exit Codes: Commands return 0 on success and a non-zero value on error.
    2. Severity Thresholds: If any finding has a CVSS score higher than the configured --severity-threshold (default is 1.0), VulnAPI writes the output to stderr in addition to stdout.
    3. CI/CD Integration: Writing to stderr is designed to trigger failure patterns like || exit 1 in automated environments.

    To optimize performance, use --only-scans-above-threshold to skip checks that cannot reach your defined --severity-threshold.

  5. JWT Blank Secret vulnerability details

    main

    The JWT Blank Secret vulnerability (Severity: High) occurs when a JSON Web Token (JWT) is signed with an empty secret. This lacks proper cryptographic protection, allowing attackers to modify claims and content without detection.

    Example Tokens

    Valid JWT (HS256):

    eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTYyNDI2MjIsImlhdCI6MTUxNjIzOTAyMiwibmFtZSI6IkpvaG4gRG9lIiwic3ViIjoiMmNiMzA3YmEtYmI0Ni00MTk0LTg1NGYtNDc3NDA0NmQ5YzliIn0.SCC35SSgMSMr0kV1i_TuPAhiSGtsC1cFGCfvaus5GyU

    Vulnerable JWT (Blank Secret): (Same header and payload, but with a signature generated using an empty key)

    eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTYyNDI2MjIsImlhdCI6MTUxNjIzOTAyMiwibmFtZSI6IkpvaG4gRG9lIiwic3ViIjoiMmNiMzA3YmEtYmI0Ni00MTk0LTg1NGYtNDc3NDA0NmQ5YzliIn0.rpOjSoJBjzZifWAc-MBQ4UVS9tOY7gJV8cN0j6bN1oA
  6. Prevent JWT key injection attacks

    main

    Do not resolve verification keys from the token header. Attackers can control headers like jwk, jku, x5c, or x5u to force the server to use a key they generated.

    Best Practices:

    • Resolve kid against a trusted, server-side key set.
    • If dynamic retrieval is required, validate jku or x5u against a strict allowlist of known, trusted URLs.

    VulnAPI detects these via jwt.jwk_injection, jwt.jku_injection, jwt.x5c_injection, and jwt.x5u_injection scans.

  7. Understanding the JWT Expired vulnerability

    main

    A vulnerability occurs when a server accepts a JSON Web Token (JWT) even after the expiration time specified in the exp claim has passed. JWTs are intended to be short-lived; once the Unix timestamp in the exp claim is in the past, the server must reject the token for authentication or authorization requests.

    Severity: Medium Classifications:

    • CWE-287: Improper Authentication
    • CWE-613: Insufficient Session Expiration OWASP Category: OWASP API2:2023 Broken Authentication
  8. Understand JWT X5U Header Injection

    main

    Concept

    JWT X5U Header Injection is a vulnerability where a server reads the x5u (X.509 URL) header from an incoming token, fetches the certificate at that URL, and uses it to verify the signature without checking if it chains to a trusted CA. This allows an attacker to point the header to a server they control, serving an attacker-generated certificate to bypass authentication.

    Impact

    • Full Authentication Bypass: Attackers can forge tokens for any user, including administrators.
    • Server-Side Request Forgery (SSRF): The target server is coerced into making outbound requests to attacker-controlled URLs.
    • Account Takeover: Impersonation of any user in the system.

    Classifications

    • CWE-295: Improper Certificate Validation
    • CAPEC-194: Fake the Source of Data
    • OWASP Category: API2:2023 Broken Authentication
  9. Interpret scan results with no findings

    main
    If the vulnerability table is empty, it means VulnAPI did not find any vulnerabilities with a CVSS score above the default threshold of 1.0. Note that VulnAPI tests for a specific set of known vulnerabilities; a clean scan does not guarantee the absence of all possible security issues.
  10. Configure security schemes in an OpenAPI Contract

    main

    When scanning APIs that require authentication, you may need to manually edit your downloaded OpenAPI JSON file to include securitySchemes and apply them to specific paths. This ensures VulnAPI can test protected endpoints.

    To add Bearer authentication, include a bearerAuth definition in the components.securitySchemes section and reference it in the security array of the relevant operations.

    Example OpenAPI Configuration Snippet:

    {
      "openapi": "3.0.1",
      "info": {
        "title": "VAmPI",
        "version": "0.1"
      },
      "servers": [
        {
          "url": "http://localhost:5000"
        }
      ],
      "paths": {
        "/users/v1/{username}/email": {
          "put": {
            "operationId": "api_views.users.update_email",
            "security": [
              {
                "bearerAuth": []
              }
            ]
          }
        }
      },
      "components": {
        "securitySchemes": {
          "bearerAuth": {
            "type": "http",
            "scheme": "bearer",
            "bearerFormat": "JWT"
          }
        }
      }
    }
    {
      "components": {
        "securitySchemes": {
          "bearerAuth": {
            "bearerFormat": "JWT",
            "scheme": "bearer",
            "type": "http"
          }
        }
      },
      "info": {
        "description": "OpenAPI v3 specs for VAmPI",
        "title": "VAmPI",
        "version": "0.1"
      },
      "openapi": "3.0.1",
      "paths": {
        "/users/v1/{username}/email": {
          "put": {
            "description": "Update a single users email",
            "operationId": "api_views.users.update_email",
            "security": [
              {
                "bearerAuth": []
              }
            ]
          }
        }
      },
      "servers": [
        {
          "url": "http://localhost:5000"
        }
      ]
    }
  11. Understand API Authentication Brute Force Attacks

    main

    An API Authentication Brute Force Attack is a trial-and-error method where attackers use automated tools to make multiple requests to an authentication endpoint. The goal is to guess correct credentials (usernames/passwords) or access tokens by trying different combinations.

    Vulnerability Details

    Impact

    Successful attacks can lead to unauthorized API access, sensitive data breaches, and data manipulation.