-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmitre_mapper.py
More file actions
33 lines (24 loc) · 1.24 KB
/
Copy pathmitre_mapper.py
File metadata and controls
33 lines (24 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import annotations
from typing import Any, Optional
def keyword_to_technique(keyword: str) -> dict[str, Optional[str]]:
k = keyword.strip().lower()
mapping: dict[str, dict[str, Optional[str]]] = {
"nmap": {"technique_id": "T1046", "tactic": "Reconnaissance"},
"curl": {"technique_id": "T1105", "tactic": "Command and Control"},
"wget": {"technique_id": "T1105", "tactic": "Command and Control"},
"cat": {"technique_id": "T1005", "tactic": "Collection"},
"grep": {"technique_id": "T1082", "tactic": "Discovery"},
"chmod": {"technique_id": "T1222.001", "tactic": "Defense Evasion"},
"sudo": {"technique_id": "T1068", "tactic": "Privilege Escalation"},
}
return mapping.get(k, {"technique_id": None, "tactic": None})
def map_keywords_to_techniques(keywords: list[str]) -> dict[str, Any]:
matches = []
technique_ids: list[str] = []
for kw in keywords:
info = keyword_to_technique(kw)
technique_id = info.get("technique_id")
if technique_id and technique_id not in technique_ids:
technique_ids.append(technique_id)
matches.append({"keyword": kw, **info})
return {"technique_ids": technique_ids, "matches": matches}