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

[RFC] Threat Enrichment - Stage 1 #1400

Merged
merged 17 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 143 additions & 11 deletions rfcs/text/0021-threat-enrichment.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# 0021: Threat Enrichment
<!-- Leave this ID at 0000. The ECS team will assign a unique, contiguous RFC number upon merging the initial stage of this RFC. -->

- Stage: **0 (strawperson)** <!-- Update to reflect target stage. See https://elastic.github.io/ecs/stages.html -->
- Date: **2021-05-03** <!-- The ECS team sets this date at merge time. This is the date of the latest stage advancement. -->

<!--
As you work on your RFC, use the "Stage N" comments to guide you in what you should focus on, for the stage you're targeting.
Feel free to remove these comments as you go along.
-->
- Stage: **1 (draft)** <!-- Update to reflect target stage. See https://elastic.github.io/ecs/stages.html -->
- Date: **2021-06-10** <!-- The ECS team sets this date at merge time. This is the date of the latest stage advancement. -->

<!--
Stage 0: Provide a high level summary of the premise of these changes. Briefly describe the nature, purpose, and impact of the changes. ~2-5 sentences.
Expand All @@ -16,8 +10,9 @@ Stage 0: Provide a high level summary of the premise of these changes. Briefly d
As [documented](https://github.com/elastic/ecs/pull/1293#issuecomment-825212880) in the [existing threat intel RFC](https://github.com/elastic/ecs/pull/1293), this proposal aims to solve the threat intel enrichment use case by reusing the `threat.indicator` fieldset under a new name and as an array of objects, where each object represents an indicator that matched the (now enriched) event, and the `matched.*` fields on each object provide context for that particular indicator match.

Moving this list of indicators to a new field allows us to:
* reuse the existing `threat.indicator` fieldset
* sidestep the documentation/mapping complexities around when `threat.indicator` is an object (indicator) vs. when it's an array of objects (enrichment)

* reuse the existing `threat.indicator` fieldset
* sidestep the documentation/mapping complexities around when `threat.indicator` is an object (indicator) vs. when it's an array of objects (enrichment)

<!--
Stage 1: If the changes include field additions or modifications, please create a folder titled as the RFC number under rfcs/text/. This will be where proposed schema changes as standalone YAML files or extended example mappings and larger source documents will go as the RFC is iterated upon.
Expand All @@ -29,6 +24,22 @@ Stage 1: If the changes include field additions or modifications, please create
Stage 1: Describe at a high level how this change affects fields. Include new or updated yml field definitions for all of the essential fields in this draft. While not exhaustive, the fields documented here should be comprehensive enough to deeply evaluate the technical considerations of this change. The goal here is to validate the technical details for all essential fields and to provide a basis for adding experimental field definitions to the schema. Use GitHub code blocks with yml syntax formatting, and add them to the corresponding RFC folder.
-->

As these fields represent the enrichment of an existing event with indicator information, they are comprised of three categories of data:

1. The indicator's indicator fields, as defined in RFC 0018
2. Other relevant ECS fields from the indicator (see below)
3. Fields representing the context of the enrichment itself

### Proposed new fields

Field | Type | Example | Description
--- | --- | --- | ---
threat.enrichments.matched.atomic | keyword | 2f5207f2add28b46267dc99bc5382480 | The value that matched between the event and the indicator
threat.enrichments.matched.id | keyword | db8fb691ffdb4432a09ef171659c8993e6ddea1ea9b21381b93269d1bf2d0bc2 | The _id of the indicator document that matched the event
threat.enrichments.matched.index | keyword | threat-index-000001 | The _index of the indicator document that matched the event
threat.enrichments.matched.field | keyword | host.name | Identifies the field on the enriched event that matched the indicator
threat.enrichments.matched.type | keyword | indicator_match_rule | Identifies the type of the atomic indicator that matched a local environment endpoint or network event.

<!--
Stage 2: Add or update all remaining field definitions. The list should now be exhaustive. The goal here is to validate the technical details of all remaining fields and to provide a basis for releasing these field definitions as beta in the schema. Use GitHub code blocks with yml syntax formatting, and add them to the corresponding RFC folder.
-->
Expand All @@ -39,12 +50,128 @@ Stage 2: Add or update all remaining field definitions. The list should now be e
Stage 1: Describe at a high-level how these field changes will be used in practice. Real world examples are encouraged. The goal here is to understand how people would leverage these fields to gain insights or solve problems. ~1-3 paragraphs.
-->

### Adding threat intelligence match/enrichment to another document

If it is determined that an event matches a given indicator, that event can be enriched with said indicator. Presently, Indicator Match Detection rules will perform that enrichment automatically, but ad hoc/manual enrichment is an expected feature that analysts will leverage in the future.

#### Example document

```json5
{
"process": {
"name": "svchost.exe",
"pid": 1644,
"entity_id": "MDgyOWFiYTYtMzRkYi1kZTM2LTFkNDItMzBlYWM3NDVlOTgwLTE2NDQtMTMyNDk3MTA2OTcuNDc1OTExNTAw",
"executable": "C:\\Windows\\System32\\svchost.exe"
},
"message": "Endpoint file event",
"@timestamp": "2020-11-17T19:07:46.0956672Z",
"file": {
"path": "C:\\Windows\\Prefetch\\SVCHOST.EXE-AE7DB802.pf",
"extension": "pf",
"name": "SVCHOST.EXE-AE7DB802.pf",
"hash": {
"sha256": "0c415dd718e3b3728707d579cf8214f54c2942e964975a5f925e0b82fea644b4"
}
},
"threat": {
"enrichments": [
{
// Each enrichment is added as a nested object under `threat.enrichments.*`
// Copy all the object indicators under `indicator.*`, providing full context
"indicator": {
"marking": {
"tlp": "WHITE"
},
"first_seen": "2020-10-01",
"last_seen": "2020-11-01",
"sightings": 4,
"type": ["sha256", "md5", "file_name", "file_size"],
"description": "file last associated with delivering Angler EK"
},
// event and file fields are copied from the indicator doc, if relevant
"event": {
"provider": "Abuse.ch",
"dataset": "threatintel.abusemalware",
"module": "threatintel",
"reference": "https://system.example.com/event/#0001234"
},
"file": {
"hash": {
"sha256": "0c415dd718e3b3728707d579cf8214f54c2942e964975a5f925e0b82fea644b4",
"md5": "1eee2bf3f56d8abed72da2bc523e7431"
},
"size": 656896,
"name": "invoice.doc"
},
/* `matched` will provide context about which of the indicators above matched on this
particular enrichment. If multiple matches for this indicator object, this could
be a list */
"matched": {
"atomic": "0c415dd718e3b3728707d579cf8214f54c2942e964975a5f925e0b82fea644b4",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not convinced that matched.atomic and matched.field are sufficient to cover more sophisticated matching mechanisms than an exact match: if e.g. a user wanted to write an indicator match rule with a partial match, or if there were a more sophisticated indicator that itself represented a wildcard/regex value, then the value of the indicator would not be identical to the value from the event and so we may want two fields here.

Similarly, we would not be able to reproduce the exact conditions of the match with only one field value. While I've been told that the indicator field being matched upon should be self-evident, it seems safer to explicitly state it in another field, and I wanted to bring it up one more time before I shut up about it 😉 .

In general, I'm viewing these matched.* fields as the answer to both HOW and WHY a given event was enriched, so keep that in mind and/or correct me on that thinking.

Copy link
Contributor

Choose a reason for hiding this comment

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

a user wanted to write an indicator match rule with a partial match, or if there were a more sophisticated indicator that itself represented a wildcard/regex value, then the value of the indicator would not be identical to the value from the event

How are you envisioning this? Are you thinking that there is a mechanical way needed to match like fields. I can think of a use-case, DGAs.

So, if you know an aggressor uses a specific domain structure for C2 (like abc123\.12345abcdef\.xyz), you'd want to be able to match if they use

abc123\.12345abcdef\.xyz
plo958\.59874qwersd\.xyz
lje456\.01258iekduh\.xyz

So, you'd need a way to match url.full:/[aA-zZ]{3}[0-9]{3}\.[0-9]{5}[aA-zZ]{6}\.xyz MATCHES threat.indicator.url.full?

Or am I off?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@peasead right, the idea is that with anything other than an exact match, the values for the LHS and RHS of the match are going to be different, and we don't have fields to account for both of those right now.

IPs is another example, where one could specify a CIDR block instead of a single IP address.

What is SOP for DGAs within threat intel, currently? Is there any attempt to generalize the pattern/algorithm generating those values?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not saying it's a must now.

There are some experimental machine learning jobs for DGAs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can continue with the implicit "exact value match" semantics for this RFC. If in the future we need to support the aforementioned functionality, I think that we can do so with the addition of two new fields as discussed.

"field": "file.hash.sha256",
"id": "abc123f03",
"index": "threat-indicators-index-000001",
"type": "indicator_match_rule"
}
}
]
},
// Tag the enriched document to indicate the threat enrichment matched
"tags": ["threat-match"],
// This should already exist from the original ingest pipeline of the document
"related": {
"hash": ["0c415dd718e3b3728707d579cf8214f54c2942e964975a5f925e0b82fea644b4"]
}
}
```

### Proposed enrichment pipeline mechanics pseudocode
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dcode @peasead I know this section is out of date, but I had some trouble grokking and could use some help on this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dcode, @rylnd and I chatted about this, but may still need some specifics if you could provide those.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rylnd did you get the information you needed on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@peasead I think I finally grokked and updated that section appropriately. If you and @dcode can verify that what I wrote still makes sense, lemme know 👍


1. Original document completes its standard pipeline for the given source (i.e. filebeat module pipeline)
2. Original document is sent to "threat lookup" pipeline
3. For each indicator type, we perform the following (a file sha256 for example):
- if exists "file.hash.sha256":
- enrich processor:
"policy_name": "file-sha256-policy",
"field" : "file.hash.sha256",
"target_field": "threat_match",
"max_matches": "1"
- policy file-sha256-policy:
"match": {
"indices": "threat-\*",
"match_field": "file.hash.sha256",
"enrich_fields": ["event", "file", "indicator"]
}
- set:
field: "threat_match.matched.type"
value: "file-sha256-policy"
- set:
field: "threat_match.matched.field"
value: "file.hash.sha256"
- set:
field: "threat_match.matched.atomic"
value: "{{ file.hash.sha256 }}"
- set:
field: "threat.enrichments"
value: []
override: false
- append:
field: "threat.enrichments"
value: "{{ threat_match }}"
- remove:
field: "threat_match"

**NOTE**: There may be some optimization on which enrichments we attempt based upon the event categorization fields. For instance, we know that data that presents the netflow model or "interface" doesn't contain a sha256 hash. Since those categorization fields are lists, if data presented as both netflow and file (for whatever reason), then we'd check both network-related lookups and file-related lookups

## Source data

<!--
Stage 1: Provide a high-level description of example sources of data. This does not yet need to be a concrete example of a source document, but instead can simply describe a potential source (e.g. nginx access log). This will ultimately be fleshed out to include literal source examples in a future stage. The goal here is to identify practical sources for these fields in the real world. ~1-3 sentences or unordered list.
-->

Source data are ECS indicator documents as specified RFC 0008. At present, the best source of these documents is the [filebeat threatintel module](https://github.com/elastic/beats/tree/master/x-pack/filebeat/module/threatintel).

<!--
Stage 2: Included a real world example source document. Ideally this example comes from the source(s) identified in stage 1. If not, it should replace them. The goal here is to validate the utility of these field changes in the context of a real world example. Format with the source name as a ### header and the example document in a GitHub code block with json formatting, or if on the larger side, add them to the corresponding RFC folder.
-->
Expand All @@ -69,6 +196,10 @@ The goal here is to research and understand the impact of these changes on users
Stage 1: Identify potential concerns, implementation challenges, or complexity. Spend some time on this. Play devil's advocate. Try to identify the sort of non-obvious challenges that tend to surface later. The goal here is to surface risks early, allow everyone the time to work through them, and ultimately document resolution for posterity's sake.
-->

I believe this format should actually simplify much of the enrichment logic originally proposed in RFC 0008, since a naive implementation would simply copy the fields directly from each indicator document into `threat.enrichments`, and add the appropriate `matched` fields.

While not a concern for ECS consumers at large, our existing experimental implementation within Kibana Security Solution will have to change significantly (for the better!), with accompanying data migration: https://github.com/elastic/kibana/issues/100510

<!--
Stage 2: Document new concerns or resolutions to previously listed concerns. It's not critical that all concerns have resolutions at this point, but it would be helpful if resolutions were taking shape for the most significant concerns.
-->
Expand All @@ -82,6 +213,7 @@ Stage 3: Document resolutions for all existing concerns. Any new concerns should
The following are the people that consulted on the contents of this RFC.

* @rylnd | author
* @devonakerr | sponsor

<!--
Who will be or has been consulted on the contents of this RFC? Identify authorship and sponsorship, and optionally identify the nature of involvement of others. Link to GitHub aliases where possible. This list will likely change or grow stage after stage.
Expand All @@ -95,7 +227,6 @@ e.g.:
* @Mariana
-->


## References

<!-- Insert any links appropriate to this RFC in this section. -->
Expand All @@ -108,6 +239,7 @@ e.g.:
<!-- An RFC should link to the PRs for each of it stage advancements. -->

* Stage 0: https://github.com/elastic/ecs/pull/1386
* Stage 1: https://github.com/elastic/ecs/pull/1400

<!--
* Stage 1: https://github.com/elastic/ecs/pull/NNN
Expand Down
5 changes: 5 additions & 0 deletions rfcs/text/0021/as.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: as
reusable:
expected:
- threat.enrichments
5 changes: 5 additions & 0 deletions rfcs/text/0021/event.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: event
reusable:
expected:
- threat.enrichments
5 changes: 5 additions & 0 deletions rfcs/text/0021/file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: file
reusable:
expected:
- threat.enrichments
5 changes: 5 additions & 0 deletions rfcs/text/0021/geo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: geo
reusable:
expected:
- threat.enrichments
5 changes: 5 additions & 0 deletions rfcs/text/0021/hash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: hash
reusable:
expected:
- threat.enrichments
5 changes: 5 additions & 0 deletions rfcs/text/0021/pe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: pe
reusable:
expected:
- threat.enrichments
5 changes: 5 additions & 0 deletions rfcs/text/0021/registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: registry
reusable:
expected:
- threat.enrichments
51 changes: 51 additions & 0 deletions rfcs/text/0021/threat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
- name: threat

fields:

- name: enrichments
level: extended
type: nested
short: List of indicators enriching the event
description: >
A list of associated indicators enriching the event, and the context of that association/enrichment

- name: enrichments.matched.atomic
ebeahan marked this conversation as resolved.
Show resolved Hide resolved
level: extended
type: keyword
short: Matched indicator value
description: >
Identifies the atomic indicator value that matched a local environment endpoint or network event.
example: bad-domain.com

- name: enrichments.matched.field
level: extended
type: keyword
short: Matched indicator field
description: >
Identifies the field of the atomic indicator that matched a local environment endpoint or network event.
example: file.hash.sha256

- name: enrichments.matched.id
level: extended
type: keyword
short: Matched indicator identifier
description: >
Identifies the _id of the indicator document enriching the event.
example: ff93aee5-86a1-4a61-b0e6-0cdc313d01b5

- name: enrichments.matched.index
level: extended
type: keyword
short: Matched indicator index
description: >
Identifies the _index of the indicator document enriching the event.
example: filebeat-8.0.0-2021.05.23-000011

- name: enrichments.matched.type
level: extended
type: keyword
short: Type of indicator match
description: >
Identifies the type of match that caused the event to be enriched with the given indicator
example: indicator_match_rule
5 changes: 5 additions & 0 deletions rfcs/text/0021/url.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: url
reusable:
expected:
- threat.enrichments
5 changes: 5 additions & 0 deletions rfcs/text/0021/x509.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: x509
reusable:
expected:
- threat.enrichments