@mitre-attack/attack-data-model
Version:
A TypeScript API for the MITRE ATT&CK data model
55 lines (52 loc) • 1.95 kB
JavaScript
import {
DataSourceImpl
} from "./chunk-UVFRWXP3.js";
import {
MitigationImpl
} from "./chunk-R4ISNN3D.js";
import {
TacticImpl
} from "./chunk-3Z75KXCP.js";
// src/classes/utils.ts
function getSubTechniques(technique, relationships, attackObjects) {
return relationships.filter((rel) => rel.relationship_type === "subtechnique-of" && rel.source_ref === technique.id).map((rel) => {
const subTech = attackObjects.find((obj) => obj.id === rel.target_ref);
return subTech;
}).filter((subTech) => subTech !== void 0);
}
function getTactics(technique, relationships, attackObjects) {
const killChainPhaseIds = technique.kill_chain_phases?.map((phase) => phase.phase_name) ?? [];
return attackObjects.filter((obj) => obj.type === "x-mitre-tactic" && killChainPhaseIds.includes(obj.id)).map((obj) => new TacticImpl(obj));
}
function getPlatforms(technique) {
return technique.x_mitre_platforms ?? [];
}
function getMitigations(technique, relationships, attackObjects) {
return relationships.filter((rel) => rel.relationship_type === "mitigates" && rel.target_ref === technique.id).map((rel) => {
const mitigation = attackObjects.find(
(obj) => obj.id === rel.source_ref && obj.type === "course-of-action"
);
if (mitigation) {
return new MitigationImpl(mitigation);
}
return null;
}).filter((mitigation) => mitigation !== null);
}
function getDataSources(technique, relationships, attackObjects) {
return relationships.filter((rel) => rel.relationship_type === "detects" && rel.target_ref === technique.id).map((rel) => {
const dataSource = attackObjects.find(
(obj) => obj.id === rel.source_ref && obj.type === "x-mitre-data-source"
);
if (dataSource) {
return new DataSourceImpl(dataSource);
}
return null;
}).filter((dataSource) => dataSource !== null);
}
export {
getSubTechniques,
getTactics,
getPlatforms,
getMitigations,
getDataSources
};