Skip to content

Commit

Permalink
v1.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
2XXE-SRA committed Dec 11, 2024
1 parent 95b548f commit 5fefc52
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 39 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
***

# Version 1.8.1 - December 2024

- Added support for overriding multiple version of the same Variant via the Blueprint

***

# Version 1.8.0 - December 2024

- Added support for Blueprint overrides to Darkpool
Expand Down
Binary file not shown.
14 changes: 14 additions & 0 deletions docs/Blueprints.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ campaigns:

In most cases, users should stick with the first form.

You can also specify these Variant structures as a list.
This is intended to support instances where you need to include multiple version of the same Variant and override one or both versions. Example:

```
campaigns:
Command and Control:
T1071.004:
dnsc2:
- version: 1
name: "Override version 1"
- version: 2
name: "Override version 2"
```

### Groups

Groups are used to add additional threat group metadata to exported test cases and follow the structure:
Expand Down
88 changes: 50 additions & 38 deletions libmm/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,53 +377,65 @@ def from_yaml(cls, y: dict):
# - integer -> ex: 1
# - string -> ex: 1;2
# - dict -> ex: { ... }
# - list -> ex: [ ... ]
#
# the string form allows for multiple version of the same variant
# this has to be done like this to avoid duplicate keys in YAML
#
# the dict form is a blueprint-level override that lets the
# blueprint override certain fields in a variant
#
# the list form allows for overriding multiple versions of the same variant

do_override = False
if type(variant_block) in [str, int]:
versions = str(variant_block)
if ";" in versions:
versions = [version.strip() for version in versions.split(";")]
else:
versions = [versions]
if isinstance(variant_block, list):
variant_list = variant_block
else:
do_override = True
versions = [variant_block.get("version")]

for version in versions:
try:
variant = lookup_variant(tid=tid, name=variant_name, version=version)
except Exception as e:
logger.error(e)
continue

session.add(variant)
session.add(campaign)
campaign.variants.append(variant)

if do_override:
override = VariantOverride(
referencces=variant_block.get("references", None),
guidance=variant_block.get("guidance", None),
display_name=variant_block.get("name", None),
variant=variant,
blueprint_id=blueprint.id,
campaign_id=campaign.id,
variant_list = [variant_block]

for variant_list_item in variant_list:
do_override = False
if isinstance(variant_list_item, (str, int)):
version_str = str(variant_list_item)
else:
do_override = True
version_str = str(variant_list_item.get("version"))

if ";" in version_str:
versions = [version.strip() for version in version_str.split(";")]
else:
versions = [version_str]

for version in versions:
try:
variant = lookup_variant(tid=tid, name=variant_name, version=version)
except Exception as e:
logger.error(e)
continue

session.add(variant)
session.add(campaign)
campaign.variants.append(variant)

if do_override:
new_name = variant_list_item.get("name", None)

override = VariantOverride(
referencces=variant_list_item.get("references", None),
guidance=variant_list_item.get("guidance", None),
display_name=new_name if new_name else variant.display_name,
variant=variant,
blueprint_id=blueprint.id,
campaign_id=campaign.id,
)
session.add(override)

# handle blueprint-level groups based on matching tid+blueprint
group_matches = (
session.query(BlueprintGroup)
.filter(BlueprintGroup.tid == tid, BlueprintGroup.blueprint_id == blueprint.id)
.all()
)
session.add(override)

# handle blueprint-level groups based on matching tid+blueprint
group_matches = (
session.query(BlueprintGroup)
.filter(BlueprintGroup.tid == tid, BlueprintGroup.blueprint_id == blueprint.id)
.all()
)
variant.groups.extend(group_matches)
variant.groups.extend(group_matches)

session.commit()
blueprint.emit_loaded()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "marketmaker"
version = "1.8.0"
version = "1.8.1"
description = "Suite of tools for managing and creating attack plans"
authors = ["2XXE <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 5fefc52

Please sign in to comment.