-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend] Filter observables creation with refs from indicators (#5293)
- Loading branch information
1 parent
47d1225
commit eb146f8
Showing
4 changed files
with
42 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { cleanupIndicatorPattern, extractObservablesFromIndicatorPattern, STIX_PATTERN_TYPE } from '../../../src/utils/syntax'; | ||
import { cleanupIndicatorPattern, extractObservablesFromIndicatorPattern, STIX_PATTERN_TYPE, validateObservableGeneration } from '../../../src/utils/syntax'; | ||
import * as C from '../../../src/schema/stixCyberObservable'; | ||
import { computeValidPeriod, computeValidTTL, DEFAULT_INDICATOR_TTL } from '../../../src/modules/indicator/indicator-utils'; | ||
import { ADMIN_USER, testContext } from '../../utils/testQuery'; | ||
|
@@ -40,19 +40,37 @@ describe('indicator utils', () => { | |
expect(domainAndHostname[1].type).toEqual(C.ENTITY_DOMAIN_NAME); | ||
expect(domainAndHostname[1].value).toEqual('www.5z8.info'); | ||
// simpleEmailAddress | ||
const simpleEmailAddress = extractObservablesFromIndicatorPattern('[email-message:sender_ref.value = \'[email protected]\' AND email-message:subject = \'Conference Info\']'); | ||
expect(simpleEmailAddress.length).toEqual(1); | ||
expect(simpleEmailAddress[0].type).toEqual(C.ENTITY_EMAIL_MESSAGE); | ||
expect(simpleEmailAddress[0].subject).toEqual('Conference Info'); | ||
const simpleEmailMessage = extractObservablesFromIndicatorPattern('[email-message:sender_ref.value = \'[email protected]\' AND email-message:subject = \'Conference Info\']'); | ||
expect(simpleEmailMessage.length).toEqual(1); | ||
expect(simpleEmailMessage[0].type).toEqual(C.ENTITY_EMAIL_MESSAGE); | ||
expect(simpleEmailMessage[0].subject).toEqual('Conference Info'); // we only extract the subject, without the sender_ref | ||
// simpleUrl | ||
const simpleUrl = extractObservablesFromIndicatorPattern('[url:value = \'http://localhost.com\']'); | ||
expect(simpleUrl.length).toEqual(1); | ||
expect(simpleUrl[0].type).toEqual(C.ENTITY_URL); | ||
expect(simpleUrl[0].value).toEqual('http://localhost.com'); | ||
// network traffic | ||
const networkTrafficPort = extractObservablesFromIndicatorPattern('[network-traffic:dst_ref.value = \'127.0.0.1\' AND network-traffic:dst_port = 443]'); | ||
expect(networkTrafficPort.length).toEqual(1); | ||
expect(networkTrafficPort[0].type).toEqual(C.ENTITY_NETWORK_TRAFFIC); | ||
expect(networkTrafficPort[0].dst_port).toEqual('443'); // we only extract dst_port, not dst_ref | ||
|
||
const networkTrafficIP = extractObservablesFromIndicatorPattern('[network-traffic:dst_ref.type = \'ipv4-addr\' AND network-traffic:dst_ref.value = \'203.0.113.33/32\']'); | ||
expect(networkTrafficIP.length).toEqual(0); // we don't know how to extract dst_ref for now | ||
// Unknown type | ||
const unknown = extractObservablesFromIndicatorPattern('[x-company-type:value = \'http://localhost.com\']'); | ||
expect(unknown.length).toEqual(0); | ||
}); | ||
it('should validate observables extracted before creation', async () => { | ||
const networkTrafficWithDstRef = validateObservableGeneration(C.ENTITY_NETWORK_TRAFFIC, "[network-traffic:dst_ref.type = 'ipv4-addr' AND network-traffic:dst_ref.value = '203.0.113.33/32']"); | ||
expect(networkTrafficWithDstRef).toBeFalsy(); | ||
const networkTrafficWithDstRefAndPort = validateObservableGeneration(C.ENTITY_NETWORK_TRAFFIC, "[network-traffic:dst_ref.value = '127.0.0.1' AND network-traffic:dst_port = 443]"); | ||
expect(networkTrafficWithDstRefAndPort).toBeFalsy(); | ||
const emailMessageWithFromRef = validateObservableGeneration(C.ENTITY_EMAIL_MESSAGE, "[email-message:sender_ref.value = '[email protected]' AND email-message:subject = 'Bad subject'"); | ||
expect(emailMessageWithFromRef).toBeFalsy(); | ||
const emailMessageSubject = validateObservableGeneration(C.ENTITY_EMAIL_MESSAGE, "[email-message:subject = 'Bad subject']"); | ||
expect(emailMessageSubject).toBeTruthy(); | ||
}); | ||
it('should indicator cleaned', async () => { | ||
const testIndicatorPattern = (from: string, expectation: string) => { | ||
const formattedPattern = cleanupIndicatorPattern(STIX_PATTERN_TYPE, from); | ||
|