forked from elastic/detection-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate detection rule to alert on traffic to typosquatting/homonym …
…domains (elastic#1199) * create new cli commands * add kibana object to create_dnstwist_rule * Adding code for index-dnstwist-results * Changed es to es_client * Tested. it works! * flake8-ed * Adding timestamps * use eql.utils.load_dump to load json file * rename data to dnstwist_data * start working on create-dnstwist-rule command * add print statements for user * tweak formatting for line length * add template threat match rule file * continue working on threat match rule creation * create rule using TomlRuleContents * save rule to toml file * Moving rule creation to eswrap.py * Moving create dnstwist rule stuff to eswrap * Fixed imports * flake8 fixes * More flake8 fixes * fix usage of @add_client('kibana') * use ctx.invoke to upload rule * cleanup record assembly and use bulk api * swap order of notes in `note` for sample rule * small modifications * move command to root click group * remove unused click group * Update detection_rules/main.py Co-authored-by: Justin Ibarra <[email protected]> * remove rule upload and convert template to ndjson * Adding docs for typosquatting rule * renaming the file * Adding a note * separate index and rule prep commands * Final changes Co-authored-by: Apoorva <[email protected]> Co-authored-by: brokensound77 <[email protected]> Co-authored-by: Apoorva Joshi <[email protected]>
- Loading branch information
1 parent
c9d6527
commit 90aa65a
Showing
6 changed files
with
232 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Generating detection rule to alert on traffic to typosquatting or homonym domains | ||
|
||
## What does the rule do? | ||
|
||
This rule helps detect spoofing attacks on domains that you want to protect. | ||
|
||
|
||
## Steps | ||
|
||
### 1. Run [dnstwist](https://github.com/elceef/dnstwist) on the domain you want to watch | ||
|
||
Eg: `dnstwist --format json elastic.co | jq` | ||
|
||
This should give you a json file consisting of potentially malicious lookalike domains for your domain. | ||
|
||
### 2. Index the lookalike domains into Elasticsearch | ||
|
||
In order to detect network activity on the lookalike domains using a threat match rule, you would first need to index these domains into an Elasticsearch index using the following CLI command: | ||
|
||
`python -m detection_rules typosquat create-dnstwist-index [OPTIONS] INPUT_FILE` | ||
|
||
### 3. Prep rule to alert on generated indexes | ||
|
||
Run the following CLI command to generate the typosquat rule file, which you will then import into Kibana. | ||
|
||
`python -m detection_rules typosquat prep-rule [OPTIONS] AUTHOR` | ||
|
||
|
||
### 4. Import the rule into Kibana | ||
|
||
Import the ndjson rule file generated in the previous step, into Kibana, via the Detection rules UI. | ||
|
||
### 5. Detect potentially malicious network activity targeting your organization! | ||
|
||
|
||
## Note | ||
|
||
You DO NOT need to re-import the rule file each time you have an additional domain to track. For each new domain, you'd run Step 1 to generate the json file consisting of lookalike domains for that domain, followed by the CLI command in Step 2 to index these domains into a new index. This index will automatically be picked up by the rule you imported the very first time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"author": ["THIS WILL BE POPULATED BY create-dnstwist-index COMMAND"], | ||
"description": "This rule is triggered when a DNS request is made for a domain in the list of typosquatting domains generated by\ndnstwist. Adversaries may register homonym or homoglyph domains for the organization that they're targeting before\nsending a phishing lure to a user in an attempt to infect their endpoint with malware or steal credentials.\n", | ||
"from": "now-10m", | ||
"index": [ | ||
"packetbeat-*", | ||
"winlogbeat-*" | ||
], | ||
"interval": "9m", | ||
"language": "kuery", | ||
"license": "Elastic License v2", | ||
"name": "DNS Request for Typosquatting Domain", | ||
"note": "## Config\n\n- Packetbeat or Winlogbeat must be configured to log DNS request events to be compatible with this rule.\n\n\n## Triage and Analysis\n\n- Determine the reason that the DNS request was made by the affected endpoint. For example, did the user visit the domain\nafter receiving a phishing email or did they mistype one of the organization's registered domains?\n- Take appropriate security measures when investigating the domain in question, as it may host malware or an attacker\nmay be monitoring for potential victims visiting the domain. For example, Use open source intelligence such as the\nWHOIS domain database to obtain information about the domain or interact with it using a malware sandbox service that\nis segmented from any of your production systems.\n", | ||
"query": "dns.question.registered_domain:*\n", | ||
"references": [], | ||
"risk_score": 73, | ||
"rule_id": "THIS WILL BE POPULATED BY create-dnstwist-index COMMAND", | ||
"severity": "high", | ||
"tags": [ | ||
"Elastic", | ||
"Network", | ||
"Windows", | ||
"Continuous Monitoring", | ||
"SecOps", | ||
"Monitoring" | ||
], | ||
"threat_index": [ | ||
"dnstwist-*" | ||
], | ||
"threat_indicator_path": "", | ||
"threat_language": "kuery", | ||
"threat_mapping": [ | ||
{ | ||
"entries": [ | ||
{ | ||
"field": "dns.question.registered_domain", | ||
"type": "mapping", | ||
"value": "dns.question.registered_domain" | ||
} | ||
] | ||
} | ||
], | ||
"threat_query": "dns.question.registered_domain:*", | ||
"timeline_id": "495ad7a7-316e-4544-8a0f-9c098daee76e", | ||
"timeline_title": "Generic Threat Match Timeline", | ||
"type": "threat_match" | ||
} |