Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loki does not handle condition lists in the manner other backends do #72

Closed
jamesc-grafana opened this issue Jun 27, 2023 · 2 comments · Fixed by #98
Closed

Loki does not handle condition lists in the manner other backends do #72

jamesc-grafana opened this issue Jun 27, 2023 · 2 comments · Fixed by #98
Assignees
Labels
bug Something isn't working querying

Comments

@jamesc-grafana
Copy link
Collaborator

Within the Sigma specification, conditions can be both a string or a list of string which is fine.

However, pySigma-backend-loki does not exhibit consistent behaviour with other backends breaking out a list of strings into multiple queries, instead pysigma-backend-loki creates multiple queries but groups all of the query terms into the first query.

Taking this Sigma Rule for example:

title: Title
id: 8bcaaeff-3fe4-4793-9fcc-9a61acec6290
description: Short Description
author: Your Name
date: 2023/06/27
logsource:
    category: application
detection:
    selection:
        - Detection Rule
    keywords:
        - Word1
        - Word2
    others:
        - Test
    condition: 
      - selection
      - keywords
      - others

With a Splunk SPL backend we get the following result:

"Detection Rule"

"Word1" OR "Word2"

"Test"

Whilst the Loki backend produces the following queries

{job=~".+"} |= `Detection Rule` |~ `Word1|Word2` |= `Test`

{job=~".+"} 

{job=~".+"} 
@jamesc-grafana jamesc-grafana added bug Something isn't working querying labels Jun 27, 2023
@jamesc-grafana
Copy link
Collaborator Author

This appears to be to do with the handling of lists within the backend as a dict will work as expected. The issue is likely that the lists are being pulled up to the top query rather than residing in their own query.

The below snippets support this theory

detection:
  sel1:
    fieldA: valueA
  sel2:
    - valueB
  sel3:
    - valueC
  sel4:
    fieldD: valueD
  condition:
    - sel1
    - sel2
    - sel3
    - sel4

Yields

{job=~".+"} |~ `(?i)valueB` |~ `(?i)valueC` | logfmt | fieldA=~`(?i)valueA`
{job=~".+"} 
{job=~".+"}
{job=~".+"} | logfmt | fieldD=~`(?i)valueD`

@kelnage
Copy link
Collaborator

kelnage commented Jun 27, 2023

Turns out it was an upstream issue! But the backend will need to be updated to incorporate the upstream fix anyway.

@kelnage kelnage self-assigned this Sep 5, 2023
kelnage added a commit that referenced this issue Oct 20, 2023
Applies fixes from SigmaHQ/pySigma#127 to resolve the issue that a list of conditions in a single rule would all share the same state.

Closes: #72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working querying
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants