pySigma OpenSearch backend
Project description
pySigma Opensearch Lucene Backend
This is the Opensearch Lucene backend for pySigma. It provides the package sigma.backends.opensearch with the OpensearchLuceneBackend class.
It supports the following output formats:
- default: plain Opensearch queries in Lucene Syntax
- Hint: In Dashboard you have to switch from DQL to Lucene
- monitor_rule: JSON Structure to import Opensearch Alerting Rules
This backend is currently maintained by:
Background
Since Lucene based queries are very identical to Elasticsearch Lucene queries, most of the code for this Backend comes from pySigma-backend-elasticsearch.
Opensearch specific changes and output formats are done in this backend (eg. Monitor Rules).
Howto
Create Output - sigma-cli
sigma convert \
-t opensearch \
-p ecs_windows \
-f monitor_rule \
/data/sigma/rules/windows/process_creation/proc_creation_win_whoami_priv.yml
Create Alerting Rules - Python
from sigma.backends.opensearch import OpensearchLuceneBackend
from sigma.pipelines.sysmon import sysmon_pipeline
from sigma.pipelines.elasticsearch.windows import ecs_windows
from sigma.collection import SigmaCollection
from sigma.processing.resolver import ProcessingPipelineResolver
# Create our pipeline resolver
piperesolver = ProcessingPipelineResolver()
# Add wanted pipelines
piperesolver.add_pipeline_class(ecs_windows())
piperesolver.add_pipeline_class(sysmon_pipeline())
# Create a single sorted and prioritzed pipeline
resolved_pipeline = piperesolver.resolve(piperesolver.pipelines)
# Instantiate backend, using our resolved pipeline
# and some backend parameter
backend = OpensearchLuceneBackend(resolved_pipeline, index_names=['logs-*-*', 'beats-*'], monitor_interval=10, monitor_interval_unit="MINUTES")
rules = SigmaCollection.from_yaml("""
title: Run Whoami Showing Privileges
id: 97a80ec7-0e2f-4d05-9ef4-65760e634f6b
status: experimental
description: Detects a whoami.exe executed with the /priv command line flag instructing the tool to show all current user privieleges. This is often used after a privilege escalation attempt.
references:
- https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/whoami
author: Florian Roth
date: 2021/05/05
modified: 2022/05/13
tags:
- attack.privilege_escalation
- attack.discovery
- attack.t1033
logsource:
category: process_creation
product: windows
detection:
selection_img:
- Image|endswith: '\whoami.exe'
- OriginalFileName: 'whoami.exe'
selection_cli:
CommandLine|contains: '/priv'
condition: all of selection*
falsepositives:
- Administrative activity (rare lookups on current privileges)
level: high
""")
# Print converted rule in Lucene syntax
print("Lucene Result: \n" + "\n".join(backend.convert(rules)))
# Print converted rule ready for dsl syntax
print("DSL Result: \n" + json.dumps(backend.convert(rules, output_format="dsl_lucene")[0], indent=2))
# Generate a JSON structure to be imported as monitor rule
print("Monitor Rule Result: \n" + backend.convert(rules, output_format="monitor_rule"))
Lucene Result:
winlog.channel:Microsoft\-Windows\-Sysmon\/Operational AND (event.code:1 AND ((process.executable:*\\whoami.exe OR process.pe.original_file_name:whoami.exe) AND process.command_line:*\/priv*))
DSL Result:
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "winlog.channel:Microsoft\\-Windows\\-Sysmon\\/Operational AND (event.code:1 AND (winlog.channel:Microsoft\\-Windows\\-Sysmon\\/Operational AND (event.code:1 AND ((process.executable:*\\\\whoami.exe OR process.pe.original_file_name:whoami.exe) AND process.command_line:*\\/priv*))))",
"analyze_wildcard": true
}
}
]
}
}
}
Monitor Rule Result:
{
"type": "monitor",
"name": "SIGMA - Run Whoami Showing Privileges",
"description": "Detects a whoami.exe executed with the /priv command line flag instructing the tool to show all current user privieleges. This is often used after a privilege escalation attempt.",
"enabled": true,
"schedule": {
"period": {
"interval": 10,
"unit": "MINUTES"
}
},
"inputs": [
{
"search": {
"indices": [
"logs-*-*",
"beats-*"
],
"query": {
"size": 1,
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "winlog.channel:Microsoft\\-Windows\\-Sysmon\\/Operational AND (event.code:1 AND (winlog.channel:Microsoft\\-Windows\\-Sysmon\\/Operational AND (event.code:1 AND (winlog.channel:Microsoft\\-Windows\\-Sysmon\\/Operational AND (event.code:1 AND ((process.executable:*\\\\whoami.exe OR process.pe.original_file_name:whoami.exe) AND process.command_line:*\\/priv*))))))",
"analyze_wildcard": true
}
}
]
}
}
}
}
}
],
"tags": [
"attack-privilege_escalation",
"attack-discovery",
"attack-t1033"
],
"triggers": [
{
"name": "generated-trigger",
"severity": 2,
"condition": {
"script": {
"source": "ctx.results[0].hits.total.value > 0",
"lang": "painless"
}
},
"actions": []
}
],
"sigma_meta_data": {
"rule_id": "97a80ec7-0e2f-4d05-9ef4-65760e634f6b",
"threat": []
},
"references": [
"https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/whoami"
]
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pysigma_backend_opensearch-2.0.0.tar.gz.
File metadata
- Download URL: pysigma_backend_opensearch-2.0.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16f1d8671b9e7d9c5db4d11e9d4460286cc9517cea81a0222577862733be0a6c
|
|
| MD5 |
34894cdaf6f7e54cba898fa50691cadf
|
|
| BLAKE2b-256 |
6086800669fc6f2c1cb4ac4311dfa5751019add77b4553b5ec23ce1ae762288c
|
Provenance
The following attestation bundles were made for pysigma_backend_opensearch-2.0.0.tar.gz:
Publisher:
release.yml on SigmaHQ/pySigma-backend-opensearch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysigma_backend_opensearch-2.0.0.tar.gz -
Subject digest:
16f1d8671b9e7d9c5db4d11e9d4460286cc9517cea81a0222577862733be0a6c - Sigstore transparency entry: 735365574
- Sigstore integration time:
-
Permalink:
SigmaHQ/pySigma-backend-opensearch@7ee4edd9d8715dc69d166fb57273b2fa5b79db55 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/SigmaHQ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7ee4edd9d8715dc69d166fb57273b2fa5b79db55 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pysigma_backend_opensearch-2.0.0-py3-none-any.whl.
File metadata
- Download URL: pysigma_backend_opensearch-2.0.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32e4f65d1318a1f9c3414936d6b47e08822694b3c6cb04dfdda130b8fdc68bf3
|
|
| MD5 |
2f6ee990624e0384b9e515da2441ba11
|
|
| BLAKE2b-256 |
97d148b63e139ac2fc3245a21bce22df72020510f882858aec952f746d22d0b2
|
Provenance
The following attestation bundles were made for pysigma_backend_opensearch-2.0.0-py3-none-any.whl:
Publisher:
release.yml on SigmaHQ/pySigma-backend-opensearch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysigma_backend_opensearch-2.0.0-py3-none-any.whl -
Subject digest:
32e4f65d1318a1f9c3414936d6b47e08822694b3c6cb04dfdda130b8fdc68bf3 - Sigstore transparency entry: 735365576
- Sigstore integration time:
-
Permalink:
SigmaHQ/pySigma-backend-opensearch@7ee4edd9d8715dc69d166fb57273b2fa5b79db55 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/SigmaHQ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7ee4edd9d8715dc69d166fb57273b2fa5b79db55 -
Trigger Event:
release
-
Statement type: