Skip to content

Commit

Permalink
Fix error with ICS domain name.
Browse files Browse the repository at this point in the history
Add relationship collection to clear database script.
  • Loading branch information
ElJocko committed May 19, 2022
1 parent 02e7a82 commit 68454ba
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
15 changes: 11 additions & 4 deletions app/services/collection-bundles-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ async function addDerivedDataSources(bundleObjects) {
const icsDataSourceValues = await systemConfigurationService.retrieveAllowedValuesForTypePropertyDomain('technique', 'x_mitre_data_sources', 'ics-attack');
for (const bundleObject of bundleObjects) {
if (bundleObject.type === 'attack-pattern') {
const enterpriseDomain = bundleObject.x_mitre_domains.find(domain => domain === 'enterprise-attack');
const icsDomain = bundleObject.x_mitre_domains.find(domain => domain === 'attack-ics');
const enterpriseDomain = bundleObject.x_mitre_domains.includes('enterprise-attack');
const icsDomain = bundleObject.x_mitre_domains.includes('ics-attack');
if (enterpriseDomain && !icsDomain) {
// Remove any existing data sources
bundleObject.x_mitre_data_sources = [];
Expand Down Expand Up @@ -776,11 +776,18 @@ async function addDerivedDataSources(bundleObjects) {
}
else if (icsDomain && !enterpriseDomain) {
// Remove any data sources that are not in the list of valid ICS data sources
bundleObject.x_mitre_data_sources = bundleObject.x_mitre_data_sources.filter(source => icsDataSourceValues.allowedValues.find(value => value === source));
if (Array.isArray(bundleObject.x_mitre_data_sources)) {
bundleObject.x_mitre_data_sources = bundleObject.x_mitre_data_sources.filter(source => icsDataSourceValues.allowedValues.includes(source));
}
}
else if (enterpriseDomain && icsDomain) {
// Remove any data sources that are not in the list of valid ICS data sources
bundleObject.x_mitre_data_sources = bundleObject.x_mitre_data_sources.filter(source => icsDataSourceValues.allowedValues.find(value => value === source));
if (Array.isArray(bundleObject.x_mitre_data_sources)) {
bundleObject.x_mitre_data_sources = bundleObject.x_mitre_data_sources.filter(source => icsDataSourceValues.allowedValues.includes(source));
}
else {
bundleObject.x_mitre_data_sources = [];
}

// Add in any enterprise data sources from detects relationships
const dataComponentIds = techniqueDetectedBy.get(bundleObject.id);
Expand Down
10 changes: 6 additions & 4 deletions app/services/stix-bundles-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ exports.exportBundle = async function(options) {
const icsDataSourceValues = await systemConfigurationService.retrieveAllowedValuesForTypePropertyDomain('technique', 'x_mitre_data_sources', 'ics-attack');
for (const bundleObject of bundle.objects) {
if (bundleObject.type === 'attack-pattern') {
const enterpriseDomain = bundleObject.x_mitre_domains.find(domain => domain === 'enterprise-attack');
const icsDomain = bundleObject.x_mitre_domains.find(domain => domain === 'attack-ics');
const enterpriseDomain = bundleObject.x_mitre_domains.includes('enterprise-attack');
const icsDomain = bundleObject.x_mitre_domains.includes('ics-attack');
if (enterpriseDomain && !icsDomain) {
// Remove any existing data source string entries
bundleObject.x_mitre_data_sources = [];
Expand Down Expand Up @@ -399,11 +399,13 @@ exports.exportBundle = async function(options) {
}
else if (icsDomain && !enterpriseDomain) {
// Remove any existing data source string entries that are not in the list of valid ICS data sources
bundleObject.x_mitre_data_sources = bundleObject.x_mitre_data_sources.filter(source => icsDataSourceValues.allowedValues.find(value => value === source));
if (Array.isArray(bundleObject.x_mitre_data_sources)) {
bundleObject.x_mitre_data_sources = bundleObject.x_mitre_data_sources.filter(source => icsDataSourceValues.allowedValues.includes(source));
}
}
else if (enterpriseDomain && icsDomain) {
// Remove any existing data source string entries that are not in the list of valid ICS data sources
bundleObject.x_mitre_data_sources = bundleObject.x_mitre_data_sources.filter(source => icsDataSourceValues.allowedValues.find(value => value === source));
bundleObject.x_mitre_data_sources = bundleObject.x_mitre_data_sources.filter(source => icsDataSourceValues.allowedValues.includes(source));

// Add data source string entries based on the data sources associated with the technique
// data component detects technique AND data component refers to data source
Expand Down
2 changes: 1 addition & 1 deletion app/tests/api/stix-bundles/stix-bundles.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const login = require('../../shared/login');

const enterpriseDomain = 'enterprise-attack';
const mobileDomain = 'mobile-attack';
const icsDomain = 'attack-ics';
const icsDomain = 'ics-attack';

const collectionId = 'x-mitre-collection--30ee11cf-0a05-4d9e-ab54-9b8563669647';
const collectionTimestamp = new Date().toISOString();
Expand Down
4 changes: 4 additions & 0 deletions scripts/clearDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'use strict';

const AttackObject = require('../app/models/attack-object-model');
const Relationship = require('../app/models/relationship-model');
const Reference = require('../app/models/reference-model');

async function clearDatabase() {
Expand All @@ -24,6 +25,9 @@ async function clearDatabase() {
let result = await AttackObject.deleteMany();
console.log(`Deleted ${ result.deletedCount } objects from the attackObjects collection.`);

result = await Relationship.deleteMany();
console.log(`Deleted ${ result.deletedCount } objects from the relationships collection.`);

result = await Reference.deleteMany();
console.log(`Deleted ${ result.deletedCount } objects from the references collection.`);
}
Expand Down

0 comments on commit 68454ba

Please sign in to comment.