pdscan

repository·master·Indexed 43 days ago

https://github.com/ankane/pdscan

A tool to scan data stores for unencrypted personally identifiable information (PII) such as email addresses, credit card numbers, and SSNs. It supports various sources including Postgres, MySQL, MariaDB, MongoDB, Redis, SQL Server, SQLite, S3 buckets, local files, Elasticsearch, and OpenSearch via URI-based connection strings.

Tokens
1.6K
Snippets
9
Records
10
Agent score
5%

What's inside pdscan

  1. Install pdscan

    master

    You can install pdscan using several methods depending on your environment:

    Prebuilt Binaries

    Download the latest version for your platform from the GitHub releases page:

    • Linux: x86_64 or arm64 tar.gz
    • Mac: x86_64 or arm64 darwin tar.gz
    • Windows: x86_64 zip

    Go

    go install github.com/ankane/pdscan@latest

    Homebrew

    brew install ankane/brew/pdscan

    Docker

    Pull the image:

    docker pull ankane/pdscan

    Run it by passing a connection URI:

    docker run -ti ankane/pdscan <connection-uri>
    go install github.com/ankane/pdscan@latest
  2. Scan Postgres databases

    master

    Connect to Postgres using the postgres:// protocol.

    Security Note: Always ensure your connection is secure when connecting over a network. Use SSH, a VPN, or append ?sslmode=verify-full to the URI. If you need to explicitly disable SSL, append ?sslmode=disable.

    Optimization: For better sampling performance, enable the tsm_system_rows extension in your Postgres database:

    CREATE EXTENSION tsm_system_rows;
    pdscan postgres://user:pass@host:5432/dbname?sslmode=disable
  3. Run pdscan in Docker with host access

    master

    When running pdscan inside Docker, you may need to connect to services on the host machine or mount local files.

    Connecting to host databases: Use host.docker.internal as the hostname.

    • Linux: Requires the --add-host flag: docker run -ti --add-host=host.docker.internal:host-gateway pdscan "postgres://user@host.docker.internal:5432/dbname?sslmode=disable"
    • Mac/Windows: docker run -ti pdscan "postgres://user@host.docker.internal:5432/dbname?sslmode=disable"

    Scanning host files: Mount the local directory as a volume: docker run -ti -v /path/to/files:/data pdscan file:///data

    docker run -ti --add-host=host.docker.internal:host-gateway pdscan "postgres://user@host.docker.internal:5432/dbname?sslmode=disable"
  4. Scan local files and directories

    master

    Use the file:// prefix to scan files or entire directories.

    • File: file://path/to/file.txt
    • Directory: file://path/to/directory
    • Absolute path: file:///absolute/path/to/file.txt
    • Home directory (Mac/Linux): file://$HOME/file.txt
    pdscan file:///absolute/path/to/file.txt
  5. Scan Elasticsearch and OpenSearch data stores

    master

    To scan Elasticsearch or OpenSearch, use the appropriate protocol prefix in your connection URI. You can specify individual indices or use wildcards.

    Elasticsearch:

    • HTTP: elasticsearch+http://user:pass@host:9200
    • HTTPS: elasticsearch+https://user:pass@host:9200
    • Specific indices: elasticsearch+http://user:pass@host:9200/index1,index2
    • Wildcards: "elasticsearch+http://user:pass@host:9200/index*"

    OpenSearch:

    • HTTP: opensearch+http://user:pass@host:9200
    • HTTPS: opensearch+https://user:pass@host:9200
    • Specific indices: opensearch+http://user:pass@host:9200/index1,index2
    • Wildcards: "opensearch+http://user:pass@host:9200/index*"
    pdscan elasticsearch+http://user:pass@host:9200/index1,index2
  6. Scan S3 buckets

    master

    Scan files in S3 using the s3:// prefix.

    • Single file: s3://bucket/path/to/file.txt (Requires s3:GetObject permission)
    • Directory/Prefix: s3://bucket/path/to/directory/ (Requires s3:ListBucket and s3:GetObject permissions)
    pdscan s3://bucket/path/to/directory/
  7. Scan other supported data stores

    master

    pdscan supports several other data stores via URI-based connection strings:

    • MariaDB: mariadb://user:pass@host:3306/dbname
    • MongoDB: mongodb://user:pass@host:27017/dbname
    • MySQL: mysql://user:pass@host:3306/dbname
    • Redis: redis://user:pass@host:6379/db
    • SQLite: sqlite://path/to/dbname.sqlite3 (Note: Not available with prebuilt binaries)
    • SQL Server: "sqlserver://user:pass@host:1433?database=dbname"
    pdscan mysql://user:pass@host:3306/dbname
  8. pdscan CLI options reference

    master

    Use these flags to customize the scan behavior:

    FlagDescription
    --show-dataShow the actual data found
    --show-allShow low confidence matches
    --sample-size <int>Change the sample size
    --processes <int>Specify the number of processes to use (defaults to 1)
    --only <types>Scan for only certain types of data (comma-separated, e.g., email,phone)
    --except <types>Scan for all except certain types of data (comma-separated, e.g., ip,mac)
    --min-count <int>(Experimental) Specify the minimum number of rows/documents/lines for a match
    --pattern <regex>(Experimental) Specify a custom pattern
    --format ndjson(Experimental) Output newline delimited JSON
  9. Configure pdscan CLI flags

    master

    The pdscan CLI supports several persistent flags to control the scanning behavior, sampling, filtering, and output format.

    Output and Visibility

    • --show-data (bool): Show the actual data found.
    • --show-all (bool): Show all matches (instead of just a summary).
    • --format (string): The output format. Defaults to text. (experimental)

    Scanning and Performance

    • --sample-size (int): The number of records to sample from the data store. Defaults to 10000. Must be a positive integer.
    • --processes (int): The number of parallel processes to use. Defaults to 1.

    Rule Filtering

    • --only (string): Only run certain rules.
    • --except (string): Skip certain rules.

    Experimental Features

    • --min-count (int): Minimum rows/documents/lines for a match. Must be a positive integer.
    • --pattern (string): Use a custom pattern for scanning.
    # Example usage with flags
    pdscan "postgres://user:pass@localhost:5432/db" --show-data --sample-size 5000 --format text
  10. Use the pdscan CLI to scan data stores

    master

    The pdscan command scans your data stores for unencrypted personal data (PII). You must provide a connection URI as the primary argument.

    Usage:

    pdscan [connection-uri] [flags]

    If no connection URI is provided, the help menu will be displayed.

    pdscan [connection-uri]