Skip to main content

Censys BigQuery Command Line Tool

PyPI Python Version PRs Welcome License

This script allows users to query the data in Censys Data BigQuery Project from the command line. The results from the query can be exported as JSON, CSV, or viewed from the terminal screen.

Note: the Censys Data BigQuery Project is available to enterprise customers and approved academic researchers. For more information on product tiers, contact sales@censys.io.

Setting Up a Service Account in BigQuery

Prior to using the BiqQuery Command Line Tool, you'll need to set up a service account that is associated with your Google Cloud Platform.

Google provides documentation on how to create a service account, either via the GCP Console or the Command Line. Visit Getting started with authentication for full documentation.

Be sure to set the GOOGLE_APPLICATION_CREDENTIALS environmental variable.

export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

Install

The library can be installed using pip.

pip install censys-bigquery-cli

OR

pip install git+https://github.com/censys/censys-bigquery

Usage

The script allows you to input SQL queries as arguments in the script, returning the results as screen output (default), JSON, or CSV.

Here are some example queries:

censys_bq 'SELECT ip, ports, protocols, tags FROM `censys-io.ipv4_public.current` WHERE location.city = "Ann Arbor" and REGEXP_CONTAINS(TO_JSON_STRING(tags), r"rsa-export") LIMIT 25'
censys_bq 'with user_ports as (
SELECT [443, 3306, 6379] as selected_ports
)

SELECT DISTINCT ip, TO_JSON_STRING(user_ports.selected_ports)
  FROM `censys-io.ipv4_banners_public.current`, user_ports, UNNEST(services) as s
  WHERE (SELECT LOGICAL_AND(a_i IN (SELECT port_number FROM UNNEST(services))) FROM UNNEST(user_ports.selected_ports) a_i) LIMIT 15' --format csv
censys_bq 'SELECT COUNT(ip), p80.http.get.body_sha256
FROM `censys-io.ipv4_public.current`
WHERE REGEXP_CONTAINS(p80.http.get.body, r"(?i)coinhive.min.js>")
GROUP BY p80.http.get.body_sha256
ORDER BY 1 DESC' --format json
censys_bq 'with Data as (SELECT
  distinct fingerprint_sha256
FROM
  `censys-io.certificates_public.certificates`, UNNEST(parsed.subject.organization) as po, UNNEST(parsed.names) as parsed_names
WHERE
   REGEXP_CONTAINS(TO_JSON_STRING(parsed.names), r"[.]example[.]")
)

SELECT
  distinct ip
FROM
  `censys-io.ipv4_banners_public.current` as c, UNNEST(services)
      JOIN Data as d on d.fingerprint_sha256 = certificate.fingerprints.sha256
LIMIT 20' --format json

Resources

Contributing

All contributions (no matter how small) are always welcome.

Development

git clone git@github.com:censys/censys-bigquery.git
cd censys-bigquery/
pip install -e ".[dev]"

License

This software is licensed under Apache License, Version 2.0

  • Copyright (C) 2021 Censys, Inc.

Metadata

Release files for censys-bigquery-cli 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for censys-bigquery-cli 1.1.1
File Size Uploaded Provenance Actions
censys-bigquery-cli-1.1.1.tar.gz 5.4 kB Without provenance Details for censys-bigquery-cli-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for censys-bigquery-cli 1.1.1
File Interpreter ABI Platform Actions
censys_bigquery_cli-1.1.1-py2.py3-none-any.whl Python 2, Python 3 none any Details for censys_bigquery_cli-1.1.1-py2.py3-none-any.whl

Total release size: 15.2 kB

Release files / censys-bigquery-cli-1.1.1.tar.gz

Download URL censys-bigquery-cli-1.1.1.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5ea95af8e3ab61dae06c42fe4b90eecdcb86a0fea8a4d69dfc3e9028bb178ab6
BLAKE2b-256 checksum
How to use checksums
9ceb01b41732be7b3adc8b1e1855d136b73dc4056c56f4e6a6dcd855bf95f565
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.10

Release files / censys_bigquery_cli-1.1.1-py2.py3-none-any.whl

Download URL censys_bigquery_cli-1.1.1-py2.py3-none-any.whl
Size 9.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0ba181d2e74392adcbdafa4b91db132a9654f80edcc885e194db4bc6dd1946ad
BLAKE2b-256 checksum
How to use checksums
4f41f7a2b77331230ea2945aee5e00b35293592a5105ffd960bc268f89782ed4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.10

Security for censys-bigquery-cli 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page