SIEM Query Utils
Install
Below is how to install in a plain python 3.12+ environment
pip install nbdev-squ
The installation can also be run in a notebook (we tend to use
JupyterLab Desktop
for local dev). The SQU_CONFIG env var indicates to nbdev_squ it
should load the json secret squconfig-my_keyvault_tenantid from the
my_kevault_name keyvault.
%pip install nbdev-squ
import os; os.environ["SQU_CONFIG"] = "{{ my_keyvault_name }}/{{ my_keyvault_tenantid }}"
from nbdev_squ import api
# do cool notebook stuff with api
Security considerations
The contents of the keyvault secret are loaded into memory and cached in the user_cache_dir which should be a temporary secure directory restricted to the single user. Please ensure that the system this library is used on disallows access and/or logging of the user cache directory to external locations, and is on an encrypted disk (a common approach is to use isolated VMs and workstations for sensitive activities).
How to use
Note: If you create/use a Github Codespace on any of the wagov repos, SQU_CONFIG should be configured automatically.
Before using, config needs to be loaded into nbdev_squ.core.cache,
which can be done automatically from json in a keyvault by setting the
env var SQU_CONFIG to "keyvault/tenantid".
export SQU_CONFIG="{{ keyvault }}/{{ tenantid }}"
Can be done in python before import from nbdev_squ as well:
import os; os.environ["SQU_CONFIG"] = "{{ keyvault }}/{{ tenantid }}"
from nbdev_squ import api
import io, pandas
# Load workspace info from datalake blob storage
df = api.list_workspaces(fmt="df"); print(df.shape)
# Load workspace info from introspection of azure graph
df = api.list_securityinsights(); print(df.shape)
# Kusto query to Sentinel workspaces via Azure Lighthouse
df = api.query_all("SecurityIncident | take 20", fmt="df"); print(df.shape)
# Kusto queries to Sentinel workspaces via Azure Lighthouse (batches up to 100 queries at a time)
df = api.query_all(["SecurityAlert | take 20" for a in range(10)]); print(df.shape)
# Kusto query to ADX
#df = api.adxtable2df(api.adx_query("kusto query | take 20"))
# General azure cli cmd
api.azcli(["config", "set", "extension.use_dynamic_install=yes_without_prompt"])
print(len(api.azcli(["account", "list"])))
# Various pre-configured api clients
# RunZero
response = api.clients.runzero.get("/export/org/assets.csv", params={"search": "has_public:t AND alive:t AND (protocol:rdp OR protocol:vnc OR protocol:teamviewer OR protocol:telnet OR protocol:ftp)"})
pandas.read_csv(io.StringIO(response.text)).head(10)
# Jira
pandas.json_normalize(api.clients.jira.jql("updated > -1d")["issues"]).head(10)
# AbuseIPDB
api.clients.abuseipdb.check_ip("1.1.1.1")
# TenableIO
pandas.DataFrame(api.clients.tio.scans.list()).head(10)
badips_df = api.query_all("""
SecurityIncident
| where Classification == "TruePositive"
| mv-expand AlertIds
| project tostring(AlertIds)
| join SecurityAlert on $left.AlertIds == $right.SystemAlertId
| mv-expand todynamic(Entities)
| project Entities.Address
| where isnotempty(Entities_Address)
| distinct tostring(Entities_Address)
""", timespan=pandas.Timedelta("45d"))
df = api.query_all("find where ClientIP startswith '172.16.' | evaluate bag_unpack(pack_) | take 40000")
df = api.query_all("""union withsource="_table" *
| extend _ingestion_time_bin = bin(ingestion_time(), 1h)
| summarize take_any(*) by _table, _ingestion_time_bin
| project pack=pack_all(true)""")
import json
pandas.DataFrame(list(df["pack"].apply(json.loads)))
Secrets template
The below json can be used as a template for saving your own json into
my_keyvault_name/squconfig-my_keyvault_tenantid to use with this
library:
{
"config_version": "20240101 - added ??? access details",
"datalake_blob_prefix": "https://???/???",
"datalake_subscription": "???",
"datalake_account": "???.blob.core.windows.net",
"datalake_container": "???",
"kql_baseurl": "https://raw.githubusercontent.com/???",
"azure_dataexplorer": "https://???.???.kusto.windows.net/???",
"tenant_id": "???",
"jira_url": "https://???.atlassian.net",
"jira_username": "???@???",
"jira_password": "???",
"runzero_apitoken": "???",
"abuseipdb_api_key": "???",
"tenable_access_key": "???",
"tenable_secret_key": "???",
}
Metadata
Release files for nbdev-squ 1.3.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nbdev_squ-1.3.7.tar.gz | 337.9 kB | Without provenance | Details for nbdev_squ-1.3.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nbdev_squ-1.3.7-py3-none-any.whl | Python 3 | none | any | Details for nbdev_squ-1.3.7-py3-none-any.whl |
Total release size: 675.8 kB
Release files / nbdev_squ-1.3.7.tar.gz
| Download URL | nbdev_squ-1.3.7.tar.gz |
|---|---|
| Size | 337.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa2a61485e5518af36e2671971ff422717659ff17b35bd93d5d5d5abf25bf09f
|
|
BLAKE2b-256 checksum How to use checksums |
422d6121c6ac7d7f458dde3a0d88a6e6db0db83a67571d81eeb92bae1b797ffb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Release files / nbdev_squ-1.3.7-py3-none-any.whl
| Download URL | nbdev_squ-1.3.7-py3-none-any.whl |
|---|---|
| Size | 338.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
63318ac9cb0ad5e531a07eeecfaced52bd407fb874d6c688c7dcf29ee2d9ea5f
|
|
BLAKE2b-256 checksum How to use checksums |
64c97e678980f1523efa3a599b79216c408e59e1cccae7f9e89a476c8518362b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Security for nbdev-squ 1.3.7
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.