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

Add malware_signature for Memory protection alert #155

Merged
merged 12 commits into from
Jul 28, 2021
Merged

Add malware_signature for Memory protection alert #155

merged 12 commits into from
Jul 28, 2021

Conversation

gogochan
Copy link
Collaborator

@gogochan gogochan commented Jun 30, 2021

Issue: https://github.com/elastic/security-team/issues/1214

Adding additional fields that are part of yara signature. The fields are used in FileScore alert and MemoryScan Alert.

  • malware_signature.all_names
  • malware_signature.primary.signature.name
  • malware_signature.primary.signature.id
  • malware_signature.memory_region.allocation_protection
  • malware_signature.memory_region.allocation_size
  • malware_signature.memory_region.allocation_type
  • malware_signature.memory_region.region_protection
  • malware_signature.memory_region.region_size
  • malware_signature.memory_region.region_state
  • malware_signature.memory_region.memory_pe.imphash
  • malware_signature.memory_region.bytes_allocation_offset
  • malware_signature.primary.signature.hash.sha256
  • malware_signature.primary.matches
  • version
  • identifier

@gogochan gogochan changed the title added malware_signature Add malware_signature Jun 30, 2021
@@ -469,6 +469,8 @@ fields:
exceptionable: true
status:
exceptionable: true
malware_signature:
fields: "*"
Copy link
Contributor

Choose a reason for hiding this comment

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

Everything else here looks like this:

Suggested change
fields: "*"
fields: {}

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should update the docs on "*" vs {} because I always forget haha. {} only works when the field is a leaf aka if we only wanted malware_signature.all_names in the mapping we could write it like:

malware_signature:
  fields:
    all_names: {}

Since we want everything under malware_signature and fields is an array we have to use the "*" syntax like Chan has here.

@@ -469,6 +469,8 @@ fields:
exceptionable: true
status:
exceptionable: true
malware_signature:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this go into memory_protection_event, since Memory Scan is presented to the user as part of Memory Protection? https://github.com/elastic/endpoint-package/blob/c23a052ef81ea39ab2934e2e1ea5b32bff102196/custom_subsets/elastic_endpoint/alerts/memory_protection_event.yaml

Copy link
Contributor

@ferullo ferullo Jun 30, 2021

Choose a reason for hiding this comment

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

This should stay where it is at the very least for malware (FileScore) events. We could duplicate it to another location as well for use by memory alerts though I'd vote against that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I take it back. I now see you're commenting on process.Ext.malware_signature not file.Exe.malware_signature.

Currently Linux only sends file activity based malware (FileScore) alerts (open, write, etc) so wouldn't ever need this location. But Windows and macOS can send process based malware alerts (process start). So I still think this is needed for Windows and macOS signature based FileScore alerts (and wonder why testing has been OK without this so far).

But that's only whether or not this update is beneficial to malware alerts. My presumption would be that a standardized key name for yara signature matches regardless of the protection type would be better than it going in different places for different alert types. But I don't feel strongly, if my presumption is wrong I'll stay silent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Per our discussion, I will remove this line from this PR. We will add it back in 7.15

Copy link
Collaborator

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

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

Thanks for the PR Chan! Couple questions and changes:

From the example that Kevin linked (memory_signature_agentTesla.json.zip) it looks like memory_region is included in malware_signature:

"memory_region": {
                    "allocation_base": 4194304,
                    "allocation_protection": "RWX",
                    "allocation_size": 245760,
                    "allocation_type": "PRIVATE",
                    "bytes_address": 4194304,
                    "bytes_allocation_offset": 0,

do we need to update https://github.com/elastic/endpoint-package/blob/master/custom_schemas/custom_memory_region.yml#L11 to include it within this schema as well?

@@ -469,6 +469,8 @@ fields:
exceptionable: true
status:
exceptionable: true
malware_signature:
fields: "*"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should update the docs on "*" vs {} because I always forget haha. {} only works when the field is a leaf aka if we only wanted malware_signature.all_names in the mapping we could write it like:

malware_signature:
  fields:
    all_names: {}

Since we want everything under malware_signature and fields is an array we have to use the "*" syntax like Chan has here.

custom_schemas/custom_malware_signature.yml Show resolved Hide resolved

- name: secondary
level: custom
type: array
Copy link
Collaborator

Choose a reason for hiding this comment

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

In Elasticsearch there isn't an array type. Everything can be an array out of the box: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html#types-array-handling

Could we change this to the structure and type that will be contained within secondary? If secondary will be the exact same as primary, you could abstract it out to a new file and have it overlaid as both primary and secondary using the ECS reuse mechanism.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

secondary will be a list of object that are subset of the primary. Should I just say object here then?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we use object then users won't be able to search for it beyond just using a search based on its existence. If we don't expect users to search for the secondary fields then you could exclude it from the definition here. The only reason we want to define it in the endpoint package is so that users can search for it. If you want to include it just as a description of a field that could exist in an alert, we can add enabled: false (e.g. https://github.com/elastic/endpoint-package/blob/master/custom_schemas/custom_endpoint.yml#L28) that way Elasticsearch will not index it.

@gogochan gogochan changed the title Add malware_signature Add malware_signature for FileScore alert Jun 30, 2021
@gogochan
Copy link
Collaborator Author

do we need to update https://github.com/elastic/endpoint-package/blob/master/custom_schemas/custom_memory_region.yml#L11 to include it within this schema as well?

I'm not sure if we need to include them. IMO creating an Exception based on those values would be too much of information.

@jonathan-buttner
Copy link
Collaborator

do we need to update https://github.com/elastic/endpoint-package/blob/master/custom_schemas/custom_memory_region.yml#L11 to include it within this schema as well?

I'm not sure if we need to include them. IMO creating an Exception based on those values would be too much of information.

I guess what I mean is, based on the example that Kevin gave I'm assuming the endpoint will send those memory region values. If we expect the user to want to search for alerts based on malware_signature.memory_region.* values then we'd need to include those in the mapping here. If we don't expect the user to search for them then we can leave them out.

@kevinlog @pzl could you take a look at the mappings when you get a chance.

@kevinlog
Copy link
Contributor

kevinlog commented Jul 1, 2021

@jonathan-buttner thanks for bubbling this up.

I guess what I mean is, based on the example that Kevin gave I'm assuming the endpoint will send those memory region values. If we expect the user to want to search for alerts based on malware_signature.memory_region.* values then we'd need to include those in the mapping here. If we don't expect the user to search for them then we can leave them out.

There are two questions to answer here:

  1. Does the user need to search for alerts based on this field
  2. Should the user be able to add Exceptions based on this field for this Alert
    • Implies we need it in the Index pattern

I don't think we need to index this field for searching.

However, we may want it included in the Index pattern so that we can write exceptions for it.

@gogochan @gabriellandau @ferullo any thoughts on writing Exceptions?

If we DO want to write Exceptions, we can enabled: false so that we don't index the field and include it in searches.

@ferullo
Copy link
Contributor

ferullo commented Jul 1, 2021

@joe-desimone has thoughts on what signature match fields should be available for exceptions.

@joe-desimone
Copy link

joe-desimone commented Jul 1, 2021

I believe users should have the ability to search for and create exceptions from the following fields: malware_signature.all_names, malware_signature.primary.signature.name, malware_signature.primary.signature.id, malware_signature.memory_region.allocation_protection, malware_signature.memory_region.allocation_size, malware_signature.memory_region.allocation_type, malware_signature.memory_region.region_protection, malware_signature.memory_region.region_size, malware_signature.memory_region.region_state, malware_signature.memory_region.memory_pe.imphash, malware_signature.memory_region.bytes_allocation_offset

@dstepanic17 can you double check my work

Also side note, the memory_region stuff is landing in production at 7.15 at the earliest. Not applicable to linux file yara scanning which is landing in 7.14.

@dstepanic
Copy link

@joe-desimone Here, are a couple fields I did not see on your list. I believe the region_base maps to allocation_base, but might be confusing for users to not let them search or create exceptions on it. I believe the other field bytes_allocation_offset can bring in unique data so might be useful for searching/exceptions. Everything else looks good.

  • malware_signature.memory_region.region_base
  • malware_signature.memory_region.bytes_allocation_offset

@joe-desimone
Copy link

@joe-desimone Here, are a couple fields I did not see on your list. I believe the region_base maps to allocation_base, but might be confusing for users to not let them search or create exceptions on it. I believe the other field bytes_allocation_offset can bring in unique data so might be useful for searching/exceptions. Everything else looks good.

  • malware_signature.memory_region.region_base
  • malware_signature.memory_region.bytes_allocation_offset

Thank you. I actually had allocation_base on there by mistake, and left off region_base intentionally. My thinking was these are going to be generally random so not too helpful from an exceptionlist point of view (but useful for response). allocation_offset I waffled on. In some situations it could be useful so I added it now.

Also, we dont have it yet but we should add malware_signature.memory_region.memory_pe.imphash to match shellcode alert schema more closely. We would want to search+exception on that as well so I added it to my original list.

@gogochan
Copy link
Collaborator Author

I believe users should have the ability to search for and create exceptions from the following fields: malware_signature.all_names, malware_signature.primary.signature.name, malware_signature.primary.signature.id, malware_signature.memory_region.allocation_protection, malware_signature.memory_region.allocation_size, malware_signature.memory_region.allocation_type, malware_signature.memory_region.region_protection, malware_signature.memory_region.region_size, malware_signature.memory_region.region_state, malware_signature.memory_region.memory_pe.imphash, malware_signature.memory_region.bytes_allocation_offset

Just want to point out that the current workflow does exception list checking before reading process memory, thus it lacks memory_signature.* fields.

https://github.com/elastic/endpoint-dev/blob/master/Elastic/Plugins/MemoryProtection/Lib/MemoryScan.cpp#L472-L479

We can alter the behavior, but it means that we are checking the exception list after scanning process memory.

@gogochan
Copy link
Collaborator Author

do we need to update https://github.com/elastic/endpoint-package/blob/master/custom_schemas/custom_memory_region.yml#L11 to include it within this schema as well?

@jonathan-buttner We will make a separate PR to address this. I've adjusted the PR per comments provided. Let me know if this is good.

@gabriellandau
Copy link
Contributor

@joe-desimone per our recent conversations, do you think we should put malware_signature under memory_region instead of vice-versa?

Copy link
Collaborator

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

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

Left a few more comments about changes I think we need

custom_schemas/custom_malware_signature.yml Outdated Show resolved Hide resolved
custom_schemas/custom_malware_signature.yml Outdated Show resolved Hide resolved
custom_subsets/elastic_endpoint/alerts/malware_event.yaml Outdated Show resolved Hide resolved
@gogochan
Copy link
Collaborator Author

Thanks @jonathan-buttner for the suggestion. It looks better now.

@ferullo
Copy link
Contributor

ferullo commented Jul 16, 2021

We can alter the behavior, but it means that we are checking the exception list after scanning process memory.

Endpoint should definitely check the exception list after it scans memory and can generate the alert but before it takes action. Checking exceptions earlier than this is a good optimization but this final check is always needed for all protections.

Copy link
Collaborator

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

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

Looks good! Just one question.

top_level: false
expected:
- process.Ext
- file.Ext
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a heads up it doesn't look like malware_signature is being placed under file.Ext 🤔 that might be because the file subset file doesn't include it 🤷‍♂️ is that ok?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I updated the title. All fields added here are for Memory Protection plugin.

@gogochan gogochan changed the title Add malware_signature for FileScore alert Add malware_signature for Memory protection alert Jul 16, 2021
@joe-desimone
Copy link

We can alter the behavior, but it means that we are checking the exception list after scanning process memory.

Endpoint should definitely check the exception list after it scans memory and can generate the alert but before it takes action. Checking exceptions earlier than this is a good optimization but this final check is always needed for all protections.

Agree here. I had the understanding that we do some early exceptionlist tests which would allow us better performance like https://github.com/elastic/global-security-exceptionlist/pull/257/files. Might be a good place for unit test.

@joe-desimone
Copy link

@joe-desimone per our recent conversations, do you think we should put malware_signature under memory_region instead of vice-versa?

Yes which would help makes things more consistent between shellcode alerts and memory scan alerts

@joe-desimone
Copy link

@joe-desimone per our recent conversations, do you think we should put malware_signature under memory_region instead of vice-versa?

Yes which would help makes things more consistent between shellcode alerts and memory scan alerts

Created an issue to specifically discuss this proposal https://github.com/elastic/security-team/issues/1496

@gogochan
Copy link
Collaborator Author

This may require further modification based on https://github.com/elastic/security-team/issues/1496

@gogochan
Copy link
Collaborator Author

gogochan commented Jul 19, 2021

Added changes proposed in https://github.com/elastic/security-team/issues/1496
basically malware_signature goes under memory_region

order: 1
top_level: false
expected:
- memory_region
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -9,6 +9,7 @@
order: 1
top_level: false
expected:
- process.Ext
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious, should we be calling it start_address_details within process.Ext too like in process.thread.Ext?

Copy link
Contributor

@gabriellandau gabriellandau left a comment

Choose a reason for hiding this comment

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

I pushed changes that addressed my concerns. LGTM.

Copy link
Collaborator

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

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

Question about renaming start_address_details

@@ -262,27 +262,6 @@ fields:
start_address_bytes: {}
start_address_bytes_disasm: {}
start_address_bytes_disasm_hash: {}
start_address_details:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will result in a breaking change since we're renaming these fields. Has the endpoint already started populating these fields in 7.14 or prior? If it has, do any of our detection rules use these fields? If they do we'll be causing them to no longer work. Do you think it's likely that users have custom detection rules triggering based on these fields?

@joe-desimone @rw-access @gogochan @gabriellandau

Copy link
Contributor

Choose a reason for hiding this comment

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

Has the endpoint already started populating these fields in 7.14 or prior?

Only for diagnostic. The shellcode feature isn't going live until 7.15.

If it has, do any of our detection rules use these fields?

Negative. Not until 7.15.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok perfect! Thanks Gabe!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants