repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
index.mdMarkdown118 lines5.8 KiBsource raw download

title: "API Key and Token Leaks" topic: "API Key Leaks" topicSlug: "api-key-leaks" sourcePath: "API Key Leaks/README.md" sourceUrl: "https://github.com/swisskyrepo/PayloadsAllTheThings/blob/3ac27901c711/API%20Key%20Leaks/README.md" sha: "3ac27901c711" isReadme: true#

API Key and Token Leaks#

API keys and tokens are forms of authentication commonly used to manage permissions and access to both public and private services. Leaking these sensitive pieces of data can lead to unauthorized access, compromised security, and potential data breaches.

Summary#

Tools#

Methodology#

Common Causes of Leaks#

Validate The API Key#

If assistance is needed in identifying the service that generated the token, mazen160/secrets-patterns-db can be consulted. It is the largest open-source database for detecting secrets, API keys, passwords, tokens, and more. This database contains regex patterns for various secrets.

patterns:
  - pattern:
      name: AWS API Gateway
      regex: '[0-9a-z]+.execute-api.[0-9a-z._-]+.amazonaws.com'
      confidence: low
  - pattern:
      name: AWS API Key
      regex: AKIA[0-9A-Z]{16}
      confidence: high

Use streaak/keyhacks or read the documentation of the service to find a quick way to verify the validity of an API key.

Reducing The Attack Surface#

Check the existence of a private key or AWS credentials before committing your changes in a GitHub repository.

Add these lines to your .pre-commit-config.yaml file.

-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.2.0
    hooks:
    -   id: detect-aws-credentials
    -   id: detect-private-key

References#