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

FR] Add Core Support for ES|QL Rule Type #3292

Merged
merged 3 commits into from
Nov 28, 2023
Merged

FR] Add Core Support for ES|QL Rule Type #3292

merged 3 commits into from
Nov 28, 2023

Conversation

Mikaayenson
Copy link
Contributor

@Mikaayenson Mikaayenson commented Nov 28, 2023

Issues

https://github.com/elastic/ia-trade-team/issues/163

Summary

  • Adds support for the ES|QL Rule type based on the kibana implementation
  • Adds base stub classes to validate esql rules

Testing

  1. Unit tests should pass with the sample esql rule locally.
  2. Manual testing with CLI commands.
Sample Rule

Use the following rule, and run view-rule command to ensure the esql rule loads successfully, skipping validation.

[metadata]
creation_date = "2023/02/27"
integration = ["endpoint"]
maturity = "production"
min_stack_comments = "New fields added: required_fields, related_integrations, setup"
min_stack_version = "8.11.0"
updated_date = "2023/06/22"

[rule]
author = ["Elastic"]
description = """
Identifies the execution of the unshadow utility which is part of John the Ripper,
a password-cracking tool on the host machine. Malicious actors can use the utility to retrieve
the combined contents of the '/etc/shadow' and '/etc/password' files.
Using the combined file generated from the utility, the malicious threat actors can use them as input
for password-cracking utilities or prepare themselves for future operations by gathering
credential information of the victim.
"""
from = "now-9m"
language = "esql"
license = "Elastic License v2"
name = "ESQL Potential Linux Credential Dumping via Unshadow"
references = [
    "https://www.cyberciti.biz/faq/unix-linux-password-cracking-john-the-ripper/",
]
risk_score = 47
rule_id = "77af47d0-5bd4-11ee-8f6d-f661ea17fbce"
severity = "medium"
tags = ["Data Source: Elastic Endgame", "Domain: Endpoint", "OS: Linux", "Use Case: Threat Detection", "Tactic: Credential Access", "Data Source: Elastic Defend"]
timestamp_override = "event.ingested"
type = "esql"
query = '''
from logs-endpoint.events.*, logs-endpoint.events.process*
    | keep host.os.type, process.name, process.working_directory, event.type, event.action
    | where host.os.type == "linux" and process.name == "unshadow" and event.type == "start" and event.action in ("exec", "exec_event")
'''


[[rule.threat]]
framework = "MITRE ATT&CK"
[[rule.threat.technique]]
id = "T1003"
name = "OS Credential Dumping"
reference = "https://attack.mitre.org/techniques/T1003/"
[[rule.threat.technique.subtechnique]]
id = "T1003.008"
name = "/etc/passwd and /etc/shadow"
reference = "https://attack.mitre.org/techniques/T1003/008/"



[rule.threat.tactic]
id = "TA0006"
name = "Credential Access"
reference = "https://attack.mitre.org/tactics/TA0006/"

CLI Testing Commands

python -m detection_rules view-rule /Users/stryker/workspace/Elastic/detection
-rules/rules/linux/credential_access_credential_dumping_via_unshadow.toml --api-format 

Or run:

python -m detection_rules validate-rule /Users/stryker/workspace/Elastic/detection
-rules/rules/linux/credential_access_credential_dumping_via_unshadow.toml

Output should look similar to the following:

Loaded config file: /Users/stryker/workspace/Elastic/detection-rules/.detection-rules-cfg.json

█▀▀▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄   ▄      █▀▀▄ ▄  ▄ ▄   ▄▄▄ ▄▄▄
█  █ █▄▄  █  █▄▄ █    █   █  █ █ █▀▄ █      █▄▄▀ █  █ █   █▄▄ █▄▄
█▄▄▀ █▄▄  █  █▄▄ █▄▄  █  ▄█▄ █▄█ █ ▀▄█      █ ▀▄ █▄▄█ █▄▄ █▄▄ ▄▄█

{
  "author": [
    "Elastic"
  ],
  "description": "Identifies the execution of the unshadow utility which is part of John the Ripper, a password-cracking tool on the host machine. Malicious actors can use the utility to retrieve the combined contents of the '/etc/shadow' and '/etc/password' files. Using the combined file generated from the utility, the malicious threat actors can use them as input for password-cracking utilities or prepare themselves for future operations by gathering credential information of the victim.",
  "from": "now-9m",
  "language": "esql",
  "license": "Elastic License v2",
  "name": "ESQL Potential Linux Credential Dumping via Unshadow",
  "query": "from logs-endpoint.events.*, logs-endpoint.events.process*\n    | keep host.os.type, process.name, process.working_directory, event.type, event.action\n    | where host.os.type == \"linux\" and process.name == \"unshadow\" and event.type == \"start\" and event.action in (\"exec\", \"exec_event\")\n",
  "references": [
    "https://www.cyberciti.biz/faq/unix-linux-password-cracking-john-the-ripper/"
  ],
  "risk_score": 47,
  "rule_id": "77af47d0-5bd4-11ee-8f6d-f661ea17fbce",
  "severity": "medium",
  "tags": [
    "Data Source: Elastic Endgame",
    "Domain: Endpoint",
    "OS: Linux",
    "Use Case: Threat Detection",
    "Tactic: Credential Access",
    "Data Source: Elastic Defend"
  ],
  "threat": [
    {
      "framework": "MITRE ATT&CK",
      "tactic": {
        "id": "TA0006",
        "name": "Credential Access",
        "reference": "https://attack.mitre.org/tactics/TA0006/"
      },
      "technique": [
        {
          "id": "T1003",
          "name": "OS Credential Dumping",
          "reference": "https://attack.mitre.org/techniques/T1003/",
          "subtechnique": [
            {
              "id": "T1003.008",
              "name": "/etc/passwd and /etc/shadow",
              "reference": "https://attack.mitre.org/techniques/T1003/008/"
            }
          ]
        }
      ]
    }
  ],
  "timestamp_override": "event.ingested",
  "type": "esql",
  "version": 1
}

Additional Information

  • ESQL query validation is not available with this PR. A warning is provided to the user notifying them for each ESQL rule.
  • In the interim, users can read our Blog for more details on ES|QL validation.

@Mikaayenson Mikaayenson added enhancement New feature or request python Internal python for the repository Area: DED esql ES|QL labels Nov 28, 2023
@Mikaayenson Mikaayenson self-assigned this Nov 28, 2023
@botelastic botelastic bot added the schema label Nov 28, 2023
Copy link
Contributor

@terrancedejesus terrancedejesus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for base ES|QL rule support.

datasets.update(set(n.value for n in node if isinstance(n, eql.ast.Literal)))
elif isinstance(node, FieldComparison) and str(node.field) == 'event.dataset':
datasets.update(set(str(n) for n in node if isinstance(n, kql.ast.Value)))
if data.type != "esql":
Copy link
Contributor

@eric-forte-elastic eric-forte-elastic Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if data.type != "esql":
if getattr(data, 'type', '') != "esql":

Maybe we should use .get in the event that the type is not set? It looks like we do that in our other checks here.

@Mikaayenson Mikaayenson merged commit bc39c20 into main Nov 28, 2023
12 checks passed
@Mikaayenson Mikaayenson deleted the esql_core branch November 28, 2023 19:03
protectionsmachine pushed a commit that referenced this pull request Nov 28, 2023
protectionsmachine pushed a commit that referenced this pull request Nov 28, 2023
protectionsmachine pushed a commit that referenced this pull request Nov 28, 2023
protectionsmachine pushed a commit that referenced this pull request Nov 28, 2023
protectionsmachine pushed a commit that referenced this pull request Nov 28, 2023
protectionsmachine pushed a commit that referenced this pull request Nov 28, 2023
protectionsmachine pushed a commit that referenced this pull request Nov 28, 2023
protectionsmachine pushed a commit that referenced this pull request Nov 28, 2023
protectionsmachine pushed a commit that referenced this pull request Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport: auto enhancement New feature or request esql ES|QL python Internal python for the repository schema
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants