Skip to content

Commit 879cd76

Browse files
authored
Merge pull request #1219 from MISP/codex/fix-dima-converter-for-version-and-jq_all_the_things
DIMA converter: increment galaxy version and run jq_all_the_things
2 parents b357a7a + 0629185 commit 879cd76

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

clusters/dima-techniques.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
],
55
"category": "dima",
66
"description": "DIMA is a social engineering and cognitive manipulation framework organized by phase, tactic, and technique.",
7-
"name": "DIMA Techniques",
7+
"name": "Techniques",
88
"source": "https://github.com/M82-project/DIMA",
99
"type": "dima-techniques",
1010
"uuid": "b4962ea7-611f-569e-a604-562f2895b06a",

galaxies/dima-techniques.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
"MEMORISE - Exposition de contenus"
2323
]
2424
},
25-
"name": "DIMA Techniques",
25+
"name": "Techniques",
2626
"namespace": "dima",
2727
"type": "dima-techniques",
2828
"uuid": "a9516d2d-3f59-5cab-9ffa-3cdac39659a1",
29-
"version": 1
29+
"version": 2
3030
}

tools/gen_dima.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import argparse
55
import json
6+
import subprocess
67
import uuid
78
from pathlib import Path
89
from urllib.request import urlopen
@@ -72,7 +73,7 @@ def build_cluster(data_by_phase: list[dict]) -> dict:
7273
}
7374

7475

75-
def build_galaxy(data_by_phase: list[dict]) -> dict:
76+
def build_galaxy(data_by_phase: list[dict], version: int = 1) -> dict:
7677
kill_chain = []
7778
for phase_data in data_by_phase:
7879
phase = phase_data["phase"]
@@ -85,7 +86,7 @@ def build_galaxy(data_by_phase: list[dict]) -> dict:
8586
"namespace": "dima",
8687
"type": "dima-techniques",
8788
"uuid": stable_uuid("galaxy", "dima-techniques"),
88-
"version": 1,
89+
"version": version,
8990
"icon": "project-diagram",
9091
"kill_chain_order": {"tactics": kill_chain},
9192
}
@@ -98,12 +99,21 @@ def main() -> None:
9899
args = parser.parse_args()
99100

100101
data_by_phase = [fetch_phase(phase) for phase in FILES]
101-
galaxy = build_galaxy(data_by_phase)
102+
103+
current_version = 0
104+
galaxy_output = Path(args.galaxy_output)
105+
if galaxy_output.exists():
106+
existing_galaxy = json.loads(galaxy_output.read_text(encoding="utf-8"))
107+
current_version = int(existing_galaxy.get("version", 0))
108+
109+
galaxy = build_galaxy(data_by_phase, version=current_version + 1)
102110
cluster = build_cluster(data_by_phase)
103111

104-
Path(args.galaxy_output).write_text(json.dumps(galaxy, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
112+
galaxy_output.write_text(json.dumps(galaxy, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
105113
Path(args.cluster_output).write_text(json.dumps(cluster, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
106114

115+
subprocess.run(["./jq_all_the_things.sh"], check=True)
116+
107117

108118
if __name__ == "__main__":
109119
main()

0 commit comments

Comments
 (0)