Skip to content

Commit 0eebfd9

Browse files
authored
Merge pull request #203 from splunk/more_data_source_updates
The failures against ESCU are expected because data_source changes have not yet been made in the develop branch of that repo. As such, we accept those failures and merge anyway.
2 parents 2eba93e + bf3b683 commit 0eebfd9

File tree

8 files changed

+82
-64
lines changed

8 files changed

+82
-64
lines changed

contentctl/actions/build.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from contentctl.output.ba_yml_output import BAYmlOutput
1212
from contentctl.output.api_json_output import ApiJsonOutput
1313
from contentctl.output.data_source_writer import DataSourceWriter
14+
from contentctl.objects.lookup import Lookup
1415
import pathlib
1516
import json
1617
import datetime
@@ -34,7 +35,14 @@ def execute(self, input_dto: BuildInputDto) -> DirectorOutputDto:
3435
updated_conf_files:set[pathlib.Path] = set()
3536
conf_output = ConfOutput(input_dto.config)
3637

37-
DataSourceWriter.writeDataSourceCsv(input_dto.director_output_dto.data_sources, str(input_dto.config.path) + "/lookups/data_sources.csv")
38+
# Construct a special lookup whose CSV is created at runtime and
39+
# written directly into the output folder. It is created with model_construct,
40+
# not model_validate, because the CSV does not exist yet.
41+
data_sources_lookup_csv_path = input_dto.config.getPackageDirectoryPath() / "lookups" / "data_sources.csv"
42+
DataSourceWriter.writeDataSourceCsv(input_dto.director_output_dto.data_sources, data_sources_lookup_csv_path)
43+
input_dto.director_output_dto.addContentToDictMappings(Lookup.model_construct(description= "A lookup file that will contain the data source objects for detections.",
44+
filename=data_sources_lookup_csv_path,
45+
name="data_sources"))
3846

3947
updated_conf_files.update(conf_output.writeHeaders())
4048
updated_conf_files.update(conf_output.writeObjects(input_dto.director_output_dto.detections, SecurityContentType.detections))

contentctl/actions/initialize.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def execute(self, config: test) -> None:
2929
('../templates/deployments/', 'deployments'),
3030
('../templates/detections/', 'detections'),
3131
('../templates/data_sources/', 'data_sources'),
32-
('../templates/event_sources/', 'event_sources'),
3332
('../templates/macros/','macros'),
3433
('../templates/stories/', 'stories'),
3534
]:

contentctl/input/director.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def addContentToDictMappings(self, content: SecurityContentObject):
6868
# for this function we prepend 'SSA ' to the name.
6969
content_name = f"SSA {content_name}"
7070

71-
if content_name in self.name_to_content_map and isinstance(self.name_to_content_map[content_name], type(content)):
71+
if content_name in self.name_to_content_map:
7272
raise ValueError(
7373
f"Duplicate name '{content_name}' with paths:\n"
7474
f" - {content.file_path}\n"
@@ -131,6 +131,16 @@ def execute(self, input_dto: validate) -> None:
131131
self.createSecurityContent(SecurityContentType.detections)
132132
self.createSecurityContent(SecurityContentType.ssa_detections)
133133

134+
135+
from contentctl.objects.abstract_security_content_objects.detection_abstract import MISSING_SOURCES
136+
if len(MISSING_SOURCES) > 0:
137+
missing_sources_string = "\n 🟡 ".join(sorted(list(MISSING_SOURCES)))
138+
print("WARNING: The following data_sources have been used in detections, but are not yet defined.\n"
139+
"This is not yet an error since not all data_sources have been defined, but will be convered to an error soon:\n 🟡 "
140+
f"{missing_sources_string}")
141+
else:
142+
print("No missing data_sources!")
143+
134144
def createSecurityContent(self, contentType: SecurityContentType) -> None:
135145
if contentType == SecurityContentType.ssa_detections:
136146
files = Utils.get_all_yml_files_from_directory(

contentctl/input/yml_reader.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ def load_file(file_path: pathlib.Path, add_fields=True, STRICT_YML_CHECKING=Fals
4040
if add_fields == False:
4141
return yml_obj
4242

43-
try:
44-
yml_obj['file_path'] = str(file_path)
45-
except Exception as e:
46-
import code
47-
code.interact(local=locals())
43+
44+
yml_obj['file_path'] = str(file_path)
45+
4846

4947
return yml_obj

contentctl/objects/abstract_security_content_objects/detection_abstract.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from contentctl.objects.enums import ProvidingTechnology
3030
from contentctl.enrichments.cve_enrichment import CveEnrichmentObj
3131

32+
MISSING_SOURCES:set[str] = set()
3233

3334
class Detection_Abstract(SecurityContentObject):
3435
model_config = ConfigDict(use_enum_values=True)
@@ -402,12 +403,16 @@ def model_post_init(self, ctx:dict[str,Any]):
402403
sources = sorted(list(updated_data_source_names))
403404

404405
matched_data_sources:list[DataSource] = []
405-
missing_sources: list[str] = []
406+
missing_sources:list[str] = []
406407
for source in sources:
407408
try:
408409
matched_data_sources += DataSource.mapNamesToSecurityContentObjects([source], director)
409410
except Exception as data_source_mapping_exception:
410-
missing_sources.append(source)
411+
# We gobble this up and add it to a global set so that we
412+
# can print it ONCE at the end of the build of datasources.
413+
# This will be removed later as per the note below
414+
MISSING_SOURCES.add(source)
415+
411416
if len(missing_sources) > 0:
412417
# This will be changed to ValueError when we have a complete list of data sources
413418
print(f"WARNING: The following exception occurred when mapping the data_source field to DataSource objects:{missing_sources}")

contentctl/objects/abstract_security_content_objects/security_content_object_abstract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ def mapNamesToSecurityContentObjects(cls, v: list[str], director:Union[DirectorO
125125
errors:list[str] = []
126126
if len(missing_objects) > 0:
127127
errors.append(f"Failed to find the following '{cls.__name__}': {missing_objects}")
128-
if len(missing_objects) > 0:
128+
if len(mistyped_objects) > 0:
129129
for mistyped_object in mistyped_objects:
130-
errors.append(f"'{mistyped_object.name}' expected to have type '{type(Self)}', but actually had type '{type(mistyped_object)}'")
130+
errors.append(f"'{mistyped_object.name}' expected to have type '{cls}', but actually had type '{type(mistyped_object)}'")
131131

132132
if len(errors) > 0:
133133
error_string = "\n - ".join(errors)

contentctl/templates/data_sources/Sysmon_EventID.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

contentctl/templates/event_sources/Sysmon_EventID_1.yml renamed to contentctl/templates/data_sources/sysmon_eventid_1.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
name: Sysmon EventID 1
22
id: b375f4d1-d7ca-4bc0-9103-294825c0af17
3+
version: 1
4+
date: '2024-07-18'
35
author: Patrick Bareiss, Splunk
4-
description: Event source object for Sysmon EventID 1
6+
description: Data source object for Sysmon EventID 1
7+
source: XmlWinEventLog:Microsoft-Windows-Sysmon/Operational
8+
sourcetype: xmlwineventlog
9+
separator: EventID
10+
supported_TA:
11+
- name: Splunk Add-on for Sysmon
12+
url: https://splunkbase.splunk.com/app/5709/
13+
version: 4.0.0
514
fields:
615
- _time
716
- Channel
@@ -100,6 +109,46 @@ fields:
100109
- user
101110
- user_id
102111
- vendor_product
112+
field_mappings:
113+
- data_model: cim
114+
data_set: Endpoint.Processes
115+
mapping:
116+
ProcessGuid: Processes.process_guid
117+
ProcessId: Processes.process_id
118+
Image: Processes.process_path
119+
Image|endswith: Processes.process_name
120+
CommandLine: Processes.process
121+
CurrentDirectory: Processes.process_current_directory
122+
User: Processes.user
123+
IntegrityLevel: Processes.process_integrity_level
124+
Hashes: Processes.process_hash
125+
ParentProcessGuid: Processes.parent_process_guid
126+
ParentProcessId: Processes.parent_process_id
127+
ParentImage: Processes.parent_process_name
128+
ParentCommandLine: Processes.parent_process
129+
Computer: Processes.dest
130+
OriginalFileName: Processes.original_file_name
131+
convert_to_log_source:
132+
- data_source: Windows Event Log Security 4688
133+
mapping:
134+
ProcessId: NewProcessId
135+
Image: NewProcessName
136+
Image|endswith: NewProcessName|endswith
137+
CommandLine: Process_Command_Line
138+
User: SubjectUserSid
139+
ParentProcessId: ProcessId
140+
ParentImage: ParentProcessName
141+
ParentImage|endswith: ParentProcessName|endswith
142+
Computer: Computer
143+
OriginalFileName: NewProcessName|endswith
144+
- data_source: Crowdstrike Process
145+
mapping:
146+
ProcessId: RawProcessId
147+
Image: ImageFileName
148+
CommandLine: CommandLine
149+
User: UserSid
150+
ParentProcessId: ParentProcessId
151+
ParentImage: ParentBaseFileName
103152
example_log: "<Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'><System><Provider\
104153
\ Name='Microsoft-Windows-Sysmon' Guid='{5770385F-C22A-43E0-BF4C-06F5698FFBD9}'/><EventID>1</EventID><Version>5</Version><Level>4</Level><Task>1</Task><Opcode>0</Opcode><Keywords>0x8000000000000000</Keywords><TimeCreated\
105154
\ SystemTime='2020-10-08T11:03:46.617920300Z'/><EventRecordID>4522</EventRecordID><Correlation/><Execution\

0 commit comments

Comments
 (0)