-
Notifications
You must be signed in to change notification settings - Fork 502
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
[DaC] [FR] End to end testing and feedback improvements #3949
Conversation
Enhancement - GuidelinesThese guidelines serve as a reminder set of considerations when addressing adding a feature to the code. Documentation and Context
Code Standards and Practices
Testing
Additional Checks
|
if threat_query: | ||
formatted_threat_query = "\nthreat_query = '''\n{}\n'''{}".format(threat_query, '\n\n' if bottom else '') | ||
top = top.replace('threat_query = "XXxXX"', formatted_threat_query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an example for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, a rule without this formatting will appear like this, invalid toml string:
threat_query = '@timestamp >= "now-24h"
'
with the formatting it will appear like this:
threat_query = '''
@timestamp >= "now-24h"
'''
Example Rule File
[metadata]
creation_date = "2024/08/02"
maturity = "development"
updated_date = "2024/08/02"
[rule]
author = ["INFOSEC_TEST"]
description = "Test Threat Query"
enabled = true
from = "now-5400s"
index = ["logs-okta*"]
interval = "1h"
language = "kuery"
max_signals = 100
name = "Test User Threat Query"
note = "Test threat query."
references = ["https://github.com/elastic"]
revision = 28
risk_score = 73
rule_id = "58be7d5b-f8bf-4666-83c6-251ceefea562"
severity = "high"
tags = ["Okta"]
threat_index = ["test_cluster:okta_users"]
threat_indicator_path = "threat.indicator"
threat_language = "kuery"
timestamp_override = "event.ingested"
to = "now"
type = "threat_match"
version = 24
query = '''
user.email:*
'''
threat_query = '''
@timestamp >= "now-24h"
'''
[[rule.required_fields]]
ecs = true
name = "user.email"
type = "keyword"
[[rule.threat_mapping]]
[[rule.threat_mapping.entries]]
field = "user.email"
type = "mapping"
value = "user.email"
* [New Rule] AWS IAM CompromisedKeyQuarantine Policy Attached to User (#3910) * [New Rule] AWS IAM CompromisedKeyQuarantine Policy Attached to User * increased severity score Co-authored-by: Ruben Groenewoud <78494512 [email protected]> --------- Co-authored-by: Ruben Groenewoud <78494512 [email protected]> * [Rule Tuning] System Binary Moved or Copied (#3933) * [Rule Tuning] Sensitive Registry Hive Access via RegBack (#3947) Co-authored-by: Mika Ayenson <[email protected]> * [New Rule] Potential Relay Attack against a Domain Controller (#3928) * [New Rule] Potential Relay Attack against a Domain Controller * Update credential_access_dollar_account_relay.toml * Move to the correct folder * [Rule Tuning] AWS S3 Object Versioning Suspended (#3953) * [Tuning] Executable Bit Set for Potential Persistence Script (#3929) * [Rule Tuning] Microsoft IIS Service Account Password Dumped (#3935) * [Rule Tuning] Accepted Default Telnet Port Connection (#3954) Co-authored-by: Mika Ayenson <[email protected]> * ndjson support for action connectors * Add kibana API support for actions * Minor typo * Add actions connector support * update rule formatter * Fix typo * [New Rule] Outlook Home Page Registry Modification (#3946) * Fix typos * Update docs and generated config * Update all_versions * Fix comments --------- Co-authored-by: Isai <59296946 [email protected]> Co-authored-by: Ruben Groenewoud <78494512 [email protected]> Co-authored-by: Jonhnathan <26856693 [email protected]> Co-authored-by: Mika Ayenson <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number of other minor fixes/updates definitely helps clean up a bunch of issues/gaps/assumptions.
Walkthrough code review final testing together looks good. 🚀
Pull Request
Issue link(s):
Summary - What I changed
Please merge #3955 into this PR before merging to main
This PR adds the ability to specify a config variable to auto generate a custom schema file for any missing non-ecs fields. To trigger this behavior add the following line to your
_config.yaml
I addition, there are a number of other minor fixes/updates to the
import-rules-to-repo
process including:--require-only
behavior in import-rules-to-repo to populate all fields but only prompt for required ones.extract_error_field
function to handle non alpha-numeric characters.rule.actions.frequency.throttle
field, required in Kibana._add_known_nulls
function to handle null fields in TOML files.extract_error_field
function related to quotes around the field value.all_versions
function.How To Test
Autogen Custom Schema
To test this, first add the appropriate config variable. Next, run view-rule on a rule that has fields that are not currently present in a schema. The rule should validate successfully and your schema file should be updated.
Example:
python -m detection_rules view-rule custom_rules/rules/dac_demo_dev_rule_1.toml
Details
This will occur in any command where rule contents are validated against a schema, including
import-rules-to-repo
,kibana export-rules
and others.Additionally added, is the
--skip-errors
flag toimport-rules-to-repo
to follow similar functionality from this same flag for thekibana export-rules
command. With this flag one should expect output similar to the following when importing rules.Also, rule names will no longer be validated against our naming conversions for custom rules. Any valid string name will now validate.
Testing support for a required field
rule.actions.frequency.throttle
Use the following example rule file to import from ndjson and export back to a kibana instance. You will get a
connector id is missing error
but this is expected and as far of an implmentation of actions as this PR expects. If the desired result is not working you would see a throttle error instead.test_action_export.ndjson.txt
Example Rule
Note you may have to download this to watch the example, needed it to be mp4 due to length and not sure how well github renders mp4.
test_action_gif.mp4
Checklist
bug
,enhancement
,schema
,Rule: New
,Rule: Deprecation
,Rule: Tuning
,Hunt: New
, orHunt: Tuning
so guidelines can be generatedmeta:rapid-merge
label if planning to merge within 24 hoursContributor checklist