Skip to content

Commit

Permalink
- some code organization work
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg-RapidFort committed Oct 29, 2024
1 parent 7ee48bc commit c5ba8ca
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 55 deletions.
2 changes: 2 additions & 0 deletions report_shots/shots.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const generateReportViews = async (
const cleanedSVGs = svgFiles.map(svgContent =>
svgContent.replace(/<style[^>]*>[\s\S]*?<\/style>/, "")
);

const dimensions = await Promise.all(svgFiles.map(parseSVGDimensions));

const severityVulnsDimensions = dimensions[0]
Expand Down Expand Up @@ -210,6 +211,7 @@ const generateReportViews = async (
.toFile(`${imageSavePath}/cve_reduction.webp`);
};


async function readSVGTemplate (filename) {
// reading svg template
return await fsPromise.readFile(`./${filename}.svg`, { encoding: 'utf8' });
Expand Down
105 changes: 50 additions & 55 deletions report_shots/vulnsParser.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,6 @@
const { parse : parseCVSS } = require('./cvss-parser/cvss');



const applyVectorModifiers = (vector, version, pocAvailable, execPath) => {
// Parse the vector string into an object
const vectorParams = vector.split('/').reduce((acc, param) => {
const [key, value] = param.split(':');
acc[key] = value;
return acc;
}, {});

// Update the Exploit Code Maturity if pocAvailable is true
if (!pocAvailable) {
vectorParams.E = 'U';
vectorParams.RL = version === 'V2' ? 'ND' : 'X';
vectorParams.RC = version === 'V2' ? 'ND' : 'X';
}

// Update the Attack Complexity and User Interaction if execPath is true
if (!execPath && version === 'V3') {
vectorParams.MAC = 'H';
vectorParams.MUI = 'R';
}

// Construct the updated vector string
const updatedVector = Object.entries(vectorParams)
.map(([key, value]) => `${key}:${value}`)
.join('/');

return updatedVector;
};

const vulnsColorScheme = {
exploited:'#C62A2F',
critical:'#DF1C41',
high:'#6E3FF3',
medium:'#F2AE40',
low:'#35B9E9',
unknown:'#8b8d98',
poc:'#C62A2F',
na:'#32D583',
}
const SEVERITY = {
CRITICAL: 'critical',
HIGH: 'high',
MEDIUM: 'medium',
LOW: 'low',
UNKNOWN: 'unknown'
}

const SEVERITY_DETAIL = {
[SEVERITY.CRITICAL]: {
id: SEVERITY.CRITICAL,
Expand Down Expand Up @@ -82,6 +34,54 @@ const SEVERITY_DETAIL = {
},
}

const vulnsColorScheme = {
exploited:'#C62A2F',
critical:'#DF1C41',
high:'#6E3FF3',
medium:'#F2AE40',
low:'#35B9E9',
unknown:'#8b8d98',
poc:'#C62A2F',
na:'#32D583',
}
const SEVERITY = {
CRITICAL: 'critical',
HIGH: 'high',
MEDIUM: 'medium',
LOW: 'low',
UNKNOWN: 'unknown'
}

const applyVectorModifiers = (vector, version, pocAvailable, execPath) => {
// Parse the vector string into an object
const vectorParams = vector.split('/').reduce((acc, param) => {
const [key, value] = param.split(':');
acc[key] = value;
return acc;
}, {});

// Update the Exploit Code Maturity if pocAvailable is true
if (!pocAvailable) {
vectorParams.E = 'U';
vectorParams.RL = version === 'V2' ? 'ND' : 'X';
vectorParams.RC = version === 'V2' ? 'ND' : 'X';
}

// Update the Attack Complexity and User Interaction if execPath is true
if (!execPath && version === 'V3') {
vectorParams.MAC = 'H';
vectorParams.MUI = 'R';
}

// Construct the updated vector string
const updatedVector = Object.entries(vectorParams)
.map(([key, value]) => `${key}:${value}`)
.join('/');

return updatedVector;
};


function getSeverity(version, score) {
const ratings = {
'V2': [
Expand Down Expand Up @@ -115,7 +115,6 @@ const applyContextualCVSS = (item, type, imageHardened)=> {
let score = item[type].SeverityScore;
let severity = item[type].Severity;
if (vector !== '-') {
// execPath = if image is not hardened then false, if hardened than based on image
vector = applyVectorModifiers(vector, version, item.RRS === 1, !imageHardened || item.hardened)
let parsedData = parseCVSS(vector, version);
score = parsedData;
Expand Down Expand Up @@ -200,7 +199,6 @@ const convertVulnsData = (data, imageHardened, isHardened, flags) => {
const seenVulns = new Map();
const seenNotApplicableVulns = new Map();
const hardenedVulnsFlags = {}
// if its app then dont group vulns
let appKeyIndex = 0;
data?.forEach?.((cur, index) => {
cur?.Vulnerabilities?.forEach?.((item)=> {
Expand All @@ -209,14 +207,10 @@ const convertVulnsData = (data, imageHardened, isHardened, flags) => {
appKey = cur.Type;
}
if (isHardened) {
item.marker = 'error'
item.hardened = true;
item.inUse = true;
hardenedVulnsFlags[`i:${item.VulnerabilityID}|v${item.InstalledVersion}|p${item.PkgName}`] = true
} else {
item.hardened = flags[`i:${item.VulnerabilityID}|v${item.InstalledVersion}|p${item.PkgName}`]
item.inUse = flags[`i:${item.VulnerabilityID}|v${item.InstalledVersion}|p${item.PkgName}`];
item.marker = item.hardened ? 'error' : 'success'
}
item.applicable = item.RFJustification?.status === 'na' ? false : true;
item.Severity = (item.Severity) ? item.Severity : 'UNKNOWN'
Expand All @@ -235,7 +229,8 @@ const convertVulnsData = (data, imageHardened, isHardened, flags) => {
seenNotApplicableVulns.set(key, item);
}
}
const advisories = ['nvd', 'default', 'rfcvss_default', 'rfcvss_nvd'];
const advisories = ['default', 'rfcvss_default'];
// const advisories = ['default', 'rfcvss_default', 'nvd', 'rfcvss_nvd'];
advisories.forEach(advisory => {
const severitykey = item[advisory]?.Severity.toLowerCase() ?? 'unknown'
if (item.applicable) {
Expand Down

0 comments on commit c5ba8ca

Please sign in to comment.