Skip to content

Commit ce5bbf6

Browse files
daryakovalShellyber
authored andcommitted
Cs falcon fetch limit issue (demisto#29411)
* fixed the parameter that send as a limit * update rn * update test playbook * Update Packs/CrowdStrikeFalcon/ReleaseNotes/1_11_7.md Co-authored-by: Shelly Tzohar <[email protected]> * fixing test playbook * adding sort incidents by the ids order; fix time field issue * rename rn * bump version * added unitest * fix rn * save unitest fix * save format * save unitest fix * update docker --------- Co-authored-by: Shelly Tzohar <[email protected]>
1 parent 508bd59 commit ce5bbf6

File tree

5 files changed

+100
-34
lines changed

5 files changed

+100
-34
lines changed

Diff for: Packs/CrowdStrikeFalcon/Integrations/CrowdStrikeFalcon/CrowdStrikeFalcon.py

+37-10
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def detection_to_incident(detection):
529529

530530
incident = {
531531
'name': 'Detection ID: ' + str(detection.get('detection_id')),
532-
'occurred': str(detection.get('created_timestamp')),
532+
'occurred': str(detection.get('first_behavior')),
533533
'rawJSON': json.dumps(detection),
534534
'severity': severity_string_to_int(detection.get('max_severity_displayname'))
535535
}
@@ -1306,7 +1306,7 @@ def get_fetch_detections(last_created_timestamp=None, filter_arg=None, offset: i
13061306
if filter_arg:
13071307
params['filter'] = filter_arg
13081308
elif last_created_timestamp:
1309-
params['filter'] = f"created_timestamp:>'{last_created_timestamp}'"
1309+
params['filter'] = f"first_behavior:>'{last_created_timestamp}'"
13101310
elif last_updated_timestamp:
13111311
params['filter'] = f"date_updated:>'{last_updated_timestamp}'"
13121312

@@ -2500,6 +2500,21 @@ def migrate_last_run(last_run: dict[str, str] | list[dict]) -> list[dict]:
25002500
return [updated_last_run_detections, updated_last_run_incidents, {}]
25012501

25022502

2503+
def sort_incidents_summaries_by_ids_order(ids_order, full_incidents, id_field):
2504+
""" sort incidents list by the order that ids_order list has
2505+
2506+
Args:
2507+
ids_order: list of ids
2508+
full_incidents: list of incidents
2509+
id_field: name of the id field
2510+
Returns:
2511+
list[dict]: New last run object.
2512+
"""
2513+
incidents_by_id = {i[id_field]: i for i in full_incidents}
2514+
incidents = [incidents_by_id[i] for i in ids_order]
2515+
return incidents
2516+
2517+
25032518
def fetch_incidents():
25042519
incidents: list = []
25052520
detections: list = []
@@ -2527,7 +2542,7 @@ def fetch_incidents():
25272542
incident_type = 'detection'
25282543
fetch_query = demisto.params().get('fetch_query')
25292544
if fetch_query:
2530-
fetch_query = f"created_timestamp:>'{start_fetch_time}'+{fetch_query}"
2545+
fetch_query = f"first_behavior:>'{start_fetch_time}'+{fetch_query}"
25312546
detections_ids = demisto.get(get_fetch_detections(filter_arg=fetch_query, limit=fetch_limit), 'resources')
25322547
else:
25332548
detections_ids = demisto.get(get_fetch_detections(last_created_timestamp=start_fetch_time, limit=fetch_limit),
@@ -2536,18 +2551,22 @@ def fetch_incidents():
25362551
raw_res = get_detections_entities(detections_ids)
25372552

25382553
if raw_res is not None and "resources" in raw_res:
2539-
for detection in demisto.get(raw_res, "resources"):
2554+
full_detections = demisto.get(raw_res, "resources")
2555+
sorted_detections = sort_incidents_summaries_by_ids_order(ids_order=detections_ids,
2556+
full_incidents=full_detections,
2557+
id_field='detection_id')
2558+
for detection in sorted_detections:
25402559
detection['incident_type'] = incident_type
25412560
demisto.debug(
25422561
f"CrowdStrikeFalconMsg: Detection {detection['detection_id']} "
2543-
f"was fetched which was created in {detection['created_timestamp']}")
2562+
f"was fetched which was created in {detection['first_behavior']}")
25442563
incident = detection_to_incident(detection)
25452564

25462565
detections.append(incident)
25472566

25482567
detections = filter_incidents_by_duplicates_and_limit(incidents_res=detections,
25492568
last_run=current_fetch_info_detections,
2550-
fetch_limit=fetch_limit, id_field='name')
2569+
fetch_limit=INCIDENTS_PER_FETCH, id_field='name')
25512570

25522571
for detection in detections:
25532572
occurred = dateparser.parse(detection["occurred"])
@@ -2583,13 +2602,17 @@ def fetch_incidents():
25832602
if incidents_ids:
25842603
raw_res = get_incidents_entities(incidents_ids)
25852604
if raw_res is not None and "resources" in raw_res:
2586-
for incident in demisto.get(raw_res, "resources"):
2605+
full_incidents = demisto.get(raw_res, "resources")
2606+
sorted_incidents = sort_incidents_summaries_by_ids_order(ids_order=incidents_ids,
2607+
full_incidents=full_incidents,
2608+
id_field='incident_id')
2609+
for incident in sorted_incidents:
25872610
incident['incident_type'] = incident_type
25882611
incident_to_context = incident_to_incident_context(incident)
25892612
incidents.append(incident_to_context)
25902613

25912614
incidents = filter_incidents_by_duplicates_and_limit(incidents_res=incidents, last_run=current_fetch_info_incidents,
2592-
fetch_limit=fetch_limit, id_field='name')
2615+
fetch_limit=INCIDENTS_PER_FETCH, id_field='name')
25932616
for incident in incidents:
25942617
occurred = dateparser.parse(incident["occurred"])
25952618
if occurred:
@@ -2617,14 +2640,18 @@ def fetch_incidents():
26172640
if idp_detections_ids:
26182641
raw_res = get_idp_detection_entities(idp_detections_ids)
26192642
if "resources" in raw_res:
2620-
for idp_detection in demisto.get(raw_res, "resources"):
2643+
full_detections = demisto.get(raw_res, "resources")
2644+
sorted_detections = sort_incidents_summaries_by_ids_order(ids_order=idp_detections_ids,
2645+
full_incidents=full_detections,
2646+
id_field='composite_id')
2647+
for idp_detection in sorted_detections:
26212648
idp_detection['incident_type'] = IDP_DETECTION
26222649
idp_detection_to_context = idp_detection_to_incident_context(idp_detection)
26232650
idp_detections.append(idp_detection_to_context)
26242651

26252652
idp_detections = filter_incidents_by_duplicates_and_limit(incidents_res=idp_detections,
26262653
last_run=current_fetch_info_idp_detections,
2627-
fetch_limit=fetch_limit, id_field='name')
2654+
fetch_limit=INCIDENTS_PER_FETCH, id_field='name')
26282655
updated_last_run = update_last_run_object(last_run=current_fetch_info_idp_detections, incidents=idp_detections,
26292656
fetch_limit=fetch_limit,
26302657
start_fetch_time=start_fetch_time, end_fetch_time=end_fetch_time,

Diff for: Packs/CrowdStrikeFalcon/Integrations/CrowdStrikeFalcon/CrowdStrikeFalcon.yml

+17-17
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ script:
412412
- description: Any commands run against an offline-queued session will be queued up and executed when the host comes online.
413413
name: queue_offline
414414
defaultValue: false
415-
- description: A comma-separated list of host agent IDs to run commands for. (Can be retrieved by running the 'cs-falcon-search-device' command.)
415+
- description: A comma-separated list of host agent IDs to run commands for. (Can be retrieved by running the 'cs-falcon-search-device' command.).
416416
name: host_ids
417417
required: true
418418
- description: The type of command to run.
@@ -423,7 +423,7 @@ script:
423423
required: true
424424
- auto: PREDEFINED
425425
defaultValue: read
426-
description: 'The scope to run the command for. Possible values are: "read", "write", and "admin". (NOTE: In order to run the CrowdStrike RTR `put` command, it is necessary to pass `scope=admin`.)'
426+
description: 'The scope to run the command for. Possible values are: "read", "write", and "admin". (NOTE: In order to run the CrowdStrike RTR `put` command, it is necessary to pass `scope=admin`.).'
427427
name: scope
428428
predefined:
429429
- read
@@ -491,7 +491,7 @@ script:
491491
- description: The file entry ID to upload.
492492
name: entry_id
493493
required: true
494-
description: Uploads a file to the CrowdStrike cloud. (Can be used for the RTR 'put' command.)
494+
description: Uploads a file to the CrowdStrike cloud. (Can be used for the RTR 'put' command.).
495495
name: cs-falcon-upload-file
496496
- arguments:
497497
- description: The ID of the file to delete. (The ID of the file can be retrieved by running the 'cs-falcon-list-files' command).
@@ -500,7 +500,7 @@ script:
500500
description: Deletes a file based on the provided ID. Can delete only one file at a time.
501501
name: cs-falcon-delete-file
502502
- arguments:
503-
- description: A comma-separated list of file IDs to get. (The list of file IDs can be retrieved by running the 'cs-falcon-list-files' command.)
503+
- description: A comma-separated list of file IDs to get. (The list of file IDs can be retrieved by running the 'cs-falcon-list-files' command.).
504504
name: file_id
505505
required: true
506506
description: Returns files based on the provided IDs. These files are used for the RTR 'put' command.
@@ -531,7 +531,7 @@ script:
531531
description: The full name of the file.
532532
type: String
533533
- contextPath: CrowdStrike.File.Permission
534-
description: 'The permission type of the file. Possible values are: "private", which is used only by the user who uploaded it, "group", which is used by all RTR Admins, and "public", which is used by all active-responders and RTR admins'
534+
description: 'The permission type of the file. Possible values are: "private", which is used only by the user who uploaded it, "group", which is used by all RTR Admins, and "public", which is used by all active-responders and RTR admins.'
535535
type: String
536536
- contextPath: CrowdStrike.File.SHA256
537537
description: The SHA-256 hash of the file.
@@ -595,7 +595,7 @@ script:
595595
description: The size of the file in bytes.
596596
type: Number
597597
- arguments:
598-
- description: A comma-separated list of script IDs to return. (The script IDs can be retrieved by running the 'cs-falcon-list-scripts' command.)
598+
- description: A comma-separated list of script IDs to return. (The script IDs can be retrieved by running the 'cs-falcon-list-scripts' command.).
599599
name: script_id
600600
required: true
601601
description: Returns custom scripts based on the provided ID. Used for the RTR 'runscript' command.
@@ -641,7 +641,7 @@ script:
641641
description: Whether the user has write access to the script.
642642
type: Boolean
643643
- arguments:
644-
- description: The script ID to delete. (Script IDs can be retrieved by running the 'cs-falcon-list-scripts' command.)
644+
- description: The script ID to delete. (Script IDs can be retrieved by running the 'cs-falcon-list-scripts' command.).
645645
name: script_id
646646
required: true
647647
description: Deletes a custom-script based on the provided ID. Can delete only one script at a time.
@@ -692,7 +692,7 @@ script:
692692
- arguments:
693693
- description: The name of the script to run.
694694
name: script_name
695-
- description: A comma-separated list of host agent IDs to run commands. (The list of host agent IDs can be retrieved by running the 'cs-falcon-search-device' command.)
695+
- description: A comma-separated list of host agent IDs to run commands. (The list of host agent IDs can be retrieved by running the 'cs-falcon-search-device' command.).
696696
name: host_ids
697697
required: true
698698
- description: The PowerShell script code to run.
@@ -1290,7 +1290,7 @@ script:
12901290
description: The identity of the user/process who last updated the IOC.
12911291
type: string
12921292
- contextPath: CrowdStrike.NextPageToken
1293-
description: A pagination token used with the limit parameter to manage pagination of results
1293+
description: A pagination token used with the limit parameter to manage pagination of results.
12941294
- arguments:
12951295
- auto: PREDEFINED
12961296
description: 'The IOC type to retrieve. Possible values are: "sha256", "sha1", "md5", "domain", "ipv4", and "ipv6". Either ioc_id or ioc_type and value must be provided.'
@@ -2274,7 +2274,7 @@ script:
22742274
- description: The ID of the host group.
22752275
name: host_group_id
22762276
required: true
2277-
- description: A comma-separated list of host agent IDs to run commands. (The list of host agent IDs can be retrieved by running the 'cs-falcon-search-device' command.)
2277+
- description: A comma-separated list of host agent IDs to run commands. (The list of host agent IDs can be retrieved by running the 'cs-falcon-search-device' command.).
22782278
isArray: true
22792279
name: host_ids
22802280
required: true
@@ -2309,7 +2309,7 @@ script:
23092309
- description: The ID of the host group.
23102310
name: host_group_id
23112311
required: true
2312-
- description: A comma-separated list of host agent IDs to run commands. (The list of host agent IDs can be retrieved by running the 'cs-falcon-search-device' command.)
2312+
- description: A comma-separated list of host agent IDs to run commands. (The list of host agent IDs can be retrieved by running the 'cs-falcon-search-device' command.).
23132313
isArray: true
23142314
name: host_ids
23152315
required: true
@@ -2627,7 +2627,7 @@ script:
26272627
description: Updates the remote incident or detection with local incident or detection changes. This method is only used for debugging purposes and will not update the current incident or detection.
26282628
name: update-remote-system
26292629
- arguments:
2630-
- description: Limit the vulnerabilities returned to specific properties. Each value must be enclosed in single quotes and placed immediately after the colon with no space. For example, 'filter=status:'open'+cve.id:['CVE-2013-3900','CVE-2021-1675']'
2630+
- description: Limit the vulnerabilities returned to specific properties. Each value must be enclosed in single quotes and placed immediately after the colon with no space. For example, 'filter=status:'open'+cve.id:['CVE-2013-3900','CVE-2021-1675']'.
26312631
name: filter
26322632
- description: Unique agent identifier (AID) of a sensor.
26332633
name: aid
@@ -2652,7 +2652,7 @@ script:
26522652
- description: Type of host a sensor is running on.
26532653
name: host_type
26542654
isArray: true
2655-
- description: Filter for vulnerabilities based on the number of days since a host last connected to CrowdStrike Falcon. Enter a numeric value from 3 to 45 to indicate the number of days you want to look back. Example- last_seen_within:10
2655+
- description: Filter for vulnerabilities based on the number of days since a host last connected to CrowdStrike Falcon. Enter a numeric value from 3 to 45 to indicate the number of days you want to look back. Example- last_seen_within:10.
26562656
name: last_seen_within
26572657
- auto: PREDEFINED
26582658
description: Indicates if the vulnerability is suppressed by a suppression rule.
@@ -3864,7 +3864,7 @@ script:
38643864
description: A unique identifier for the scan profile used in the scan.
38653865
type: String
38663866
- contextPath: CrowdStrike.ODSScanHost.host_id
3867-
description: A unique identifier for the host that was scanned
3867+
description: A unique identifier for the host that was scanned.
38683868
type: String
38693869
- contextPath: CrowdStrike.ODSScanHost.host_scan_id
38703870
description: A unique identifier for the scan that was performed on the host.
@@ -3882,10 +3882,10 @@ script:
38823882
description: The number of files that were skipped during the scan.
38833883
type: Number
38843884
- contextPath: CrowdStrike.ODSScanHost.status
3885-
description: The status of the scan. (e.g., "completed", "pending", "cancelled", "running", or "failed")
3885+
description: The status of the scan. (e.g., "completed", "pending", "cancelled", "running", or "failed").
38863886
type: String
38873887
- contextPath: CrowdStrike.ODSScanHost.severity
3888-
description: A severity score assigned to the scan, ranging from 0 to 100
3888+
description: A severity score assigned to the scan, ranging from 0 to 100.
38893889
type: Number
38903890
- contextPath: CrowdStrike.ODSScanHost.started_on
38913891
description: The date and time when the scan was started.
@@ -4375,7 +4375,7 @@ script:
43754375
- contextPath: CrowdStrike.IDPEntity.EmailAddresses
43764376
description: The identity entity email address.
43774377
type: String
4378-
dockerimage: demisto/py3-tools:1.0.0.72621
4378+
dockerimage: demisto/py3-tools:1.0.0.73055
43794379
isfetch: true
43804380
ismappable: true
43814381
isremotesyncin: true

0 commit comments

Comments
 (0)