Skip to content

[sentinel_one] Enrich events with event.{category,type,outcome}#3787

Merged
andrewkroh merged 8 commits intoelastic:mainfrom
vinit-chauhan:sentinel_one_pipeline_fix
Aug 23, 2022
Merged

[sentinel_one] Enrich events with event.{category,type,outcome}#3787
andrewkroh merged 8 commits intoelastic:mainfrom
vinit-chauhan:sentinel_one_pipeline_fix

Conversation

@vinit-chauhan
Copy link
Contributor

@vinit-chauhan vinit-chauhan commented Jul 21, 2022

Type of change

  • Bug

What does this PR do?

This PR fixes the bug related to the value of event.category and event.type fields are being statically mapped. In this PR we have mapped the values of event.category, event.type and event.outcome based on the activity performed.

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.

How to test this PR locally

Related issues

Screenshots

image
image
image
image

@vinit-chauhan vinit-chauhan requested a review from a team as a code owner July 21, 2022 12:30
@vinit-chauhan vinit-chauhan added bug Something isn't working, use only for issues Team:Security-External Integrations Integration:sentinel_one SentinelOne labels Jul 21, 2022
@elasticmachine
Copy link

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@elasticmachine
Copy link

elasticmachine commented Jul 21, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-08-17T13:38:11.157+0000

  • Duration: 17 min 5 sec

Test stats 🧪

Test Results
Failed 0
Passed 31
Skipped 0
Total 31

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@elasticmachine
Copy link

elasticmachine commented Jul 21, 2022

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (5/5) 💚
Files 100.0% (5/5) 💚 2.825
Classes 100.0% (5/5) 💚 2.825
Methods 100.0% (71/71) 💚 10.664
Lines 97.97% (2558/2611) 👍 7.059
Conditionals 100.0% (0/0) 💚

def eventCategory = new HashSet();
def eventType = new HashSet();
if(ctx.json?.threatId != null && ctx.json?.threatId != "") {
if(ctx.json?.data?.threatClassification == "Malware") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I there a reason "Trojan" is not a malware classification? It appears in some of the documents that are now classed as "threat"/"indicator".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yes. Will update it.

Comment on lines +41 to +42
else if(ctx.json?.primaryDescription != null){
if(ctx.json?.primaryDescription?.toLowerCase().contains("logged in")){
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be made less verbose and made to do less work by assigning a local. Also, since we know ctx.json?.primaryDescription != null, the conditional null derefs are not needed in the later steps.

Suggested change
else if(ctx.json?.primaryDescription != null){
if(ctx.json?.primaryDescription?.toLowerCase().contains("logged in")){
else if(ctx.json?.primaryDescription != null) {
def description = ctx.json.primaryDescription.toLowerCase();
if (description.contains("logged in")) {

with similar uses in all the following conditions.

eventCategory.add("authentication");
ctx.event.outcome = "failure";
}
eventType.add("info");
Copy link
Contributor

Choose a reason for hiding this comment

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

Adjust the indent to match the block.

eventType.add("info");
}
ctx.event.category = eventCategory.size()==0 ? null : eventCategory;
ctx.event.type = eventType.size()==0 ? null : eventType;
Copy link
Member

Choose a reason for hiding this comment

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

How about an if (!eventCategory.isEmpty) { ctx.event.category = eventCategory } so that we don't end up with a null in the doc. Same for event.type.

eventType.add("start");
ctx.event.outcome = "success";
}
if(description.contains("logged out")){
Copy link
Member

Choose a reason for hiding this comment

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

Should these be else if?

eventCategory.add("authentication");
ctx.event.outcome = "failure";
}
eventType.add("info");
Copy link
Member

Choose a reason for hiding this comment

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

Is this meant to be a catch all? Should it be part of a final else block?

@vinit-chauhan vinit-chauhan force-pushed the sentinel_one_pipeline_fix branch from f2157dd to 94b571f Compare August 12, 2022 15:49
@vinit-chauhan vinit-chauhan force-pushed the sentinel_one_pipeline_fix branch from 94b571f to 510311b Compare August 12, 2022 16:45
@vinit-chauhan
Copy link
Contributor Author

/test

@andrewkroh andrewkroh added the conflicts There is a conflict in the backported pull request label Aug 16, 2022
@andrewkroh andrewkroh changed the title [sentinel_one] Enrich the event.category, event.type and event.outcome field based o… [sentinel_one] Enrich events with event.category/type/outcome Aug 16, 2022
@andrewkroh andrewkroh changed the title [sentinel_one] Enrich events with event.category/type/outcome [sentinel_one] Enrich events with event.{category,type,outcome} Aug 16, 2022
source: >
def eventCategory = new HashSet();
def eventType = new HashSet();
if (ctx.json?.threatId != null && ctx.json?.threatId != '') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (ctx.json?.threatId != null && ctx.json?.threatId != '') {
if (ctx.json?.threatId != null && ctx.json.threatId != '') {

if (!eventCategory.isEmpty()) {
ctx.event.category = eventCategory;
}
if (ctx.json?.data?.confidenceLevel != null && ['suspicious', 'malicious'].contains(ctx.json?.data?.confidenceLevel)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[...].contains(null) returns false unless the array list holds a null, so this can be rewritten:

Suggested change
if (ctx.json?.data?.confidenceLevel != null && ['suspicious', 'malicious'].contains(ctx.json?.data?.confidenceLevel)) {
if (['suspicious', 'malicious'].contains(ctx.json?.data?.confidenceLevel)) {

if (threat_classification == 'Exploit' || threat_classification == 'PUA') {
eventCategory.add('threat');
eventType.add('indicator');
} else if (threat_classification == 'Malware' || threat_classification == 'Ransomware' || threat_classification == 'Trojan' || threat_classification == 'Downloader') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} else if (threat_classification == 'Malware' || threat_classification == 'Ransomware' || threat_classification == 'Trojan' || threat_classification == 'Downloader') {
} else if ['Malware', 'Ransomware', 'Trojan', 'Downloader'].contains(threat_classification)) {

Maybe similar for above? I have no strong opinion either way for that though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working, use only for issues conflicts There is a conflict in the backported pull request Integration:sentinel_one SentinelOne

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The sentinel_one activity dataset events are miscategorized as "malware" in field event.category

4 participants