Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] [EDR Workflows] Crowdstrike - Add more routes and responses to mocked server (#192881) #193119

Merged
merged 1 commit into from
Sep 17, 2024
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 @@ -10,6 +10,7 @@ import type {
CrowdstrikeGetAgentsResponse,
} from '@kbn/stack-connectors-plugin/common/crowdstrike/types';
import { merge } from 'lodash';
import { TEST_AGENT_ID, TEST_CID_ID } from './routes/utils';

export const createCrowdstrikeGetAgentsApiResponseMock = (
data: CrowdstrikeBaseApiResponse['resources'][number]
Expand All @@ -18,117 +19,134 @@ export const createCrowdstrikeGetAgentsApiResponseMock = (
meta: {
query_time: 0.001831479,
powered_by: 'device-api',
trace_id: '4567898765-432423432432-42342342',
trace_id: 'xxx',
},
errors: null,
resources: data,
};
};

export const createCrowdstrikeErrorResponseMock = (error: object) => {
return {
meta: {
query_time: 0.001831479,
powered_by: 'device-api',
trace_id: 'xxx',
},
errors: [error],
};
};

export const createCrowdstrikeAgentDetailsMock = (
overrides: Partial<CrowdstrikeGetAgentsResponse['resources'][number]> = {}
): CrowdstrikeGetAgentsResponse['resources'][number] => {
return merge(
{
device_id: '5f4ed7ec2690431f8fa79213268779cb',
cid: '234567890',
device_id: TEST_AGENT_ID,
cid: TEST_CID_ID,
agent_load_flags: '0',
agent_local_time: '2024-03-18T22:21:00.173Z',
agent_version: '7.07.16206.0',
bios_manufacturer: 'Amazon EC2',
bios_version: '1.0',
config_id_base: '65994753',
config_id_build: '16206',
config_id_platform: '8',
cpu_signature: '8392466',
cpu_vendor: '1',
external_ip: '18.157.150.216',
mac_address: '03-f4-f4-f4-f4',
instance_id: 'i-456789',
service_provider: 'AWS_EC2_V2',
service_provider_account_id: '23456789',
hostname: 'Crowdstrike-1460',
first_seen: '2024-03-15T13:18:56Z',
last_login_timestamp: '2024-03-15T22:11:47Z',
last_login_user: 'testuser',
last_login_uid: '1002',
last_seen: '2024-03-20T07:19:01Z',
local_ip: '172.31.200.45',
major_version: '5',
minor_version: '14',
os_version: 'RHEL 9.3',
agent_local_time: '2024-09-08T06:07:00.326Z',
agent_version: '7.18.17106.0',
bios_manufacturer: 'EFI Development Kit II / OVMF',
bios_version: '0.0.0',
config_id_base: '65994763',
config_id_build: '17106',
config_id_platform: '128',
cpu_signature: '4294967295',
cpu_vendor: '3',
external_ip: '79.184.246.19',
mac_address: '52-54-00-09-42-a6',
hostname: 'cs-falcon',
filesystem_containment_status: 'normal',
first_login_timestamp: '2024-08-19T08:37:15Z',
first_login_user: 'ubuntu',
first_seen: '2024-08-19T08:37:17Z',
last_login_timestamp: '2024-08-19T08:37:15Z',
last_login_user: 'ubuntu',
last_login_uid: '1000',
last_seen: '2024-09-10T09:32:58Z',
local_ip: '192.168.80.7',
major_version: '6',
minor_version: '8',
os_version: 'Ubuntu 24.04',
platform_id: '3',
platform_name: 'Linux',
policies: [
{
policy_type: 'prevention',
policy_id: '234234234234',
policy_id: 'test_prevention_policy_id',
applied: true,
settings_hash: 'f0e04444',
assigned_date: '2024-03-15T13:20:02.25821602Z',
applied_date: '2024-03-15T13:20:16.804783955Z',
settings_hash: 'test2984',
assigned_date: '2024-08-19T08:40:24.454802663Z',
applied_date: '2024-08-19T08:46:46.169115065Z',
rule_groups: [],
},
],
reduced_functionality_mode: 'no',
device_policies: {
prevention: {
policy_type: 'prevention',
policy_id: '234234234234',
policy_id: 'test_prevention_policy_id',
applied: true,
settings_hash: 'f0e04444',
assigned_date: '2024-03-15T13:20:02.25821602Z',
applied_date: '2024-03-15T13:20:16.804783955Z',
settings_hash: 'test2984',
assigned_date: '2024-08-19T08:40:24.454802663Z',
applied_date: '2024-08-19T08:46:46.169115065Z',
rule_groups: [],
},
sensor_update: {
policy_type: 'sensor-update',
policy_id: '234234234234',
policy_id: 'test_sensor_update_policy_id',
applied: true,
settings_hash: 'tagged|5;',
assigned_date: '2024-03-15T13:20:02.258765734Z',
applied_date: '2024-03-15T13:23:53.773752711Z',
settings_hash: 'test3a5bb',
assigned_date: '2024-08-19T08:40:24.406563043Z',
applied_date: '2024-08-19T08:44:54.277815271Z',
uninstall_protection: 'UNKNOWN',
},
global_config: {
policy_type: 'globalconfig',
policy_id: '234234234234',
policy_id: 'test_global_config_policy_id',
applied: true,
settings_hash: 'f0e04444',
assigned_date: '2024-03-18T22:21:01.50638371Z',
applied_date: '2024-03-18T22:21:30.565040189Z',
settings_hash: 'testa5bc',
assigned_date: '2024-09-08T04:54:07.410501178Z',
applied_date: '2024-09-08T04:55:06.81648557Z',
},
remote_response: {
policy_type: 'remote-response',
policy_id: '234234234234',
policy_id: 'test_remote_response_policy_id',
applied: true,
settings_hash: 'test205c',
assigned_date: '2024-08-19T08:48:00.144480664Z',
applied_date: '2024-08-19T08:55:01.036602542Z',
},
'host-retention': {
policy_type: 'host-retention',
policy_id: 'test_host-retention_policy_id',
applied: true,
settings_hash: 'f0e04444',
assigned_date: '2024-03-15T13:20:02.258285018Z',
applied_date: '2024-03-15T13:20:17.016591803Z',
settings_hash: 'testfghjk',
assigned_date: '2024-08-19T08:40:24.444810716Z',
applied_date: '2024-08-19T08:44:54.577562462Z',
},
},
groups: [],
group_hash: '45678909876545678',
groups: ['test123', 'test456'],
group_hash: 'test123',
product_type_desc: 'Server',
provision_status: 'NotProvisioned',
serial_number: '345678765-35d6-e704-1723-423423432',
status: 'containment_pending',
system_manufacturer: 'Amazon EC2',
system_product_name: 't3a.medium',
provision_status: 'Provisioned',
status: 'normal',
system_manufacturer: 'QEMU',
system_product_name: 'QEMU Virtual Machine',
tags: [],
modified_timestamp: '2024-03-20T07:19:45Z',
modified_timestamp: '2024-09-10T09:33:21Z',
meta: {
version: '484',
version_string: '9:33384301139',
version: '552',
version_string: '1:1815077394',
},
zone_group: 'eu-central-1a',
kernel_version: '5.14.0-234234el9_3.x86_64',
kernel_version: '6.8.0-41-generic',
chassis_type: '1',
chassis_type_desc: 'Other',
connection_ip: '172.31.200.45',
default_gateway_ip: '172.31.200.1',
connection_mac_address: '02-e8-f1-0e-b7-c4',
linux_sensor_mode: 'Kernel Mode',
connection_ip: '192.168.80.7',
default_gateway_ip: '192.168.80.1',
connection_mac_address: '52-54-00-09-42-a6',
linux_sensor_mode: 'User Mode',
deployment_type: 'Standard',
},
overrides
Expand All @@ -140,8 +158,10 @@ export const createCrowdstrikeGetAgentOnlineStatusDetailsMock: (
) => CrowdstrikeGetAgentOnlineStatusResponse['resources'][number] = (overrides) => {
return merge(
{
id: TEST_AGENT_ID,
cid: TEST_CID_ID,
last_seen: '2024-09-10T09:59:56Z',
state: 'online',
id: '5f4ed7ec2690431f8fa79213268779cb',
},
overrides
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { buildCrowdstrikeRoutePath, TEST_AGENT_ID, TEST_BATCH_ID, TEST_SESSION_ID } from './utils';
import type { ExternalEdrServerEmulatorRouteHandlerMethod } from '../../../external_edr_server_emulator.types';
import type { EmulatorServerRouteDefinition } from '../../../lib/emulator_server.types';

export const batchInitRTRSessionRoute = (): EmulatorServerRouteDefinition => {
return {
path: buildCrowdstrikeRoutePath('/real-time-response/combined/batch-init-session/v1'),
method: 'POST',
handler: batchInitSessionSuccessHandler,
};
};
// @ts-expect-error - example of error response
const initSessionWrongHostIdError = async () => {
return {
meta: {
query_time: 0.244284399,
powered_by: 'empower-api',
trace_id: 'xxx',
},
batch_id: '',
resources: {
[TEST_AGENT_ID]: {
session_id: '',
complete: false,
stdout: '',
stderr: '',
aid: TEST_AGENT_ID,
errors: [
{
code: 500,
message: `uuid: incorrect UUID length 47 in string ${TEST_AGENT_ID}`,
},
],
query_time: 0,
offline_queued: false,
},
},
errors: [
{
code: 404,
message: 'no successful hosts initialized on RTR',
},
],
};
};
// @ts-expect-error - example of error response
const initSessionMissingIdsError = async () => {
return {
meta: {
query_time: 0.00034664,
powered_by: 'empower-api',
trace_id: 'xxx',
},
batch_id: '',
resources: {},
errors: [
{
code: 400,
message:
'Invalid number of hosts in request: 0. Must be an integer greater than 0 and less than or equal to 10000',
},
],
};
};

const batchInitSessionSuccessHandler: ExternalEdrServerEmulatorRouteHandlerMethod<
{},
{}
> = async () => {
return {
meta: {
query_time: 1.067267552,
powered_by: 'empower-api',
trace_id: 'xxx',
},
batch_id: TEST_BATCH_ID,
resources: {
[TEST_AGENT_ID]: {
session_id: TEST_SESSION_ID,
task_id: 'xxx',
complete: true,
stdout: '/',
stderr: '',
base_command: 'pwd',
aid: TEST_AGENT_ID,
errors: [],
query_time: 0,
offline_queued: false,
},
},
errors: [],
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { buildCrowdstrikeRoutePath, TEST_AGENT_ID, TEST_SESSION_ID } from './utils';
import type { ExternalEdrServerEmulatorRouteHandlerMethod } from '../../../external_edr_server_emulator.types';
import type { EmulatorServerRouteDefinition } from '../../../lib/emulator_server.types';

export const batchRTRRefreshSessionRoute = (): EmulatorServerRouteDefinition => {
return {
path: buildCrowdstrikeRoutePath('/real-time-response/combined/batch-refresh-session/v1'),
method: 'POST',
handler: batchRTRRefreshSessionHandler,
};
};

// @ts-expect-error - example of error response
const batchRTRRefreshSessionInvalidSessionError = async () => {
return {
meta: {
query_time: 0.001031577,
powered_by: 'empower-api',
trace_id: 'xxx',
},
resources: {},
errors: [
{
code: 400,
message: 'no hosts in this batch session',
},
],
};
};

const batchRTRRefreshSessionHandler: ExternalEdrServerEmulatorRouteHandlerMethod<
{},
{}
> = async () => {
return {
meta: {
query_time: 0.068379923,
powered_by: 'empower-api',
trace_id: 'xxx',
},
resources: {
[TEST_AGENT_ID]: {
aid: TEST_AGENT_ID,
session_id: TEST_SESSION_ID,
errors: [],
},
},
errors: [],
};
};
Loading