Skip to content

Commit b1a34de

Browse files
committed
Allow attribute tagging to be disabled with -v
1 parent 954f582 commit b1a34de

3 files changed

Lines changed: 49 additions & 40 deletions

File tree

cs_misp_import/actors.py

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ def create_internal_reference() -> MISPObject:
150150
return inter
151151

152152
@staticmethod
153-
def int_ref_handler(evt, kc_name, kc_detail, ref_list, slg, act_name, int_ref, no_slug: bool = False):
153+
def int_ref_handler(evt, kc_name, kc_detail, ref_list, slg, act_name, int_ref, verbose: bool = False):
154154
misp_object = MISPObject("internal-reference")
155155
misp_object.add_attribute("type", "Adversary detail", disable_correlation=True)
156156
misp_object.add_attribute("identifier", kc_name.title(), disable_correlation=True)
157157
if not isinstance(kc_detail, list):
158158
kc_detail.replace("\t", "").replace(" ", "")
159159
sum_id = misp_object.add_attribute("comment", kc_detail, disable_correlation=True)
160160
ref_list.append(evt.add_object(misp_object))
161-
if not no_slug:
161+
if verbose:
162162
evt.add_attribute_tag(f"CrowdStrike:adversary:{kc_name.lower().replace(' ', '-')}: {act_name}", sum_id.uuid)
163163
evt.add_attribute_tag(f"CrowdStrike:adversary:{slg}: {kc_name.upper()}", sum_id.uuid)
164164
int_ref.add_reference(misp_object.uuid, "Adversary detail")
@@ -185,6 +185,7 @@ def create_event_from_actor(self, actor, act_details) -> MISPEvent():
185185
slug = details.get("slug", actor_name.lower().replace(" ", "-"))
186186
actor_branch = actor_name.split(" ")[1].upper()
187187
actor_region = ""
188+
verbosity = self.import_settings["verbose_tags"]
188189
if actor_name:
189190
for act_reg in [adv for adv in dir(Adversary) if "__" not in adv]:
190191
if act_reg in actor_branch:
@@ -213,7 +214,7 @@ def create_event_from_actor(self, actor, act_details) -> MISPEvent():
213214
if not internal:
214215
internal = self.create_internal_reference()
215216

216-
self.int_ref_handler(event, "Actor Type", act_type.title(), to_reference, slug, actor_name, internal, False)
217+
self.int_ref_handler(event, "Actor Type", act_type.title(), to_reference, slug, actor_name, internal, verbosity)
217218
event.add_tag(f"CrowdStrike:adversary:type: {act_type.upper()}")
218219

219220
# Adversary motives
@@ -224,7 +225,7 @@ def create_event_from_actor(self, actor, act_details) -> MISPEvent():
224225
if not internal:
225226
internal = self.create_internal_reference()
226227

227-
self.int_ref_handler(event, "Motivation", motive_list_string, to_reference, slug, actor_name, internal, False)
228+
self.int_ref_handler(event, "Motivation", motive_list_string, to_reference, slug, actor_name, internal, verbosity)
228229
for mname in mlist:
229230
event.add_tag(f"CrowdStrike:adversary:motivation: {mname.upper()}")
230231

@@ -236,7 +237,7 @@ def create_event_from_actor(self, actor, act_details) -> MISPEvent():
236237
if not internal:
237238
internal = self.create_internal_reference()
238239

239-
self.int_ref_handler(event, "Capability", cap_val, to_reference, slug, actor_name, internal, False)
240+
self.int_ref_handler(event, "Capability", cap_val, to_reference, slug, actor_name, internal, verbosity)
240241
event.add_tag(f"CrowdStrike:adversary:capability: {cap_val.upper()}")
241242
# Set adversary event threat level based upon adversary capability
242243
if "BELOW" in cap_val.upper() or "LOW" in cap_val.upper():
@@ -262,13 +263,13 @@ def create_event_from_actor(self, actor, act_details) -> MISPEvent():
262263

263264
# Kill chain - Objectives
264265
if objectives:
265-
self.int_ref_handler(event, "objectives", objectives, to_reference, slug, actor_name, internal)
266+
self.int_ref_handler(event, "objectives", objectives, to_reference, slug, actor_name, internal, verbosity)
266267
# Kill chain - Command and Control
267268
if candc:
268-
self.int_ref_handler(event, "command and control", candc, to_reference, slug, actor_name, internal)
269+
self.int_ref_handler(event, "command and control", candc, to_reference, slug, actor_name, internal, verbosity)
269270
# Kill chain - Delivery
270271
if delivery:
271-
self.int_ref_handler(event, "delivery", delivery, to_reference, slug, actor_name, internal)
272+
self.int_ref_handler(event, "delivery", delivery, to_reference, slug, actor_name, internal, verbosity)
272273
# Kill chain - Exploitation
273274
if exploitation:
274275
exploitation_object = MISPObject("internal-reference")
@@ -278,23 +279,24 @@ def create_event_from_actor(self, actor, act_details) -> MISPEvent():
278279
exploits = exploitation.replace("\t", "").replace(" ", "").split("\r\n")
279280
ex_id = exploitation_object.add_attribute("comment", exploitation.replace("\t", "").replace(" ", ""), disable_correlation=True)
280281
to_reference.append(event.add_object(exploitation_object))
281-
event.add_attribute_tag(f"CrowdStrike:adversary:{slug}: EXPLOITATION", ex_id.uuid)
282-
event.add_attribute_tag(f"CrowdStrike:adversary:exploitation: {actor_name}", ex_id.uuid)
283-
for exptt in [exp for exp in exploits if exp]:
284-
if exptt not in ["Unknown", "N/A"]:
285-
for exploit in [a.strip() for a in exptt.split(",")]:
286-
if len(exploit.split(" ")) <= 4:
287-
event.add_attribute_tag(f"CrowdStrike:adversary:exploitation: {exploit.upper()}", ex_id.uuid)
282+
if verbosity:
283+
event.add_attribute_tag(f"CrowdStrike:adversary:{slug}: EXPLOITATION", ex_id.uuid)
284+
event.add_attribute_tag(f"CrowdStrike:adversary:exploitation: {actor_name}", ex_id.uuid)
285+
for exptt in [exp for exp in exploits if exp]:
286+
if exptt not in ["Unknown", "N/A"]:
287+
for exploit in [a.strip() for a in exptt.split(",")]:
288+
if len(exploit.split(" ")) <= 4:
289+
event.add_attribute_tag(f"CrowdStrike:adversary:exploitation: {exploit.upper()}", ex_id.uuid)
288290
internal.add_reference(exploitation_object.uuid, "Adversary detail")
289291
# Kill chain - Installation
290292
if installation:
291-
self.int_ref_handler(event, "installation", installation, to_reference, slug, actor_name, internal)
293+
self.int_ref_handler(event, "installation", installation, to_reference, slug, actor_name, internal, verbosity)
292294
# Kill chain - Reconnaissance
293295
if reconnaissance:
294-
self.int_ref_handler(event, "reconnaissance", reconnaissance, to_reference, slug, actor_name, internal)
296+
self.int_ref_handler(event, "reconnaissance", reconnaissance, to_reference, slug, actor_name, internal, verbosity)
295297
# Kill chain - Weaponization
296298
if weaponization:
297-
self.int_ref_handler(event, "weaponization", weaponization, to_reference, slug, actor_name, internal)
299+
self.int_ref_handler(event, "weaponization", weaponization, to_reference, slug, actor_name, internal, verbosity)
298300

299301
for ref in to_reference:
300302
internal.add_reference(ref.uuid, "Adversary detail")
@@ -305,7 +307,7 @@ def create_event_from_actor(self, actor, act_details) -> MISPEvent():
305307
if internal:
306308
event.add_object(internal)
307309
# Add the description tags
308-
if details.get('description'):
310+
if details.get('description') and verbosity:
309311
event.add_attribute_tag(f"CrowdStrike:adversary:description: {actor_name}", desc_id.uuid)
310312
event.add_attribute_tag(f"CrowdStrike:adversary:{slug}: DESCRIPTION", desc_id.uuid)
311313

@@ -339,10 +341,10 @@ def create_event_from_actor(self, actor, act_details) -> MISPEvent():
339341
event.add_attribute_tag(f"CrowdStrike:adversary:branch: {actor_branch}", ta.uuid)
340342
if had_timestamp:
341343
event.add_object(timestamp_object)
342-
if tsf:
344+
if tsf and verbosity:
343345
event.add_attribute_tag(f"CrowdStrike:adversary:first-seen: {actor_name}", tsf.uuid)
344346
event.add_attribute_tag(f"CrowdStrike:adversary:{slug}: FIRST SEEN", tsf.uuid)
345-
if tsl:
347+
if tsl and verbosity:
346348
event.add_attribute_tag(f"CrowdStrike:adversary:last-seen: {actor_name}", tsl.uuid)
347349
event.add_attribute_tag(f"CrowdStrike:adversary:{slug}: LAST SEEN", tsl.uuid)
348350
if actor.get('known_as') or actor.get("origins"):
@@ -351,19 +353,20 @@ def create_event_from_actor(self, actor, act_details) -> MISPEvent():
351353
aliased = [a.strip() for a in actor.get("known_as").split(",")]
352354
for alias in aliased:
353355
kao = known_as_object.add_attribute('alias', alias, disable_correlation=True)
354-
kao.add_tag(f"CrowdStrike:adversary:branch: {actor_branch}")
355-
kao.add_tag(f"CrowdStrike:adversary:{slug}:alias: {alias.upper()}")
356356
# Tag the aliases to the threat-actor attribution
357-
event.add_attribute_tag(f"CrowdStrike:adversary:{slug}:alias: {alias.upper()}", ta.uuid)
357+
if verbosity:
358+
kao.add_tag(f"CrowdStrike:adversary:branch: {actor_branch}")
359+
kao.add_tag(f"CrowdStrike:adversary:{slug}:alias: {alias.upper()}")
360+
event.add_attribute_tag(f"CrowdStrike:adversary:{slug}:alias: {alias.upper()}", ta.uuid)
358361
event.add_object(known_as_object)
359362
for orig in actor.get("origins", []):
360363
locale = orig.get("value")
361364
if locale:
362365
kar = event.add_attribute("country-of-residence", locale, disable_correlation=True)
363-
event.add_attribute_tag(f"CrowdStrike:adversary:{slug}:origin: {locale.upper()}", kar.uuid)
364-
event.add_attribute_tag(f"CrowdStrike:adversary:origin: {locale.upper()}", kar.uuid)
365366
event.add_tag(f"CrowdStrike:adversary:origin: {locale.upper()}")
366-
367+
if verbosity:
368+
event.add_attribute_tag(f"CrowdStrike:adversary:{slug}:origin: {locale.upper()}", kar.uuid)
369+
event.add_attribute_tag(f"CrowdStrike:adversary:origin: {locale.upper()}", kar.uuid)
367370

368371
victim = None
369372
# Adversary victim location
@@ -373,9 +376,9 @@ def create_event_from_actor(self, actor, act_details) -> MISPEvent():
373376
if not victim:
374377
victim = MISPObject("victim")
375378
vic = victim.add_attribute('regions', region, disable_correlation=True)
376-
vic.add_tag(f"CrowdStrike:target:location: {region.upper()}")
377-
vic.add_tag(f"CrowdStrike:adversary:{slug}:target:location: {region.upper()}")
378-
#vic.add_tag(f"CrowdStrike:adversary:{slug}:target: LOCATION")
379+
if verbosity:
380+
vic.add_tag(f"CrowdStrike:target:location: {region.upper()}")
381+
vic.add_tag(f"CrowdStrike:adversary:{slug}:target:location: {region.upper()}")
379382

380383
# Adversary victim industry
381384
if actor.get("target_industries"):
@@ -384,10 +387,11 @@ def create_event_from_actor(self, actor, act_details) -> MISPEvent():
384387
if not victim:
385388
victim = MISPObject("victim")
386389
vic = victim.add_attribute('sectors', sector, disable_correlation=True)
387-
vic.add_tag(f"CrowdStrike:adversary:{slug}:target:sector: {sector.upper()}")
388-
#vic.add_tag(f"CrowdStrike:adversary:{slug}:target: SECTOR")
389-
vic.add_tag(f"CrowdStrike:target:sector: {sector.upper()}")
390-
event.add_object(victim)
390+
if verbosity:
391+
vic.add_tag(f"CrowdStrike:adversary:{slug}:target:sector: {sector.upper()}")
392+
vic.add_tag(f"CrowdStrike:target:sector: {sector.upper()}")
393+
if victim:
394+
event.add_object(victim)
391395

392396
# TYPE Taxonomic tag, all events
393397
if confirm_boolean_param(self.settings["TAGGING"].get("taxonomic_TYPE", False)):

cs_misp_import/reports.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def add_actor_detail(self, report: dict, event: MISPEvent) -> MISPEvent:
351351
att = event.add_attribute(**actor_att, disable_correlation=True)
352352
for stem in actor_name:
353353
for adversary in Adversary:
354-
if adversary.name == stem.upper():
354+
if adversary.name == stem.upper() and self.import_settings["verbose_tags"]:
355355
# Can't cross-tag with this as we're using it for delete
356356
event.add_attribute_tag(f"CrowdStrike:report:adversary:branch: {stem.upper()}", att.uuid)
357357
event.add_tag(f"CrowdStrike:report:adversary: {actor.get('name')}")
@@ -392,7 +392,8 @@ def add_indicator_detail(self, event: MISPEvent, report_id: str, indicator_list:
392392
ind_seen["last_seen"] = ind.get("published_date")
393393

394394
added = event.add_attribute(indicator_object.type, indicator_object.value, category=indicator_object.category, disable_correlation=True, **ind_seen)
395-
event.add_attribute_tag(f"CrowdStrike:report:indicator:type: {indicator_object.type.upper()}", added.uuid)
395+
if self.import_settings["verbose_tags"]:
396+
event.add_attribute_tag(f"CrowdStrike:report:indicator:type: {indicator_object.type.upper()}", added.uuid)
396397
# Event level only
397398
#for tag in self.settings["CrowdStrike"]["indicators_tags"].split(","):
398399
# event.add_attribute_tag(tag, added.uuid)
@@ -416,7 +417,8 @@ def add_victim_detail(self, report: dict, event: MISPEvent) -> MISPEvent:
416417
if not victim:
417418
victim = MISPObject("victim")
418419
vic = victim.add_attribute('regions', country, disable_correlation=True)
419-
vic.add_tag(f"CrowdStrike:target:location: {country.upper()}")
420+
if self.import_settings["verbose_tags"]:
421+
vic.add_tag(f"CrowdStrike:target:location: {country.upper()}")
420422
# Also create a target-location attribute for this value (Too noisy?)
421423
# reg = event.add_attribute('target-location', country)
422424
# event.add_attribute_tag(f"CrowdStrike:target: {country.upper()}", reg.uuid)
@@ -429,7 +431,8 @@ def add_victim_detail(self, report: dict, event: MISPEvent) -> MISPEvent:
429431
if not victim:
430432
victim = MISPObject("victim")
431433
vic = victim.add_attribute('sectors', sector, disable_correlation=True)
432-
vic.add_tag(f"CrowdStrike:target:sector: {sector.upper()}")
434+
if self.import_settings["verbose_tags"]:
435+
vic.add_tag(f"CrowdStrike:target:sector: {sector.upper()}")
433436
if victim:
434437
event.add_object(victim)
435438

@@ -472,7 +475,7 @@ def add_report_content(self, report: dict, event: MISPEvent, details: dict, repo
472475
# Event level only
473476
#for tag in self.settings["CrowdStrike"]["reports_tags"].split(","):
474477
# event.add_attribute_tag(tag, att.uuid)
475-
if att.value not in ["text", "Full Report", "Report", report_id]:
478+
if att.value not in ["text", "Full Report", "Report", report_id] and self.import_settings["verbose_tags"]:
476479
event.add_attribute_tag(f"CrowdStrike:report:{report_id.lower().replace('-',': ')}", att.uuid)
477480
#if report_tag:
478481
# event.add_attribute_tag(f"CrowdStrike:report: {report_tag.upper()}", att.uuid)

misp_import.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def parse_command_line() -> Namespace:
7777
parser.add_argument("-p", "--publish", dest="publish", help="Publish events upon creation.", action="store_true", required=False, default=False)
7878
parser.add_argument("-t", "--type", "--report_type", "--indicator_type", "--adversary_type", dest="type", help="Import only this type.", required=False, default=False)
7979
parser.add_argument("-c", "--config", dest="config_file", help="Path to local configuration file", required=False)
80+
parser.add_argument("-v", "--verbose_tagging", dest="verbose", action="store_false", help="Disable verbose tagging.", required=False, default=True)
8081
parser.add_argument("-nd", "--no_dupe_check",
8182
dest="no_dupe_check",
8283
help="Enable or disable duplicate checking on import, defaults to False.",
@@ -305,7 +306,8 @@ def main():
305306
"no_banners": args.no_banner,
306307
"no_dupe_check": args.no_dupe_check,
307308
"type": args.type,
308-
"publish": args.publish
309+
"publish": args.publish,
310+
"verbose_tags": args.verbose
309311
}
310312

311313
if not import_settings["unknown_mapping"]:

0 commit comments

Comments
 (0)