Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@ toc_hide: true

# ReversingLabs Spectra Assure Parser

The Spectra Assure platform is a set of [ReversingLabs](https://www.reversinglabs.com/) solutions primarily designed for software assurance and software supply chain security use-cases.
Spectra Assure Assets analyze compiled software packages, their components and third-party dependencies to detect exposures, reduce vulnerabilities, and eliminate threats before reaching production.
The Spectra Assure platform is a set of [ReversingLabs](https://www.reversinglabs.com/) solutions
primarily designed for software assurance and software supply chain security use-cases.
Spectra Assure products analyze compiled software packages,
their components and third-party dependencies to detect exposures,
reduce vulnerabilities, and eliminate threats before reaching production.

Every Spectra Assure analysis (software scan) produces a set of reports and the overall CI status (pass or fail) for the analyzed software package.
The reports are created in multiple different formats, with different level of detail and scope of information about the analysis results.
The official documentation describes all [supported report formats](https://docs.secure.software/concepts/analysis-reports) in Spectra Assure.
Every Spectra Assure analysis (software scan) produces a set of reports
and the overall CI status (pass or fail) for the analyzed software package.
The reports are created in multiple different formats,
with different level of detail and scope of information about the analysis results.
The official documentation describes all
[supported report formats](https://docs.secure.software/concepts/analysis-reports)
in Spectra Assure.

**The primary purpose of this parser is extracting known vulnerabilities (CVEs/GHSA) that are present in the `components` and `dependencies` sections of the `rl-json` report.**

It also reports failing **secrets** and **threats** (malware) policy violations.

**The primary purpose of this parser is extracting known vulnerabilities (CVEs) that are present in the `components` and `dependencies` sections of the `rl-json` report.**

### File Types

The parser accepts only `report.rl.json` files (the Spectra Assure [rl-json report](https://docs.secure.software/concepts/analysis-reports#rl-json)).
The parser accepts only `report.rl.json` files
(the Spectra Assure [rl-json report](https://docs.secure.software/concepts/analysis-reports#rl-json)).

You can find instructions for exporting the `rl-json` report in the documentation of the Spectra Assure Asset you're using.
You can find instructions for exporting the `rl-json` report in the documentation of the Spectra Assure product you're using.

- [Spectra Assure CLI](https://docs.secure.software/cli/commands/report).
- [Spectra Assure Portal](https://docs.secure.software/api-reference/#tag/Version/operation/getVersionReport).
Expand All @@ -36,69 +47,111 @@ For the specification of the `rl-json` report, consult the official Spectra Assu

### Field Mapping Details

The parser creates two kinds of findings:

- **Vulnerability findings**: one per active vulnerability (CVE or GHSA) on a component,
or on a dependency found inside a component. Only the `active` vulnerabilities are imported.
- **Policy violation findings**: one per component referenced by a failing `threats` or `secrets` policy violation.

The finding date is the scan date (the report `timestamp`); a report without a valid `timestamp` is rejected.


#### Title

##### Component
##### Vulnerability on a component

`<vulnerability id> on component: purl: <component purl> (sha256 <first 8 characters>)`

Without a purl, `purl: <purl>` is replaced by `<name> version <version>`; an empty name or version is left out.

For a component, the title includes:
##### Vulnerability on a dependency

- the CVE
- the type: `Component`
- the `purl` of the `Component` if present; otherwise name and version
`<vulnerability id> on dependency: purl: <dependency purl> (sha256 <first 8 characters>)`

Without a purl, `purl: <purl>` is replaced by `<dependency name> version <dependency version>`; an empty part is left out.
The sha256 is that of the component the dependency was found in.

##### Dependency
##### Policy violation

For a dependency, the title includes:
`<violation description> (<category>) on <component name> (sha256 <first 8 characters>)`

The short sha256 is there because one name can stand for several different binaries:
an installer may ship a build per language, all with the same name and the same install path.
Without it those findings would be identical rows in the findings list.

- the CVE
- the type: `Dependency`
- the `purl` of the `Dependency` if present; otherwise name and version

#### Description

##### Component
Every description starts with the title as a heading.

##### Vulnerabilities

The vulnerability summary, followed by the component the vulnerability was found in:
its purl (without a purl, `item: <name> <version>`), the path and the full sha256.
The full sha256 is included because a file scan may have multiple components with the same name and version,
but with different hashes; typically this happens with multi-language Windows installer packages.

When the same binary (same sha256) sits at more than one path in one report, the finding is reported once:
the number of occurrences is incremented and each extra path is added as an `- also at: <path>` line.

For a component, the description repeats the information from the [title](#title) and includes the SHA256 hash of the component.
##### Policy violations

The SHA256 is included because sometimes a file scan may have multiple items with the same name and version, but with different hashes.
Typically this happens with multi-language Windows installer packages.
- `threats`: the threat name from the component classification, e.g. `Threat name: Win32.Trojan.Example`.
- `secrets`: for each secret detected on the component (service, timestamp, exposed)
and each piece of evidence (liveness, file offset, line number, canary), as a fenced block.
When the report holds no secret detail for that rule and component, the description has the title only.


##### Dependency
#### Severity

For a dependency, the description repeats the information from the [title](#title) and includes the component path, `component-name` and `component-hash`.
For duplicates, the description includes an additional line showing the title and component of each duplicate.
Vulnerability findings: from the CVSS base score.

#### Vulnerabilities
| CVSS v3.x / v4.0 | CVSS v2 | Severity |
|------------------|-----------|----------|
| 9.0 - 10.0 | | Critical |
| 7.0 - 8.9 | 7.0 - 10 | High |
| 4.0 - 6.9 | 4.0 - 6.9 | Medium |
| 0.1 - 3.9 | 0 - 3.9 | Low |
| 0 or no score | | Info |

For vulnerabilities, the following information is retrieved:
The base score is stored in `CVSSv3 score` or `CVSSv4 score`, depending on the CVSS version; a v2 score is not stored.

- the CVE unique ID
- CVSS version
- CVSS base score
Policy violation findings: the severity of the violation in the report; an unknown severity becomes `Info`.

From the CVSS base score, we map the severity into:

- Info
- Low
- Medium
- High
- Critical
#### Other fields

- `Vulnerability Id` and `vuln_id_from_tool`: the CVE or GHSA id. For policy violations there is no vulnerability id
and `vuln_id_from_tool` is `<category>-<rule_id>`, e.g. `secrets-SQ34304`.
- `Component Name` / `Component Version`: the component; for a vulnerable dependency, the dependency.
The version is the one in the report, except that `Generic` (Spectra Assure's version for a file without a version
of its own) on a component without a purl is no version: it is left out of the field, the title and the description.
- `File Path`: the path of the component in the scanned package.
- Tags and impact: the exploit information of the vulnerability, as `Fix Available`, `Exploit Exists`,
`Exploited by Malware` and `Patching Mandated`. `Patching Mandated` also sets `Known Exploited`.
The exploit states `UNPROVEN` ("CVE Discovered" in the Portal) and `TRIAGED` give no tag and no impact line.
- All findings are static findings.

If no mapping is matched, the default severity is `Info`.

##### Notes

- Currently, no endpoints are created.
- Deduplication is done with sha256 if the title.
- On detecting a duplicate dependency, we increment the number of occurrences. Components have no duplicates, so the number of occurrences is always 1.
- We extract the scan date, the Spectra Assure scanner version, and set a static scanner name.
- No endpoints are created.
- With `V3_FEATURE_LOCATIONS` enabled, each vulnerability finding whose package has a purl gets one `dependency` location
naming the vulnerable package (for a vulnerable dependency, the dependency itself, not the component containing it)
and the path of the component it was found in. Policy violation findings carry no package, so they get no location.
- Deduplication uses the `hash_code` algorithm on `unique_id_from_tool`, `component_name` and `component_version`.
`unique_id_from_tool` is the vulnerability id (or `<category>-<rule_id>` for a policy violation) plus the sha256 of the
component file it was found in, e.g. `CVE-2016-9840/sha256:0c0d54b2...`. A different sha256 is a different binary,
so it is a different finding, even under the same name and path. Without a sha256 the component path is used.
- Earlier versions of this parser deduplicated on a sha256 of the title. Findings imported with an earlier version
will not match findings imported with this version.


### Sample Scan Data or Unit Tests

- [Sample Scan Data Folder](https://github.com/DefectDojo/django-DefectDojo/tree/master/unittests/scans/reversinglabs_spectraassure)


### Link To Tool

- [Spectra Assure Cli](https://docs.secure.software/cli/)
Expand Down
2 changes: 2 additions & 0 deletions dojo/settings/settings.dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param
# is what every result family assigns to "title" as well.
"Checkmarx One Scan": ["unique_id_from_tool"],
"OPF Scan": ["title", "cwe", "severity", "description"],
"ReversingLabs Spectra Assure": ["unique_id_from_tool", "component_name", "component_version"],
}

# Override the hardcoded settings here via the env var
Expand Down Expand Up @@ -2020,6 +2021,7 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param
# The parser builds a stable unique_id_from_tool for every finding (detector, kind, target, path and the
# certificate or image that tells findings at one path apart), so no hash_code fallback is needed.
"Early Light Scan": DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL,
"ReversingLabs Spectra Assure": DEDUPE_ALGO_HASH_CODE,
}

# Override the hardcoded settings here via the env var
Expand Down
112 changes: 66 additions & 46 deletions dojo/tools/reversinglabs_spectraassure/parser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# noqa: RUF100
import hashlib
import logging
from typing import Any

from dojo.location.feature import locations_enabled
from dojo.models import Finding
from dojo.tools.locations import LocationData
from dojo.tools.reversinglabs_spectraassure.rlJsonInfo import RlJsonInfo
from dojo.tools.reversinglabs_spectraassure.rlJsonInfo.cve_info_node import CveInfoNode
from dojo.tools.reversinglabs_spectraassure.rl_json_info import RlJsonInfo
from dojo.tools.reversinglabs_spectraassure.rl_json_info.cve_info_node import CveInfoNode

logger = logging.getLogger(__name__)

Expand All @@ -16,80 +15,93 @@
"""
The actual parsing is done by `RlJsonInfo` and it stores data as a collection of `CveInfoNode`
A `CveInfoNode` matches a dd.Finding more closely and makes the collection of Findings easy.

"""


class ReversinglabsSpectraassureParser:

# --------------------------------------------
# This class MUST have an empty constructor or no constructor

def _find_duplicate(self, key: str) -> Finding | None:
logger.debug("")

if key in self._duplicates:
return self._duplicates

return None

def _make_hash(
self,
data: str,
) -> str:
# Calculate SHA-256 hash
d = data.encode()
return hashlib.sha256(d).hexdigest()
@staticmethod
def _unique_id(node: CveInfoNode) -> str:
# What was found, in which exact component file. A different sha256 is a different binary even
# under the same name and path (HxD ships one per language), so it must be a different finding.
# Without a sha256, fall back to the component path.
where = (
f"sha256:{node.component_file_sha256}" if node.component_file_sha256 else f"path:{node.component_file_path}"
)
return f"{node.vuln_id_from_tool}/{where}"

def _one_finding(
self,
*,
node: CveInfoNode,
test: Any,
) -> Finding:
logger.debug("%s", node)
logger.debug("_one_finding: %s", node)

cvssv3_score = None
if node.cvss_version == 3:
cvssv3_score = node.score or None

cvssv4_score = None
if node.cvss_version == 4:
cvssv4_score = node.score or None

description = f"# {node.title}\n\n{node.description}" # CommonMark needs the space after '#'

key = self._make_hash(node.title + " " + node.component_file_path)
cve = node.cve
finding = Finding(
date=node.scan_date,
title=node.title,
description=node.title + " " + node.description + "\n",
cve=cve,
cvssv3_score=node.score,
description=description,
cve=node.cve,
cvssv3_score=cvssv3_score,
cvssv4_score=cvssv4_score,
severity=node.score_severity,
vuln_id_from_tool=node.vuln_id_from_tool,
file_path=node.component_file_path,
component_name=node.component_name,
component_version=node.component_version,
# empty -> None: DefectDojo hashes the unsaved finding (import and reimport) but stores blank component
# fields as NULL, so an empty string would hash differently from any later recompute ('' vs 'None')
component_name=node.component_name or None,
component_version=node.component_version or None,
nb_occurences=1,
hash_code=key, # sha256 on title
unique_id_from_tool=self._unique_id(node),
references=None, # future: urls
active=True, # this is the DefectDojo active field, nothing to do with node.active field
test=test,
static_finding=True,
dynamic_finding=False,
known_exploited=node.known_exploited,
)
finding.unsaved_vulnerability_ids = [cve]

finding.unsaved_vulnerability_ids = [node.cve] if node.cve else []
finding.unsaved_tags = node.tags
finding.impact = node.impact

# Locations (V3_FEATURE_LOCATIONS): attach the vulnerable package as a dependency location.
# component_purl is the dependency's purl for dependency findings and the component's own
# purl otherwise; policy violation findings have none and get no location.
# Check locations_enabled() first: with the feature off, Finding has no unsaved_locations.
if locations_enabled() and node.component_purl:
finding.unsaved_locations.append(
LocationData.dependency(purl=node.component_purl),
LocationData.dependency(purl=node.component_purl, file_path=node.component_file_path),
)

return finding

# --------------------------------------------
# PUBLIC
def get_scan_types(self) -> list[str]:
logger.debug("get_scan_types")
return [SCAN_TYPE]

def get_label_for_scan_types(self, scan_type: str) -> str:
logger.debug("get_label_for_scan_types")
return scan_type

def get_description_for_scan_types(self, scan_type: str) -> str:
logger.debug("get_description_for_scan_types")

if scan_type == SCAN_TYPE:
return "Import the SpectraAssure report.rl.json file."
return f"Unknown Scan Type; {scan_type}"
Expand All @@ -99,31 +111,39 @@ def get_findings(
file: Any,
test: Any,
) -> list[Finding]:
# ------------------------------------
rl_json_info_instance = RlJsonInfo(file_handle=file)
rl_json_info_instance.get_cve_active_all()
logger.debug("get_findings")

self._findings: list[Finding] = []
self._duplicates: dict[str, Finding] = {}
self._duplicates: dict[tuple[str, str, str], Finding] = {}

try:
info = RlJsonInfo(file_handle=file)
info.build_findings()
nodes = list(info.get_results_list())
except (ValueError, KeyError, TypeError) as e:
msg = f"Not a valid Spectra Assure rl.json report: {e}"
raise ValueError(msg) from e

for cve_info_node_instance in rl_json_info_instance.get_results_list():
for node in nodes:
finding = self._one_finding(
node=cve_info_node_instance,
node=node,
test=test,
)
if finding is None:
continue

key = finding.hash_code
if key not in self._duplicates:
# The identity DefectDojo hashes (HASHCODE_FIELDS_PER_SCANNER). Within one report a repeat is the
# same component file showing the same issue again, e.g. one binary at two paths: count it and note
# where, instead of appending the whole description again.
# built from the node (str), not read back from the Finding, where these fields are Optional
key = (self._unique_id(node), node.component_name, node.component_version)
dup = self._duplicates.get(key)
if dup is None:
self._findings.append(finding)
self._duplicates[key] = finding
continue

dup = self._duplicates[key]
if dup:
dup.description += finding.description
dup.nb_occurences += 1
dup.nb_occurences += 1
also = f"- also at: {finding.file_path}"
if finding.file_path != dup.file_path and also not in dup.description:
dup.description = f"{dup.description.rstrip()}\n{also}\n"

# ------------------------------------
return self._findings
Loading
Loading