Skip to content

Commit

Permalink
505 merging of multiple bundles into a single matrix (#613)
Browse files Browse the repository at this point in the history
* works with different domains

* progress on same domains

* added comments

* more progress

* works

* unit tests for the code

* added requested changes

* merged file from develop

* sonarcloud fixes
  • Loading branch information
adpare authored Feb 25, 2024
1 parent 992bb0a commit eb76a01
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
4 changes: 2 additions & 2 deletions nav-app/src/app/classes/stix/technique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Technique extends StixObject {
public readonly subtechniques: Technique[]; // subtechniques under this technique
public readonly datasources: string; // data sources of the technique
public parent: Technique = null; // parent technique. Only present if it's a sub-technique

public readonly x_mitre_domains: string[];
public get isSubtechnique() {
return this.parent != null;
}
Expand All @@ -22,7 +22,7 @@ export class Technique extends StixObject {
super(stixSDO, dataService);
this.platforms = stixSDO.x_mitre_platforms ? stixSDO.x_mitre_platforms.map((platform) => platform.trim()) : undefined;
this.datasources = stixSDO.x_mitre_data_sources ? stixSDO.x_mitre_data_sources.toString() : '';

this.x_mitre_domains = stixSDO.x_mitre_domains;
if (!this.revoked && !this.deprecated) {
this.tactics = stixSDO.kill_chain_phases.map((phase) => phase.phase_name);
}
Expand Down
38 changes: 29 additions & 9 deletions nav-app/src/app/services/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,28 @@ export class DataService {
*/
parseBundle(domain: Domain, stixBundles: any[]): void {
let platforms = new Set<string>();
let matricesList = [];
let tacticsList = [];
let seenIDs = new Set<string>();
let matrixSDOs = [];
for (let bundle of stixBundles) {
let techniqueSDOs = [];
let matrixSDOs = [];
let idToTechniqueSDO = new Map<string, any>();
let idToTacticSDO = new Map<string, any>();
for (let sdo of bundle.objects) {
//iterate through stix domain objects in the bundle
// iterate through stix domain objects in the bundle
// Filter out object not included in this domain if domains field is available
if (!domain.isCustom) {
if ('x_mitre_domains' in sdo && sdo.x_mitre_domains.length > 0 && !sdo.x_mitre_domains.includes(domain.domain_identifier))
if ('x_mitre_domains' in sdo && sdo.x_mitre_domains.length > 0 && (domain.urls.length == 1 && !sdo.x_mitre_domains.includes(domain.domain_identifier))) {
continue;
}
}

// filter out duplicates
if (!seenIDs.has(sdo.id)) seenIDs.add(sdo.id);
else continue;
else {
continue;
}

// parse according to type
switch (sdo.type) {
Expand Down Expand Up @@ -175,7 +180,6 @@ export class DataService {
break;
}
}

//create techniques
for (let techniqueSDO of techniqueSDOs) {
let subtechniques: Technique[] = [];
Expand All @@ -193,12 +197,15 @@ export class DataService {
}
domain.techniques.push(new Technique(techniqueSDO, subtechniques, this));
}

//create matrices, which also creates tactics and filters techniques
// create a list of matrix and tactic SDOs
for (let matrixSDO of matrixSDOs) {
if (matrixSDO.x_mitre_deprecated) continue;
domain.matrices.push(new Matrix(matrixSDO, idToTacticSDO, domain.techniques, this));
if (matrixSDO.x_mitre_deprecated) {
continue;
}
matricesList.push(matrixSDO);
tacticsList.push(idToTacticSDO);
}
matrixSDOs = [];

// parse platforms
for (let technique of domain.techniques) {
Expand All @@ -214,6 +221,19 @@ export class DataService {
}
}
}
//create matrices, which also creates tactics and filters techniques
for (let i = 0; i < matricesList.length; i++) {
let techniquesList = [];
if (matricesList[i].x_mitre_deprecated) {
continue;
}
for (let technique of domain.techniques) {
if(technique.x_mitre_domains == matricesList[i].external_references[0].external_id) {
techniquesList.push(technique);
}
}
domain.matrices.push(new Matrix(matricesList[i], tacticsList[i], techniquesList, this));
}
domain.platforms = Array.from(platforms); // convert to array

// data loading complete; update watchers
Expand Down
2 changes: 1 addition & 1 deletion nav-app/src/app/tabs/tabs.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,4 +743,4 @@ describe('TabsComponent', () => {
});
}));
});
});
});
17 changes: 16 additions & 1 deletion nav-app/src/tests/utils/mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ export const configData = [
],
},
];

export const mobileDomainData = [
{
name: 'ATT&CK v13',
version: '13',
domains: [
{
name: 'Mobile',
identifier: 'mobile-attack',
data: ['https://raw.githubusercontent.com/mitre/cti/ATT%26CK-v14.1/mobile-attack/mobile-attack.json'],
},
],
},
];
export const configDataExtended = [
{
name: 'ATT&CK v13',
Expand Down Expand Up @@ -95,6 +109,7 @@ export const stixSDO = {
created: '2001-01-01T01:01:00.000Z',
modified: '2001-01-01T01:01:00.000Z',
version: '1.0',
x_mitre_domains: ['enterprise-attack'],
x_mitre_version: '1.0',
};
export const stixSDO_v1_1 = {
Expand Down Expand Up @@ -249,7 +264,7 @@ export const matrixSDO = {
id: 'matrix-0',
type: 'x-mitre-matrix',
tactic_refs: ['tactic-0'],
external_references: [{ external_id: 'enterprise-matrix' }],
external_references: [{ external_id: 'enterprise-attack' }],
};
export const deprecatedMatrixSDO = {
...stixSDO,
Expand Down

0 comments on commit eb76a01

Please sign in to comment.