Giter Site home page Giter Site logo

i3ef0xh4ck / censys-bigquery Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 23 KB

BigQuery tool for Censys! Enterprise customers can take advantage of this tool to quickly query our BQ dataset from a command-line environment.

License: Apache License 2.0

Python 100.00%

censys-bigquery's Introduction

Censys BigQuery Command Line Tool

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 [email protected].

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 https://cloud.google.com/docs/authentication/getting-started for full documentation.

Be sure to set the GOOGLE_APPLICATION_CREDENTIALS environmental variable. $ export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

Installation:
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' --output 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' --output 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' --output json

censys-bigquery's People

Contributors

artsturdevant avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.