Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ describe('indicator match', () => {
{
line: 3,
text:
' "indicator": "{\\"first_seen\\":\\"2021-03-10T08:02:14.000Z\\",\\"file\\":{\\"size\\":80280,\\"pe\\":{},\\"type\\":\\"elf\\",\\"hash\\":{\\"sha256\\":\\"a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3\\",\\"tlsh\\":\\"6D7312E017B517CC1371A8353BED205E9128223972AE35302E97528DF957703BAB2DBE\\",\\"ssdeep\\":\\"1536:87vbq1lGAXSEYQjbChaAU2yU23M51DjZgSQAvcYkFtZTjzBht5:8D+CAXFYQChaAUk5ljnQssL\\",\\"md5\\":\\"9b6c3518a91d23ed77504b5416bfb5b3\\"}},\\"type\\":\\"file\\",\\"matched\\":{\\"atomic\\":\\"a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3\\",\\"field\\":\\"myhash.mysha256\\",\\"id\\":\\"84cf452c1e0375c3d4412cb550bd1783358468a3b3b777da4829d72c7d6fb74f\\",\\"index\\":\\"filebeat-7.12.0-2021.03.10-000001\\",\\"type\\":\\"file\\"}}"',
' "indicator": "{\\"first_seen\\":\\"2021-03-10T08:02:14.000Z\\",\\"file\\":{\\"size\\":80280,\\"pe\\":{},\\"type\\":\\"elf\\",\\"hash\\":{\\"sha256\\":\\"a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3\\",\\"tlsh\\":\\"6D7312E017B517CC1371A8353BED205E9128223972AE35302E97528DF957703BAB2DBE\\",\\"ssdeep\\":\\"1536:87vbq1lGAXSEYQjbChaAU2yU23M51DjZgSQAvcYkFtZTjzBht5:8D+CAXFYQChaAUk5ljnQssL\\",\\"md5\\":\\"9b6c3518a91d23ed77504b5416bfb5b3\\"}},\\"type\\":\\"file\\",\\"event\\":{\\"reference\\":\\"https://urlhaus-api.abuse.ch/v1/download/a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3/\\",\\"ingested\\":\\"2021-03-10T14:51:09.809069Z\\",\\"created\\":\\"2021-03-10T14:51:07.663Z\\",\\"kind\\":\\"enrichment\\",\\"module\\":\\"threatintel\\",\\"category\\":\\"threat\\",\\"type\\":\\"indicator\\",\\"dataset\\":\\"threatintel.abusemalware\\"},\\"matched\\":{\\"atomic\\":\\"a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3\\",\\"field\\":\\"myhash.mysha256\\",\\"id\\":\\"84cf452c1e0375c3d4412cb550bd1783358468a3b3b777da4829d72c7d6fb74f\\",\\"index\\":\\"filebeat-7.12.0-2021.03.10-000001\\",\\"type\\":\\"file\\"}}"',
},
{ line: 2, text: ' }' },
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ecsMapping from './ecs_mapping.json';
incremented by 10 in order to add "room" for the aforementioned patch
release
*/
export const SIGNALS_TEMPLATE_VERSION = 25;
export const SIGNALS_TEMPLATE_VERSION = 26;
export const MIN_EQL_RULE_INDEX_VERSION = 2;

export const getSignalsTemplate = (index: string) => {
Expand All @@ -45,6 +45,19 @@ export const getSignalsTemplate = (index: string) => {
properties: {
...ecsMapping.mappings.properties,
signal: signalsMapping.mappings.properties.signal,
threat: {
...ecsMapping.mappings.properties.threat,
properties: {
...ecsMapping.mappings.properties.threat.properties,
indicator: {
...ecsMapping.mappings.properties.threat.properties.indicator,
properties: {
...ecsMapping.mappings.properties.threat.properties.indicator.properties,
event: ecsMapping.mappings.properties.event,
},
},
},
},
},
_meta: {
version: SIGNALS_TEMPLATE_VERSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('buildMatchedIndicator', () => {
getThreatListItemMock({
_id: '123',
_source: {
event: { dataset: 'abuse.ch', reference: 'https://test.com' },
threat: { indicator: { domain: 'domain_1', other: 'other_1', type: 'type_1' } },
},
}),
Expand Down Expand Up @@ -117,6 +118,16 @@ describe('buildMatchedIndicator', () => {
expect(get(indicator, 'matched.atomic')).toEqual('domain_1');
});

it('returns event values as a part of threat', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

const [indicator] = buildMatchedIndicator({
queries,
threats,
indicatorPath,
});
const expectedEvent = threats[0]._source!.event;
expect(get(indicator, 'event')).toEqual(expectedEvent);
});

it('returns the _id of the matched indicator as matched.id', () => {
const [indicator] = buildMatchedIndicator({
queries,
Expand Down Expand Up @@ -162,12 +173,16 @@ describe('buildMatchedIndicator', () => {
getThreatListItemMock({
_id: '123',
_source: {
threat: { indicator: { domain: 'domain_1', other: 'other_1', type: 'type_1' } },
event: { reference: 'https://test.com' },
threat: {
indicator: { domain: 'domain_1', other: 'other_1', type: 'type_1' },
},
},
}),
getThreatListItemMock({
_id: '456',
_source: {
event: { reference: 'https://test2.com' },
threat: { indicator: { domain: 'domain_1', other: 'other_1', type: 'type_1' } },
},
}),
Expand Down Expand Up @@ -205,6 +220,10 @@ describe('buildMatchedIndicator', () => {
},
other: 'other_1',
type: 'type_1',
event: {
reference: 'https://test.com',
dataset: 'abuse.ch',
},
},
]);
});
Expand All @@ -214,6 +233,9 @@ describe('buildMatchedIndicator', () => {
getThreatListItemMock({
_id: '123',
_source: {
event: {
reference: 'https://test3.com',
},
'threat.indicator.domain': 'domain_1',
custom: {
indicator: {
Expand Down Expand Up @@ -244,6 +266,9 @@ describe('buildMatchedIndicator', () => {
type: 'indicator_type',
},
type: 'indicator_type',
event: {
reference: 'https://test3.com',
},
},
]);
});
Expand Down Expand Up @@ -307,6 +332,9 @@ describe('buildMatchedIndicator', () => {
getThreatListItemMock({
_id: '123',
_source: {
event: {
reference: 'https://test4.com',
},
threat: {
indicator: [
{ domain: 'foo', type: 'first' },
Expand Down Expand Up @@ -334,6 +362,9 @@ describe('buildMatchedIndicator', () => {
type: 'first',
},
type: 'first',
event: {
reference: 'https://test4.com',
},
},
]);
});
Expand Down Expand Up @@ -392,6 +423,9 @@ describe('enrichSignalThreatMatches', () => {
getThreatListItemMock({
_id: '123',
_source: {
event: {
category: 'malware',
},
threat: { indicator: { domain: 'domain_1', other: 'other_1', type: 'type_1' } },
},
}),
Expand Down Expand Up @@ -419,7 +453,11 @@ describe('enrichSignalThreatMatches', () => {

it('preserves existing threat.indicator objects on signals', async () => {
const signalHit = getSignalHitMock({
_source: { '@timestamp': 'mocked', threat: { indicator: [{ existing: 'indicator' }] } },
_source: {
'@timestamp': 'mocked',
event: { category: 'malware' },
threat: { indicator: [{ existing: 'indicator' }] },
},
matched_queries: [matchedQuery],
});
const signals = getSignalsResponseMock([signalHit]);
Expand All @@ -444,6 +482,9 @@ describe('enrichSignalThreatMatches', () => {
},
other: 'other_1',
type: 'type_1',
event: {
category: 'malware',
},
},
]);
});
Expand Down Expand Up @@ -477,7 +518,11 @@ describe('enrichSignalThreatMatches', () => {

it('preserves an existing threat.indicator object on signals', async () => {
const signalHit = getSignalHitMock({
_source: { '@timestamp': 'mocked', threat: { indicator: { existing: 'indicator' } } },
_source: {
'@timestamp': 'mocked',
event: { category: 'virus' },
threat: { indicator: { existing: 'indicator' } },
},
matched_queries: [matchedQuery],
});
const signals = getSignalsResponseMock([signalHit]);
Expand All @@ -502,6 +547,9 @@ describe('enrichSignalThreatMatches', () => {
},
other: 'other_1',
type: 'type_1',
event: {
category: 'malware',
},
},
]);
});
Expand Down Expand Up @@ -573,12 +621,14 @@ describe('enrichSignalThreatMatches', () => {
getThreatListItemMock({
_id: '123',
_source: {
event: { category: 'threat' },
threat: { indicator: { domain: 'domain_1', other: 'other_1', type: 'type_1' } },
},
}),
getThreatListItemMock({
_id: '456',
_source: {
event: { category: 'bad' },
threat: { indicator: { domain: 'domain_2', other: 'other_2', type: 'type_2' } },
},
}),
Expand Down Expand Up @@ -622,6 +672,9 @@ describe('enrichSignalThreatMatches', () => {
field: 'event.field',
type: 'type_1',
},
event: {
category: 'threat',
},
other: 'other_1',
type: 'type_1',
},
Expand All @@ -634,6 +687,9 @@ describe('enrichSignalThreatMatches', () => {
field: 'event.other',
type: 'type_2',
},
event: {
category: 'bad',
},
other: 'other_2',
type: 'type_2',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ export const buildMatchedIndicator = ({
}
const atomic = get(matchedThreat?._source, query.value) as unknown;
const type = get(indicator, 'type') as unknown;
const event = get(matchedThreat?._source, 'event') as unknown;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 this logic is correct, it's just the mappings that are off.


return {
...indicator,
event,
matched: { atomic, field: query.field, id: query.id, index: query.index, type },
};
});
Expand Down
Loading