Skip to content

Commit 4390ea8

Browse files
authored
[EDR Workflows] Scripts selector component in Response Console (elastic#204965)
1 parent 5a82e1f commit 4390ea8

22 files changed

Lines changed: 913 additions & 28 deletions

File tree

x-pack/platform/plugins/shared/stack_connectors/common/crowdstrike/schema.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,5 +348,45 @@ export const CrowdstrikeExecuteRTRResponseSchema = schema.object(
348348
{ unknowns: 'allow' }
349349
);
350350

351-
// TODO: will be part of a next PR
352-
export const CrowdstrikeGetScriptsParamsSchema = schema.any({});
351+
export const CrowdstrikeGetScriptsResponseSchema = schema.object(
352+
{
353+
meta: schema.maybe(
354+
schema.object(
355+
{
356+
query_time: schema.maybe(schema.number()),
357+
powered_by: schema.maybe(schema.string()),
358+
trace_id: schema.maybe(schema.string()),
359+
},
360+
{ unknowns: 'allow' }
361+
)
362+
),
363+
resources: schema.maybe(
364+
schema.arrayOf(
365+
schema.object(
366+
{
367+
content: schema.maybe(schema.string()),
368+
created_by: schema.maybe(schema.string()),
369+
created_by_uuid: schema.maybe(schema.string()),
370+
created_timestamp: schema.maybe(schema.string()),
371+
file_type: schema.maybe(schema.string()),
372+
id: schema.maybe(schema.string()),
373+
description: schema.maybe(schema.string()),
374+
modified_by: schema.maybe(schema.string()),
375+
modified_timestamp: schema.maybe(schema.string()),
376+
name: schema.maybe(schema.string()),
377+
permission_type: schema.maybe(schema.string()),
378+
platform: schema.maybe(schema.arrayOf(schema.string())),
379+
run_attempt_count: schema.maybe(schema.number()),
380+
run_success_count: schema.maybe(schema.number()),
381+
sha256: schema.maybe(schema.string()),
382+
size: schema.maybe(schema.number()),
383+
write_access: schema.maybe(schema.boolean()),
384+
},
385+
{ unknowns: 'allow' }
386+
)
387+
)
388+
),
389+
errors: schema.maybe(schema.arrayOf(schema.any())),
390+
},
391+
{ unknowns: 'allow' }
392+
);

x-pack/platform/plugins/shared/stack_connectors/common/crowdstrike/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
RelaxedCrowdstrikeBaseApiResponseSchema,
2020
CrowdstrikeInitRTRParamsSchema,
2121
CrowdstrikeExecuteRTRResponseSchema,
22+
CrowdstrikeGetScriptsResponseSchema,
2223
} from './schema';
2324

2425
export type CrowdstrikeConfig = TypeOf<typeof CrowdstrikeConfigSchema>;
@@ -42,3 +43,4 @@ export type CrowdstrikeActionParams = TypeOf<typeof CrowdstrikeActionParamsSchem
4243
export type CrowdstrikeInitRTRParams = TypeOf<typeof CrowdstrikeInitRTRParamsSchema>;
4344

4445
export type CrowdStrikeExecuteRTRResponse = TypeOf<typeof CrowdstrikeExecuteRTRResponseSchema>;
46+
export type CrowdstrikeGetScriptsResponse = TypeOf<typeof CrowdstrikeGetScriptsResponseSchema>;

x-pack/platform/plugins/shared/stack_connectors/server/connector_types/crowdstrike/crowdstrike.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,7 @@ describe('CrowdstrikeConnector', () => {
458458
mockedRequest.mockResolvedValueOnce({ data: { access_token: 'testToken' } });
459459
mockedRequest.mockResolvedValueOnce(mockResponse);
460460

461-
const result = await connector.getRTRCloudScripts(
462-
{ ids: ['script1', 'script2'] },
463-
connectorUsageCollector
464-
);
461+
const result = await connector.getRTRCloudScripts({}, connectorUsageCollector);
465462

466463
expect(mockedRequest).toHaveBeenNthCalledWith(
467464
1,

x-pack/platform/plugins/shared/stack_connectors/server/connector_types/crowdstrike/crowdstrike.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ import type {
2525
CrowdstrikeGetAgentOnlineStatusResponse,
2626
RelaxedCrowdstrikeBaseApiResponse,
2727
CrowdStrikeExecuteRTRResponse,
28+
CrowdstrikeGetScriptsResponse,
2829
} from '../../../common/crowdstrike/types';
2930
import type { CrowdstrikeGetTokenResponseSchema } from '../../../common/crowdstrike/schema';
31+
import { CrowdstrikeGetScriptsResponseSchema } from '../../../common/crowdstrike/schema';
3032
import {
3133
CrowdstrikeHostActionsParamsSchema,
3234
CrowdstrikeGetAgentsParamsSchema,
3335
CrowdstrikeHostActionsResponseSchema,
3436
RelaxedCrowdstrikeBaseApiResponseSchema,
3537
CrowdstrikeRTRCommandParamsSchema,
3638
CrowdstrikeExecuteRTRResponseSchema,
37-
CrowdstrikeGetScriptsParamsSchema,
3839
CrowdstrikeApiDoNotValidateResponsesSchema,
3940
} from '../../../common/crowdstrike/schema';
4041
import { SUB_ACTION } from '../../../common/crowdstrike/constants';
@@ -76,7 +77,7 @@ export class CrowdstrikeConnector extends SubActionConnector<
7677
batchExecuteRTR: string;
7778
batchActiveResponderExecuteRTR: string;
7879
batchAdminExecuteRTR: string;
79-
getRTRCloudScriptsDetails: string;
80+
getRTRCloudScripts: string;
8081
};
8182

8283
constructor(
@@ -95,7 +96,7 @@ export class CrowdstrikeConnector extends SubActionConnector<
9596
batchExecuteRTR: `${this.config.url}/real-time-response/combined/batch-command/v1`,
9697
batchActiveResponderExecuteRTR: `${this.config.url}/real-time-response/combined/batch-active-responder-command/v1`,
9798
batchAdminExecuteRTR: `${this.config.url}/real-time-response/combined/batch-admin-command/v1`,
98-
getRTRCloudScriptsDetails: `${this.config.url}/real-time-response/entities/scripts/v1`,
99+
getRTRCloudScripts: `${this.config.url}/real-time-response/entities/scripts/v1`,
99100
};
100101

101102
if (!CrowdstrikeConnector.base64encodedToken) {
@@ -146,11 +147,10 @@ export class CrowdstrikeConnector extends SubActionConnector<
146147
method: 'batchAdminExecuteRTR',
147148
schema: CrowdstrikeRTRCommandParamsSchema, // Define a proper schema for the command
148149
});
149-
// temporary to fetch scripts and help testing
150150
this.registerSubAction({
151151
name: SUB_ACTION.GET_RTR_CLOUD_SCRIPTS,
152152
method: 'getRTRCloudScripts',
153-
schema: CrowdstrikeGetScriptsParamsSchema,
153+
schema: CrowdstrikeRTRCommandParamsSchema, // Empty schema - this request do not have any parameters
154154
});
155155
}
156156
}
@@ -371,18 +371,16 @@ export class CrowdstrikeConnector extends SubActionConnector<
371371
);
372372
}
373373

374-
// TODO: for now just for testing purposes, will be a part of a following PR
375374
public async getRTRCloudScripts(
376-
payload: CrowdstrikeGetAgentsParams,
375+
payload: {},
377376
connectorUsageCollector: ConnectorUsageCollector
378-
): Promise<CrowdstrikeGetAgentOnlineStatusResponse> {
379-
// @ts-expect-error will be a part of the next PR
380-
return this.crowdstrikeApiRequest(
377+
): Promise<CrowdstrikeGetScriptsResponse> {
378+
return await this.crowdstrikeApiRequest(
381379
{
382-
url: this.urls.getRTRCloudScriptsDetails,
380+
url: this.urls.getRTRCloudScripts,
383381
method: 'GET',
384382
paramsSerializer,
385-
responseSchema: RelaxedCrowdstrikeBaseApiResponseSchema,
383+
responseSchema: CrowdstrikeGetScriptsResponseSchema,
386384
},
387385
connectorUsageCollector
388386
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { schema, type TypeOf } from '@kbn/config-schema';
9+
import { AgentTypeSchemaLiteral } from '..';
10+
11+
export const CustomScriptsRequestSchema = {
12+
query: schema.object({
13+
agentType: schema.maybe(
14+
schema.oneOf(
15+
// @ts-expect-error TS2769: No overload matches this call
16+
AgentTypeSchemaLiteral,
17+
{
18+
defaultValue: 'endpoint',
19+
}
20+
)
21+
),
22+
}),
23+
};
24+
25+
export type CustomScriptsRequestQueryParams = TypeOf<typeof CustomScriptsRequestSchema.query>;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export const EXECUTE_ROUTE = `${BASE_ENDPOINT_ACTION_ROUTE}/execute`;
9797
export const UPLOAD_ROUTE = `${BASE_ENDPOINT_ACTION_ROUTE}/upload`;
9898
export const SCAN_ROUTE = `${BASE_ENDPOINT_ACTION_ROUTE}/scan`;
9999
export const RUN_SCRIPT_ROUTE = `${BASE_ENDPOINT_ACTION_ROUTE}/run_script`;
100+
export const CUSTOM_SCRIPTS_ROUTE = `${BASE_ENDPOINT_ACTION_ROUTE}/custom_scripts`;
100101

101102
/** Endpoint Actions Routes */
102103
export const ENDPOINT_ACTION_LOG_ROUTE = `${BASE_ENDPOINT_ROUTE}/action_log/{agent_id}`;

0 commit comments

Comments
 (0)