Skip to content

Conversation

terrancedejesus
Copy link
Contributor

@terrancedejesus terrancedejesus commented Dec 19, 2024

Pull Request

Issue link(s):

Summary - What I changed

Adjusted the from and interval times for rules per @approksiu.

How To Test

Queries were adjusted for format, but no logic changes.

Checklist

  • Added a label for the type of pr: bug, enhancement, schema, maintenance, Rule: New, Rule: Deprecation, Rule: Tuning, Hunt: New, or Hunt: Tuning so guidelines can be generated
  • Added the meta:rapid-merge label if planning to merge within 24 hours
  • Secret and sensitive material has been managed correctly
  • Automated testing was updated or added to match the most common scenarios
  • Documentation and comments were added for features that require explanation

Contributor checklist

@terrancedejesus terrancedejesus added the Rule: Tuning tweaking or tuning an existing rule label Dec 19, 2024
@protectionsmachine
Copy link
Collaborator

Rule: Tuning - Guidelines

These guidelines serve as a reminder set of considerations when tuning an existing rule.

Documentation and Context

  • Detailed description of the suggested changes.
  • Provide example JSON data or screenshots.
  • Provide evidence of reducing benign events mistakenly identified as threats (False Positives).
  • Provide evidence of enhancing detection of true threats that were previously missed (False Negatives).
  • Provide evidence of optimizing resource consumption and execution time of detection rules (Performance).
  • Provide evidence of specific environment factors influencing customized rule tuning (Contextual Tuning).
  • Provide evidence of improvements made by modifying sensitivity by changing alert triggering thresholds (Threshold Adjustments).
  • Provide evidence of refining rules to better detect deviations from typical behavior (Behavioral Tuning).
  • Provide evidence of improvements of adjusting rules based on time-based patterns (Temporal Tuning).
  • Provide reasoning of adjusting priority or severity levels of alerts (Severity Tuning).
  • Provide evidence of improving quality integrity of our data used by detection rules (Data Quality).
  • Ensure the tuning includes necessary updates to the release documentation and versioning.

Rule Metadata Checks

  • updated_date matches the date of tuning PR merged.
  • min_stack_version should support the widest stack versions.
  • name and description should be descriptive and not include typos.
  • query should be inclusive, not overly exclusive. Review to ensure the original intent of the rule is maintained.

Testing and Validation

  • Validate that the tuned rule's performance is satisfactory and does not negatively impact the stack.
  • Ensure that the tuned rule has a low false positive rate.
@Mikaayenson
Copy link
Contributor

Mikaayenson commented Dec 19, 2024

@terrancedejesus With some simple logic, there are a few identified:

Details

from detection_rules.rule_loader import RuleCollection from detection_rules.utils import convert_time_span rules = RuleCollection.default() def convert_relative_delta(lookback: str) -> int: now = len("now") min_length = now + len('+5m') if lookback.startswith("now") and len(lookback) >= min_length: lookback = lookback[len("now"):] sign = lookback[0] # + or - span = lookback[1:] amount = convert_time_span(span) return amount * (-1 if sign == "-" else 1) else: return convert_time_span(lookback) for rule in rules.rules: to = convert_relative_delta(rule.contents.data.to) if rule.contents.data.to else 0 from_ = convert_relative_delta(rule.contents.data.from_ or "now-6m") interval = convert_time_span(rule.contents.data.interval or "5m") if to - from_ <= interval: print(f"{rule.name} - {rule.id}")

My First Rule - a198fbbd-9413-45ec-a269-47ae4ccf59ce Rapid Secret Retrieval Attempts from AWS SecretsManager - 185c782e-f86a-11ee-9d9f-f661ea17fbce Multiple Okta Sessions Detected for a Single User - 621e92b6-7e54-11ee-bdc0-f661ea17fbcd Query Registry using Built-in Tools - ded09d02-0137-4ccc-8005-c45e617e8d4c

Can you go ahead and fix the others?

FWIW, we could probably turn the code into a unit test. Starting in 8.18, when rules customization is released, the issue where this surfaces should be fixed by elastic/kibana#204317 .

@botelastic botelastic bot added the bbr Building Block Rules label Dec 19, 2024
"This rule is not looking for threat activity. Disable the rule if you're already familiar with alerts.",
]
from = "now-30m"
from = "now-1h"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@approksiu @Mikaayenson - If we want this different just let me know.

terrancedejesus and others added 2 commits December 19, 2024 10:57
Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com>
…_single_user.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com>
@terrancedejesus terrancedejesus merged commit dad008e into main Dec 19, 2024
9 checks passed
@terrancedejesus terrancedejesus deleted the rule-tuning-okta-multiple-sessions-for-single-user branch December 19, 2024 18:03
protectionsmachine pushed a commit that referenced this pull request Dec 19, 2024
…trieval Rules (#4324) * rule tuning Okta and AWS lookback times * adjusted Query Registry using Built-in Tools * adjusted My First Rule * Update rules/cross-platform/guided_onboarding_sample_rule.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> * Update rules/integrations/okta/lateral_movement_multiple_sessions_for_single_user.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> --------- Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> Removed changes from: - rules/integrations/okta/lateral_movement_multiple_sessions_for_single_user.toml (selectively cherry picked from commit dad008e)
protectionsmachine pushed a commit that referenced this pull request Dec 19, 2024
…trieval Rules (#4324) * rule tuning Okta and AWS lookback times * adjusted Query Registry using Built-in Tools * adjusted My First Rule * Update rules/cross-platform/guided_onboarding_sample_rule.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> * Update rules/integrations/okta/lateral_movement_multiple_sessions_for_single_user.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> --------- Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> Removed changes from: - rules/integrations/okta/lateral_movement_multiple_sessions_for_single_user.toml (selectively cherry picked from commit dad008e)
protectionsmachine pushed a commit that referenced this pull request Dec 19, 2024
…trieval Rules (#4324) * rule tuning Okta and AWS lookback times * adjusted Query Registry using Built-in Tools * adjusted My First Rule * Update rules/cross-platform/guided_onboarding_sample_rule.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> * Update rules/integrations/okta/lateral_movement_multiple_sessions_for_single_user.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> --------- Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> Removed changes from: - rules/integrations/okta/lateral_movement_multiple_sessions_for_single_user.toml (selectively cherry picked from commit dad008e)
protectionsmachine pushed a commit that referenced this pull request Dec 19, 2024
…trieval Rules (#4324) * rule tuning Okta and AWS lookback times * adjusted Query Registry using Built-in Tools * adjusted My First Rule * Update rules/cross-platform/guided_onboarding_sample_rule.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> * Update rules/integrations/okta/lateral_movement_multiple_sessions_for_single_user.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> --------- Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> (cherry picked from commit dad008e)
protectionsmachine pushed a commit that referenced this pull request Dec 19, 2024
…trieval Rules (#4324) * rule tuning Okta and AWS lookback times * adjusted Query Registry using Built-in Tools * adjusted My First Rule * Update rules/cross-platform/guided_onboarding_sample_rule.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> * Update rules/integrations/okta/lateral_movement_multiple_sessions_for_single_user.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> --------- Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> (cherry picked from commit dad008e)
protectionsmachine pushed a commit that referenced this pull request Dec 19, 2024
…trieval Rules (#4324) * rule tuning Okta and AWS lookback times * adjusted Query Registry using Built-in Tools * adjusted My First Rule * Update rules/cross-platform/guided_onboarding_sample_rule.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> * Update rules/integrations/okta/lateral_movement_multiple_sessions_for_single_user.toml Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> --------- Co-authored-by: Mika Ayenson <Mikaayenson@users.noreply.github.com> (cherry picked from commit dad008e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport: auto bbr Building Block Rules Domain: Cloud Workloads Integration: AWS AWS related rules Integration: Okta okta related rules Rule: Tuning tweaking or tuning an existing rule

4 participants