Skip to main content

Identify secrets in static structured text

Project description

Whispers

"My little birds are everywhere, even in the North, they whisper to me the strangest stories." - Varys

Whispers is a static structured text analysis tool designed for parsing various common software config formats in search of hardcoded secrets. Whispers can be used as a standalone executable, or as a Python library, which is meant to facilitate its integration into automated processes and pipelines.

Download

Install

pip3 install whispers

Supported formats

Detects

  • Passwords
  • API tokens
  • Cloud keys
  • Private keys
  • Hashed credentials
  • Authentication tokens
  • Webhooks
  • Sensitive files
  • Python functions
  • See all rules

Usage

CLI

# General usage & help
whispers

# More information about Whispers
whispers --info

# Show installed version
whispers --version
# Simplest usage
whispers dir/or/file

# Write JSON results to a file instead of the screen
whispers dir/or/file -o /tmp/secrets.json

# Pipe JSON results downstream
whispers dir/or/file | jq '.[].value'

# Custom usage:
#   - only check 'keys' rule group
#   - with Critical or High severity
#   - everywhere in target/dir except for .log & .raw files (regex)
whispers -g keys -s Critical,High -F '.*\.(log|raw)' target/dir
# Configuration file template
whispers --init > config.yml

# Provide custom configuration file
whispers --config config.yml dir/or/file

# Return custom system code on success
whispers --exitcode 7 dir/or/file
# Include only 'aws-id' & 'aws-secret' rule IDs
whispers --rules aws-id,aws-secret dir/or/file

# Exclude 'file-known' rule ID
whispers --xrules file-known dir/or/file
# Include only 'keys' & 'misc' rule groups
whispers --groups keys,misc dir/or/file

# Exclude 'files' rule group
whispers --xgroups files dir/or/file
# Include only Critical & High severity
whispers --severity Critical,High dir/or/file

# Exclude all Low severity
whispers --xseverity Low dir/or/file
# Include only .json & .yml files (globs)
whispers --files '*.json,*.yml' dir/or/file

# Exclude .log & .cfg files (regex)
whispers --xfiles '.*\.(log|cfg)' dir/or/file

Python

import whispers

args = "-c whispers/config.yml -R file-known -S Info tests/fixtures"

for secret in whispers.secrets(args):
  print(f"[{secret.file}:{secret.line}] {secret.key} = {secret.value}")

Docker

docker build -t=whispers .

docker run \
  --volume $(pwd)/tests/fixtures:/src \
  --volume $(pwd)/tests/configs/integration.yml:/config.yml \
  whispers --config /config.yml .

Config

There are several configuration options available in Whispers. It’s possible to include and exclude results based on file path, keys, values, individual or grouped rules, and severity levels. There is a default configuration file that will be used if you don't specify a custom one.

Note: all keys and static values are always included, and then filtered out based on config and rules.

  • File path specifications are lists of globs
  • Key and value specifications are lists of regular expressions
  • Rule specifications are lists of rule IDs or inline rule definitions
  • Everything else is a list of strings

Config examples

Exclude all log files:

exclude:
  files:
    - .*\.log

Only scan for High level findings in .npmrc files, excluding a known testing value:

include:
  files:
    - "**/*.npmrc"
  severity:
    - High

exclude:
  values: 
    - ^token_for_testing$

Config format

See whispers/models/appconfig.py for available fields and their defaults.

include:
  files:
    - "**/*.yml"  # glob
  rules:
    - password
    - uri
    - id: starks  # inline rule
      message: Whispers from the North
      severity: Critical
      value:
        regex: (Aria|Ned) Stark
        ignorecase: True
  groups:
    - keys
  severity:
    - Critical
    - High
    - Medium

exclude:
  files:
    - .*/tests?/  # regex
  keys:
    - ^foo        # regex
  values:
    - bar$        # regex
  rules:
    - apikey-known

The fastest way to tweak detection in a repeatable way (ie: remove false positives and unwanted results) is to copy the default config.yml into a new file, adapt it, and pass it as an argument to Whispers, for example:

whispers --init > custom.yml
# edit custom.yml as needed
whispers -c custom.yml target

Simple filtering based on rules and severity can also be done with CLI arguments directly, without having to provide a config file. See whispers --info for details.

Rules

Group Rule ID Severity
files file-known Low
infra dockercfg High
infra htpasswd Medium
infra npmrc High
infra pip High
infra pypirc High
keys apikey Medium
keys apikey-known High
keys apikey-maybe Low
keys aws-id Critical
keys aws-secret Critical
keys aws-token Critical
keys privatekey High
misc comment Info
misc creditcard Low
misc secret Low
misc webhook Low
passwords password High
passwords uri High
python cors Low
python system Low

Custom rules

Rules specify the actual things that should be pulled out from key-value pairs. There are several common ones that come built-in, such as AWS keys and passwords, but the tool is made to be easily expandable with new rules.

  • Custom rules can be defined in the main config file under rules: key
  • Custom rules can be added to whispers/rules directory

Rule format

See whispers/models/rule.py for available fields and their defaults.

- id: rule-id                 # unique rule name
  group: rule-group           # rule group name
  description: Values formatted like AWS Session Token
  message: AWS Session Token  # report will show this message
  severity: Critical           # one of Critical, High, Medium, Low, Info

  key:                        # specify key format
    regex: (aws.?session.?token)?
    ignorecase: True          # case-insensitive matching

  value:                      # specify value format
    regex: ^(?=.*[a-z])(?=.*[A-Z])[A-Za-z0-9\+\/]{270,450}$
    ignorecase: False         # case-sensitive matching
    minlen: 270               # value is at least this long
    isBase64: True            # value is base64-encoded
    isAscii: False            # value is binary data when decoded
    isUri: False              # value is not formatted like a URI
    isFile: False             # value doesn't match filenames

  similar: 0.35               # maximum allowed Jaro-Winkler similarity
                              # between key and value (1.0 being exactly the same)

Plugins

All parsing functionality is implemented via plugins. Each plugin implements a class with the pairs() method that runs through files and yields KeyValuePair objects to be checked with rules.

from pathlib import Path
from whispers.models.pair import KeyValuePair

class PluginName:
  def pairs(self, filepath: Path) -> Iterator[KeyValuePair]:
    yield KeyValuePair(
      "key",
      "value",
      keypath=["path", "to", "key"],
      file=filepath.as_posix()
    )

Development

git clone https://github.com/adeptex/whispers
cd whispers
make install-dev
make format test

License

BSD 3-Clause License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whispers-2.2.1.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

whispers-2.2.1-py3-none-any.whl (36.3 kB view details)

Uploaded Python 3

File details

Details for the file whispers-2.2.1.tar.gz.

File metadata

  • Download URL: whispers-2.2.1.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/43.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.2.1 tqdm/4.66.2 importlib-metadata/7.1.0 keyring/25.1.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.11.1

File hashes

Hashes for whispers-2.2.1.tar.gz
Algorithm Hash digest
SHA256 a9d86089bc5ca0aed2021b74edd21d22a45b405d37fa259817d96d6e1c66614b
MD5 c3fdc0e5183ba08c089314af608467fc
BLAKE2b-256 75599b37d0441f7d69e2d7b4952ed44281d01a409b452887099498c53ef4e463

See more details on using hashes here.

File details

Details for the file whispers-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: whispers-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 36.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/43.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.2.1 tqdm/4.66.2 importlib-metadata/7.1.0 keyring/25.1.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.11.1

File hashes

Hashes for whispers-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4573a00654915697f3185f69d9ac779fa10d7bd5768dd0997cfdf8569b6d1b47
MD5 c9c49cd20927ff5e2986ea598fdf7be1
BLAKE2b-256 e53bc46c8a128930fc95e677ea1b9ac1fbb2caed74b231a362fdedfcff1e68fb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page