Skip to content

Commit ee2c8ca

Browse files
paul-tavaresakowalska622
authored andcommitted
[Security Solution][Endpoint] Update response action creation so that it store policy information when action is created (elastic#218175)
## Summary The following changes are in support of space awareness for response actions (currently behind feature flag: `endpointManagementSpaceAwarenessEnabled`). All response actions will now start to store agent policy information. - A new property will be stored in the Action Request document that captures policy information about each agent the action was sent to (`agent.policy: []`). - All response action client instances must now be initiated with a `spaceId` - A new method was added to the internal Fleet Services to retrieve all `namespace`'s in use by a given integration type in the active space - The SentinelOne and Microsoft run host scripts were enhaced so that the host VM name includes the space id
1 parent ced6d32 commit ee2c8ca

File tree

43 files changed

+1643
-219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1643
-219
lines changed

x-pack/solutions/security/plugins/security_solution/common/endpoint/data_generators/endpoint_action_generator.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,22 @@ export class EndpointActionGenerator extends BaseDataGenerator {
5050
overrides: DeepPartial<LogsEndpointAction<TParameters, TOutputContent, TMeta>> = {}
5151
): LogsEndpointAction<TParameters, TOutputContent, TMeta> {
5252
const timeStamp = overrides['@timestamp'] ? new Date(overrides['@timestamp']) : new Date();
53+
const agent = (overrides.agent?.id ?? [
54+
this.seededUUIDv4(),
55+
]) as LogsEndpointAction['agent']['id'];
56+
const agentId = Array.isArray(agent) ? (agent[0] as string) : agent;
5357
const doc: LogsEndpointAction<TParameters, TOutputContent, TMeta> = {
5458
'@timestamp': timeStamp.toISOString(),
5559
agent: {
56-
id: [this.seededUUIDv4()],
60+
id: agent,
61+
policy: [
62+
{
63+
agentId,
64+
elasticAgentId: agentId,
65+
integrationPolicyId: 'integration-policy-1',
66+
agentPolicyId: 'agent-policy-1',
67+
},
68+
],
5769
},
5870
EndpointActions: {
5971
action_id: this.seededUUIDv4(),

x-pack/solutions/security/plugins/security_solution/common/endpoint/data_generators/microsoft_defender_data_generator.ts

Lines changed: 142 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -5,141 +5,167 @@
55
* 2.0.
66
*/
77

8+
import type { DeepPartial } from 'utility-types';
9+
import { merge } from 'lodash';
10+
import type { SearchHit } from '@elastic/elasticsearch/lib/api/types';
11+
import { buildIndexNameWithNamespace } from '../utils/index_name_utilities';
12+
import { MICROSOFT_DEFENDER_ENDPOINT_LOG_INDEX_PATTERN } from '../service/response_actions/microsoft_defender';
813
import { BaseDataGenerator } from './base_data_generator';
14+
import type { MicrosoftDefenderEndpointLogEsDoc } from '../types';
915

1016
export class MicrosoftDefenderDataGenerator extends BaseDataGenerator {
1117
/**
1218
* Generates a MS Defender endpoint log as ingested by the Microsoft Defender for Endpoint
1319
* integration into the `logs-microsoft_defender_endpoint.log` index.
1420
* If adding this generated document to ES, make sure that the integration has been installed.
1521
*/
16-
generateEndpointLog() {
22+
generateEndpointLog(
23+
overrides: DeepPartial<MicrosoftDefenderEndpointLogEsDoc> = {}
24+
): MicrosoftDefenderEndpointLogEsDoc {
1725
const now = new Date().toISOString();
1826

19-
return {
20-
agent: {
21-
name: 'ptavares-agentless-integrations-default-8511',
22-
id: 'a572fc2e-0276-494a-b693-6e907bc2a78b',
23-
ephemeral_id: 'e7d70430-d25e-4d72-863e-918ac36bbbf7',
24-
type: 'filebeat',
25-
version: '9.0.0',
26-
},
27-
process: {
28-
parent: {
27+
return merge(
28+
{
29+
agent: {
30+
name: 'ptavares-agentless-integrations-default-8511',
31+
id: 'a572fc2e-0276-494a-b693-6e907bc2a78b',
32+
ephemeral_id: 'e7d70430-d25e-4d72-863e-918ac36bbbf7',
33+
type: 'filebeat',
34+
version: '9.0.0',
35+
},
36+
process: {
37+
parent: {
38+
start: now,
39+
pid: 9901,
40+
},
2941
start: now,
30-
pid: 9901,
42+
pid: 10083,
43+
command_line: '-bash',
3144
},
32-
start: now,
33-
pid: 10083,
34-
command_line: '-bash',
35-
},
36-
elastic_agent: {
37-
id: 'a572fc2e-0276-494a-b693-6e907bc2a78b',
38-
version: '9.0.0',
39-
snapshot: true,
40-
},
41-
rule: {
42-
description:
43-
'Remote file transfer activity was observed on this device. Attackers might be attempting to steal data from the device or move laterally on the network.',
44-
},
45-
message: 'Remote exfiltration activity',
46-
microsoft: {
47-
defender_endpoint: {
48-
evidence: {
49-
accountName: 'ubuntu',
50-
detectionStatus: 'Detected',
51-
parentProcessFileName: 'bash',
52-
entityType: 'Process',
53-
evidenceCreationTime: now,
54-
domainName: 'discerning-spaniel',
45+
elastic_agent: {
46+
id: 'a572fc2e-0276-494a-b693-6e907bc2a78b',
47+
version: '9.0.0',
48+
snapshot: true,
49+
},
50+
rule: {
51+
description:
52+
'Remote file transfer activity was observed on this device. Attackers might be attempting to steal data from the device or move laterally on the network.',
53+
},
54+
message: 'Remote exfiltration activity',
55+
microsoft: {
56+
defender_endpoint: {
57+
evidence: {
58+
accountName: 'ubuntu',
59+
detectionStatus: 'Detected',
60+
parentProcessFileName: 'bash',
61+
entityType: 'Process',
62+
evidenceCreationTime: now,
63+
domainName: 'discerning-spaniel',
64+
},
65+
mitreTechniques: [
66+
'T1005',
67+
'T1020',
68+
'T1041',
69+
'T1048',
70+
'T1071',
71+
'T1071.001',
72+
'T1204.001',
73+
'T1567',
74+
'T1570',
75+
],
76+
detectorId: this.seededUUIDv4(),
77+
investigationState: 'UnsupportedOs',
78+
incidentId: '4',
79+
lastUpdateTime: now,
80+
status: 'New',
5581
},
56-
mitreTechniques: [
57-
'T1005',
58-
'T1020',
59-
'T1041',
60-
'T1048',
61-
'T1071',
62-
'T1071.001',
63-
'T1204.001',
64-
'T1567',
65-
'T1570',
82+
},
83+
tags: ['microsoft-defender-endpoint', 'forwarded'],
84+
cloud: {
85+
instance: {
86+
id: '7bcf55e03728756dbf02ba7979a0c6218321ade7',
87+
},
88+
provider: 'azure',
89+
account: {
90+
id: 'c38d90f4-369c-4815-ab69-4663a1f5c115',
91+
},
92+
},
93+
input: {
94+
type: 'httpjson',
95+
},
96+
observer: {
97+
product: 'Defender for Endpoint',
98+
vendor: 'Microsoft',
99+
name: 'WindowsDefenderAtp',
100+
},
101+
'@timestamp': now,
102+
file: {
103+
path: '/usr/bin/',
104+
name: 'bash',
105+
hash: {
106+
sha1: 'ce4fbd66c02e235bbc8dfa4a512c51414d8e0e67',
107+
sha256: 'c5f8a98c674631609902846fae6df219b3b16d97db58cf1c1334f8eb14962bde',
108+
},
109+
},
110+
ecs: {
111+
version: '8.11.0',
112+
},
113+
related: {
114+
hosts: ['discerning-spaniel'],
115+
hash: [
116+
'ce4fbd66c02e235bbc8dfa4a512c51414d8e0e67',
117+
'c5f8a98c674631609902846fae6df219b3b16d97db58cf1c1334f8eb14962bde',
66118
],
67-
detectorId: this.seededUUIDv4(),
68-
investigationState: 'UnsupportedOs',
69-
incidentId: '4',
70-
lastUpdateTime: now,
71-
status: 'New',
72119
},
73-
},
74-
tags: ['microsoft-defender-endpoint', 'forwarded'],
75-
cloud: {
76-
instance: {
77-
id: '7bcf55e03728756dbf02ba7979a0c6218321ade7',
120+
data_stream: {
121+
namespace: 'default',
122+
type: 'logs',
123+
dataset: 'microsoft_defender_endpoint.log',
78124
},
79-
provider: 'azure',
80-
account: {
81-
id: 'c38d90f4-369c-4815-ab69-4663a1f5c115',
125+
host: {
126+
hostname: 'discerning-spaniel',
127+
name: 'discerning-spaniel',
82128
},
83-
},
84-
input: {
85-
type: 'httpjson',
86-
},
87-
observer: {
88-
product: 'Defender for Endpoint',
89-
vendor: 'Microsoft',
90-
name: 'WindowsDefenderAtp',
91-
},
92-
'@timestamp': now,
93-
file: {
94-
path: '/usr/bin/',
95-
name: 'bash',
96-
hash: {
97-
sha1: 'ce4fbd66c02e235bbc8dfa4a512c51414d8e0e67',
98-
sha256: 'c5f8a98c674631609902846fae6df219b3b16d97db58cf1c1334f8eb14962bde',
129+
threat: {
130+
framework: 'MITRE ATT&CK',
131+
technique: {
132+
name: ['Exfiltration'],
133+
},
99134
},
100-
},
101-
ecs: {
102-
version: '8.11.0',
103-
},
104-
related: {
105-
hosts: ['discerning-spaniel'],
106-
hash: [
107-
'ce4fbd66c02e235bbc8dfa4a512c51414d8e0e67',
108-
'c5f8a98c674631609902846fae6df219b3b16d97db58cf1c1334f8eb14962bde',
109-
],
110-
},
111-
data_stream: {
112-
namespace: 'default',
113-
type: 'logs',
114-
dataset: 'microsoft_defender_endpoint.log',
115-
},
116-
host: {
117-
hostname: 'discerning-spaniel',
118-
name: 'discerning-spaniel',
119-
},
120-
threat: {
121-
framework: 'MITRE ATT&CK',
122-
technique: {
123-
name: ['Exfiltration'],
135+
event: {
136+
severity: 3,
137+
created: now,
138+
kind: 'alert',
139+
timezone: 'UTC',
140+
start: now,
141+
type: ['start'],
142+
duration: 5253721000,
143+
agent_id_status: 'verified',
144+
ingested: now,
145+
provider: 'defender_endpoint',
146+
action: 'Exfiltration',
147+
end: now,
148+
id: this.seededUUIDv4(),
149+
category: ['host', 'process'],
150+
dataset: 'microsoft_defender_endpoint.log',
124151
},
125152
},
126-
event: {
127-
severity: 3,
128-
created: now,
129-
kind: 'alert',
130-
timezone: 'UTC',
131-
start: now,
132-
type: ['start'],
133-
duration: 5253721000,
134-
agent_id_status: 'verified',
135-
ingested: now,
136-
provider: 'defender_endpoint',
137-
action: 'Exfiltration',
138-
end: now,
139-
id: this.seededUUIDv4(),
140-
category: ['host', 'process'],
141-
dataset: 'microsoft_defender_endpoint.log',
142-
},
143-
};
153+
overrides
154+
);
155+
}
156+
157+
generateEndpointLogEsHit(
158+
overrides: DeepPartial<MicrosoftDefenderEndpointLogEsDoc> = {}
159+
): SearchHit<MicrosoftDefenderEndpointLogEsDoc> {
160+
return this.toEsSearchHit(
161+
this.generateEndpointLog(overrides),
162+
buildIndexNameWithNamespace(MICROSOFT_DEFENDER_ENDPOINT_LOG_INDEX_PATTERN, 'default')
163+
);
164+
}
165+
166+
generateEndpointLogEsSearchResponse(
167+
docs: Array<SearchHit<MicrosoftDefenderEndpointLogEsDoc>> = [this.generateEndpointLogEsHit()]
168+
) {
169+
return this.toEsSearchResponse(docs);
144170
}
145171
}

x-pack/solutions/security/plugins/security_solution/common/endpoint/data_generators/sentinelone_data_generator.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
SentinelOneGetRemoteScriptStatusApiResponse,
1919
SentinelOneRemoteScriptExecutionStatus,
2020
} from '@kbn/stack-connectors-plugin/common/sentinelone/types';
21+
import { buildIndexNameWithNamespace } from '../utils/index_name_utilities';
2122
import { EndpointActionGenerator } from './endpoint_action_generator';
2223
import { SENTINEL_ONE_ACTIVITY_INDEX_PATTERN } from '../..';
2324
import type {
@@ -26,7 +27,9 @@ import type {
2627
EndpointActionDataParameterTypes,
2728
EndpointActionResponseDataOutput,
2829
SentinelOneActivityDataForType80,
30+
SentinelOneAgentEsDoc,
2931
} from '../types';
32+
import { SENTINEL_ONE_AGENT_INDEX_PATTERN } from '../service/response_actions/sentinel_one';
3033

3134
export class SentinelOneDataGenerator extends EndpointActionGenerator {
3235
static readonly scriptExecutionStatusValues: Readonly<
@@ -428,6 +431,45 @@ export class SentinelOneDataGenerator extends EndpointActionGenerator {
428431
pagination: { totalItems: 1, nextCursor: undefined },
429432
};
430433
}
434+
435+
/**
436+
* Generate a SentinelOne Agent record that is ingested into Elasticsearch by the
437+
* integration into `logs-sentinel_one.agent-`
438+
*/
439+
generateAgentEsDoc(overrides: DeepPartial<SentinelOneAgentEsDoc> = {}): SentinelOneAgentEsDoc {
440+
return merge(
441+
{
442+
agent: {
443+
id: '1-2-3',
444+
type: 'filebeat',
445+
version: '9.1.0',
446+
},
447+
sentinel_one: {
448+
agent: {
449+
agent: {
450+
id: 's1-agent-1',
451+
},
452+
},
453+
},
454+
},
455+
overrides
456+
);
457+
}
458+
459+
generateAgentEsSearchHit(
460+
overrides: DeepPartial<SentinelOneAgentEsDoc> = {}
461+
): SearchHit<SentinelOneAgentEsDoc> {
462+
return this.toEsSearchHit(
463+
this.generateAgentEsDoc(overrides),
464+
buildIndexNameWithNamespace(SENTINEL_ONE_AGENT_INDEX_PATTERN, 'default')
465+
);
466+
}
467+
468+
generateAgentEsSearchResponse(
469+
docs: Array<SearchHit<SentinelOneAgentEsDoc>> = [this.generateAgentEsSearchHit()]
470+
): SearchResponse<SentinelOneAgentEsDoc> {
471+
return this.toEsSearchResponse<SentinelOneAgentEsDoc>(docs);
472+
}
431473
}
432474

433475
// Activity types from SentinelOne. Values can be retrieved from the SentineOne API at:

x-pack/solutions/security/plugins/security_solution/common/endpoint/service/response_actions/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ export const RESPONSE_ACTIONS_ALERT_AGENT_ID_FIELDS: Readonly<
213213
],
214214
crowdstrike: ['device.id'],
215215
microsoft_defender_endpoint: [
216+
'cloud.instance.id',
216217
'm365_defender.alerts.entities.deviceId',
217218
'm365_defender.alerts.devices.mdatpDeviceId',
218219
'm365_defender.incident.alert.evidence.mde_device_id',
219-
'cloud.instance.id',
220220
],
221221
});
222222

0 commit comments

Comments
 (0)