Skip to content

Commit

Permalink
Add suport of Mobile & ICS MITRE ATT&CK layer (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkiros committed Oct 29, 2024
1 parent 7b2cec1 commit 366bc52
Show file tree
Hide file tree
Showing 4 changed files with 1,115 additions and 32 deletions.
117 changes: 90 additions & 27 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@
height: 100px;
margin-bottom: 2%;
}

.process-row {
margin-top: 2%;
padding-right: 0 !important;
}
}

</style>
Expand Down Expand Up @@ -224,7 +229,14 @@ <h4 class="text-center">1. List of CVEs</h4>
</div>
</div>
<div class="col-lg-2 col-md-12 d-flex align-items-center process">
<a href="#" class="btn btn-primary mx-auto" onclick="process()">2. Generate<br/>MITRE ATT&CK</a>
<div class="row mx-auto process-row" style="padding-right: 4%;">
<a href="#" class="btn btn-primary mx-auto" onclick="process()">2. Generate<br/>MITRE ATT&CK</a>
<select id="layer_type" class="form-select mt-2 text-center bg-secondary-subtle">
<option value="enterprise">Enterprise</option>
<option value="mobile">Mobile</option>
<option value="ics">ICS</option>
</select>
</div>
</div>
<div class="col-lg-7 col-md-12 position-relative bg-white">
<div class="mx-3" style="width: 100%; min-height: 400px;" id="container"></div>
Expand All @@ -241,8 +253,6 @@ <h4 class="text-center">1. List of CVEs</h4>
<script>
var metrics = {"CWE": {}, "CAPEC": {}, "TECHNIQUES": {}};
var data_cleaned = [];
const url_params = new URLSearchParams(window.location.search);
const cves_param = url_params.get('input');
var chart = echarts.init(document.getElementById('container'), null, {
renderer: 'canvas',
useDirtyRect: false
Expand All @@ -254,7 +264,18 @@ <h4 class="text-center">1. List of CVEs</h4>
document.execCommand('inserttext', false, event.clipboardData.getData('text/plain'));
});

document.querySelector("#layer_type").addEventListener('change', function() {
adapt();
});

document.querySelector("#cves").addEventListener('DOMSubtreeModified', function() {
adapt();
});

document.addEventListener('DOMContentLoaded', function() {

check_param();

var contentEditableElements = document.querySelectorAll('[contenteditable]');

// Function to check if the element is empty and clear it
Expand All @@ -273,19 +294,30 @@ <h4 class="text-center">1. List of CVEs</h4>
});
});


document.onload = check_param();

async function adapt() {
var layer_type = document.getElementById('layer_type').value
var cves = document.getElementById('cves').innerText.trim().replace(/\n/g, ',');
var cves_gzip = await compress(cves, 'gzip');
var cves_b64 = btoa(String.fromCharCode.apply(null, new Uint8Array(cves_gzip)));
history.pushState({}, '', `?layer=${layer_type}&input=${cves_b64}`);
}


async function check_param() {
var url_params = new URLSearchParams(window.location.search);
var cves_param = url_params.get('input');
var layer_param = url_params.get('layer');
if (cves_param) {
var cves_b64 = atob(cves_param);
var cves_gzip = new Uint8Array(cves_b64.split('').map(c => c.charCodeAt(0)));
var cves = await decompress(cves_gzip, 'gzip');
document.getElementById('cves').innerText = cves.replace(/,/g, '\n');
await process();
}
if (layer_param) {
document.getElementById('layer_type').value = layer_param;
}
}

// Gzip compression
Expand All @@ -312,6 +344,12 @@ <h4 class="text-center">1. List of CVEs</h4>

async function process() {

// clear all data are not CVE-XXXX-XXXX format
var cves = document.getElementById('cves').innerText.trim();
var cves_array = cves.split('\n').map(cve => cve.trim()).filter(cve => cve !== '');
var cves_cleaned = cves_array.filter(cve => cve.match(/^CVE-\d{4}-\d{4,}$/));
document.getElementById('cves').innerText = cves_cleaned.join('\n');

chart.showLoading();

data_cleaned = [];
Expand All @@ -328,17 +366,35 @@ <h4 class="text-center">1. List of CVEs</h4>
return;
}

var techniques_association;

try {
techniques_association = await fetch('https://raw.githubusercontent.com/Galeax/CVE2CAPEC/refs/heads/main/resources/techniques_association.json').then(res => res.text());
techniques_association = JSON.parse(techniques_association);
} catch (error) {
console.error(error);
Swal.fire({
icon: 'error',
title: 'An error occurred',
text: 'Failed to fetch the Techniques association database',
});
chart.hideLoading();
return;
}

var cves_array = cves.split('\n').map(cve => cve.trim()).filter(cve => cve !== '');

// Group by year
var cves_list = {};
for (var i = 0; i < cves_array.length; i++) {
var cve = cves_array[i];
var year = cve.split('-')[1];
if (!cves_list[year]) {
cves_list[year] = [];
if (year) {
if (!cves_list[year]) {
cves_list[year] = [];
}
cves_list[year].push(cve);
}
cves_list[year].push(cve);
}

var data = [];
Expand Down Expand Up @@ -392,8 +448,24 @@ <h4 class="text-center">1. List of CVEs</h4>
var lines = capec_data_raw[technique]['techniques'].split("NAME:ATTACK:ENTRY ")
for (var i = 1; i < lines.length; i++) {
var line = lines[i];
var layer_type = document.getElementById('layer_type').value;
var technique_id = line.split(":")[1];
technics.add(technique_id);
if (layer_type === "ics") {
if (Object.keys(techniques_association).includes(technique_id)) {
technique_id = techniques_association[technique_id].ics;
} else {
technique_id = null;
}
} else if (layer_type === "mobile") {
if (Object.keys(techniques_association).includes(technique_id)) {
technique_id = techniques_association[technique_id].mobile;
} else {
technique_id = null;
}
}
if (technique_id) {
technics.add(technique_id);
}
}
techniques_data[technique]["techniques"] = Array.from(technics);
});
Expand Down Expand Up @@ -569,11 +641,12 @@ <h4 class="text-center">1. List of CVEs</h4>

window.addEventListener('resize', chart.resize);

// set list of CVEs in the URL
// set list of CVEs in the URL and the layer type
var cves = document.getElementById('cves').innerText.trim().replace(/\n/g, ',');
var layer_type = document.getElementById('layer_type').value;
var cves_gzip = await compress(cves, 'gzip');
var cves_b64 = btoa(String.fromCharCode.apply(null, new Uint8Array(cves_gzip)));
history.pushState({}, '', `?input=${cves_b64}`);
history.pushState({}, '', `?layer=${layer_type}&input=${cves_b64}`);


await create_mitre_layer();
Expand All @@ -584,12 +657,10 @@ <h4 class="text-center">1. List of CVEs</h4>
title: 'Some CVEs not found',
text: 'The following CVEs were not found in the database: ' + cves_not_found.join(', '),
});
return;
}

chart.hideLoading();

create_mitre_layer();
print_mitre();
}

Expand All @@ -600,6 +671,10 @@ <h4 class="text-center">1. List of CVEs</h4>
// Get the list of techniques, some node.to maybe null
var techniques_list = data_cleaned.filter(node => node.target !== null);
var max_score = 0;
var layer_type = document.getElementById('layer_type').value;
var enterprise_plateform = ["Windows", "Linux", "macOS", "Network", "PRE", "Containers", "Office 365", "SaaS", "Google Workspace", "IaaS", "Azure AD"];
var mobile_plateform = ["Android", "iOS"];
var ics_plateform = ["None"];


for (var i = 0; i < techniques_list.length; i++) {
Expand Down Expand Up @@ -640,22 +715,10 @@ <h4 class="text-center">1. List of CVEs</h4>
"navigator": "5.1.0",
"layer": "4.5"
},
"domain": "enterprise-attack",
"domain": layer_type + "-attack",
"description": "",
"filters": {
"platforms": [
"Windows",
"Linux",
"macOS",
"Network",
"PRE",
"Containers",
"Office 365",
"SaaS",
"Google Workspace",
"IaaS",
"Azure AD"
]
"platforms": layer_type === "enterprise" ? enterprise_plateform : layer_type === "mobile" ? mobile_plateform : ics_plateform,
},
"sorting": 3,
"layout": {
Expand Down
Loading

0 comments on commit 366bc52

Please sign in to comment.