Elastic Security Labs thrunting-tools
Have you ever been threat hunting (hereafter known as "thrunting") in Kibana and thought "Gee! I wish I could take these results and do some automation on the command line!". Well look no further, fellow thrunter! This repo has just what you need to make your automation adventures a bit easier.
thrunting-tools is a collection of command line utilities for working with data.
The current list of tools are:
eql-query, a tool to let you perform EQL searches from your shell!lucene-query, a tool to let you perform Lucene searches against Elasticsearch in your comfort zone, the command line.from-charcode, a tool to convert a character code in a given base to the ASCII characterto-charcode, a tool to convert an ASCII character to a given baseurl-decode, a tool to decode urlencoded stringsurl-encode, a tool to encode common character or all special characters to urlencoded stringszlib-compress, a tool to perform zlib compression/deflation on the command linezlib-decompress, a tool to perform zlib decompression/inflation on the command linezlib-deflate, an alias for zlib-compresszlib-decompress, an alias for zlib-decompressunmap-pe, processes a PE binary, removing the memory mapping. Useful for analyzing process memory dumps
Installation
The easiest way to install thrunting-tools is with pipx. Once you have pipx installed, to install these tools on your path, simply install the latest release with:
pipx install thrunting-tools
Alternatively, if you'd like to install with pip and you have your own Python environment, you can do that too.
pip3 install thrunting-tools
You can now check that each command was installed.
eql-query --version
lucene-query --version
Docker Usage
Lastly, if you want to use a container runtime environment, you can use the latest release from the repository GitHub Container Repository. Currently, we're publishing AMD64 and ARM64 images.
docker pull ghcr.io/elastic/securitylabs-thrunting-tools:main
Then, you can run the container and pass your local configuration in to the default
location used by the container, /config.yml. (NOTE: the :z part of the volume
specification is only needed if you use SELinux)
docker run -ti -v "${HOME}/.config/thrunting-tools/config.yml":/config.yml:ro,z \
--rm ghcr.io/elastic/securitylabs-thrunting-tools:latest eql-query --help
Usage
Each of the commands provide a usage when called with --help.
$ eql-query --help
Usage: eql-query [OPTIONS] QUERY
╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────╮
│ * query TEXT Query specified using EQL (See https://ela.st/eql) [required] │
╰─────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ───────────────────────────────────────────────────────────────────────────────────╮
│ --index -i TEXT Index pattern to search. Defaults to │
│ '.alerts-security.alerts-default,apm-*-transaction*,logs-*' │
│ --since -s TEXT Earliest time filter using datemath or datetime │
│ [default: now-30d/d] │
│ --before -b TEXT Latest time filter using datemath or datetime │
│ [default: now] │
│ --compact -c Output one event/sequence per line │
│ --fields -f TEXT Comma separated list of fields to display [default: None] │
│ --size -s INTEGER Specify maximum size of result set [default: 100] │
│ --config PATH Optional path to YAML configuration with settings for │
│ Elasticsearch │
│ [default: │
│ /home/user/.config/thrunting-tools/config.yml] │
│ --environment -e TEXT Environment name to use from config file (if present) │
│ [default: default] │
│ --help Show this message and exit. │
╰─────────────────────────────────────────────────────────────────────────────────────────────╯
Configuration
There are two ways to pass configuration to the tools: environment variables and configuration files.
The tools default to looking for the YAML configuration file in the platform-specific
configuration directory (see the --help output). If present, configuration groups are
top-level keys (e.g. elasticsearch), which contain a list of environments. All scripts will
check for the first environment with the name attribute set to default if none is specified
on the command line.
Example configuration file:
elasticsearch:
- name: default
cloud_id: "security-cluster:dXMtd2VzdDEuZ2NwLmNsb3VkLmVzLmlvJGFiY2R="
cloud_auth: "elastic:changeme"
Examples
Run query using devel environment configuration
eql-query -e devel 'malware where event.kind: "alert"'
Using jq and wc to get the number of alert events where EXCEL.EXE was the parent process.
eql-query 'any where event.kind: "alert"' -c | \
jq 'select(._source.process.parent.name == "EXCEL.EXE")' -c | wc -l
Find the unique event categories of all events in the last day that triggered based upon a rule using the 'sandbox' environment
$ lucene-query --since 'now-1d' 'rule: *' -e sandbox -c | \
jq '._source.event.category[]' -c -r | sort -u
network
Find the unique dynamic DNS subdomains of a particular domain resolved in our network in the last month
lucene-query --since 'now-1M' 'dns.question.name: *.duckdns.org' -c \
| jq '._source.dns.question.name' -r | sort -u
...
Find a list of all the unique agent IDs that resolved a known malware domain within the last 12 months.
$ lucene-query --since 'now-12M' 'dns.question.name: puerto2547.duckdns.org' -c \
| jq '._source.agent.id' -r | sort -u
ec82f608-3d1b-4651-900e-b970c68bbeef
Extract a single binary using Elastic Defend integration with optional sample collection enabled. Note that additional shell scripting would be needed to loop over a set of results.
eql-query 'process where ?process.Ext.memory_region.bytes_compressed_present == true' \
--size 1 \
--fields 'process.Ext.memory_region.bytes_compressed' | \
jq -r '.process.Ext.memory_region.bytes_compressed' | \
base64 -d | zlib-decompress > captured_sample.bin
Metadata
Release files for thrunting-tools 8.5.2
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 |
|---|---|---|---|---|
| thrunting_tools-8.5.2.tar.gz | 17.4 kB | Without provenance | Details for thrunting_tools-8.5.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| thrunting_tools-8.5.2-py3-none-any.whl | Python 3 | none | any | Details for thrunting_tools-8.5.2-py3-none-any.whl |
Total release size: 43.0 kB
Release files / thrunting_tools-8.5.2.tar.gz
| Download URL | thrunting_tools-8.5.2.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c23bcff461a057ed1c93070a00073a9dce3c6f0e2f287ee79a4ee27b73f332e
|
|
BLAKE2b-256 checksum How to use checksums |
a3bd540f89b1f6ab062e33a4f50b780d05864e2b81255b66b7d0dd2e4491b469
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.11.0 Linux/5.15.0-1023-azure
|
Release files / thrunting_tools-8.5.2-py3-none-any.whl
| Download URL | thrunting_tools-8.5.2-py3-none-any.whl |
|---|---|
| Size | 25.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ee4986e8cf55a8a871e9d22c182f21ca5feb7eaa4a398ea7b8b3b8abe117430
|
|
BLAKE2b-256 checksum How to use checksums |
ea6d4a883f587f0fcb69d9872426a64b0b20d3686472b69deacf385e7a756bd0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.11.0 Linux/5.15.0-1023-azure
|
Security for thrunting-tools 8.5.2
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.