@mitre-attack/attack-data-model
Version:
A TypeScript API for the MITRE ATT&CK data model
119 lines (112 loc) • 3.94 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/classes/utils.ts
var utils_exports = {};
__export(utils_exports, {
getDataSources: () => getDataSources,
getMitigations: () => getMitigations,
getPlatforms: () => getPlatforms,
getSubTechniques: () => getSubTechniques,
getTactics: () => getTactics
});
module.exports = __toCommonJS(utils_exports);
// src/classes/common/attack-object.impl.ts
var AttackBaseImpl = class {
/**
* Sets the object that revokes the current object.
* @param obj - The object that revokes this object.
*/
setRevokedBy(obj) {
this.revokedBy = obj;
}
/**
* Returns the object that revoked this object.
*/
getRevokedBy() {
return this.revokedBy;
}
};
// src/classes/sdo/tactic.impl.ts
var TacticImpl = class extends AttackBaseImpl {
constructor(tactic) {
super();
this.tactic = tactic;
Object.assign(this, tactic);
}
};
// src/classes/sdo/mitigation.impl.ts
var MitigationImpl = class extends AttackBaseImpl {
constructor(mitigation) {
super();
this.mitigation = mitigation;
Object.assign(this, mitigation);
}
};
// src/classes/sdo/data-source.impl.ts
var DataSourceImpl = class extends AttackBaseImpl {
constructor(dataSource) {
super();
this.dataSource = dataSource;
Object.assign(this, dataSource);
}
};
// 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);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getDataSources,
getMitigations,
getPlatforms,
getSubTechniques,
getTactics
});