Correlating CVEs with inventory: version ranges without guessing
Matching a CVE to inventory software: where the Syscollector version comes from, how to read ranges in CVE JSON 5 and NVD, and when the result is UNKNOWN.
Vulnerability detection without a reliable product version gives false precision. Correlation works when each source is responsible for one thing: the inventory for the observed version and package identity, the vulnerability sources for the vulnerable version ranges, and separate logic for comparing one with the other.
Where to get the observed version
The Wazuh documentation describes Syscollector as an agent module that collects, among other things, installed software. The data goes to the server, to each agent’s local SQLite database, and the state is indexed in the indexer. For packages, the documentation gives the table sys_programs and the indices wazuh-states-inventory-packages-*. On Linux, packages can have the format deb, pacman or rpm.
Fields used in correlation:
| Syscollector field | Indexer field | Type | Notes |
|---|---|---|---|
| name | package.name | keyword | Package name |
| version | package.version | keyword | Version, for example 4.4.0.130.136 |
| format | package.type | keyword | For example deb |
| architecture | package.architecture | keyword | For example amd64 |
| vendor | package.vendor | keyword | Vendor name |
| source | package.source | keyword | Source package, for deb, rpm and pkg on macOS |
| agent_id | agent.id | keyword | Agent identifier |
The same inventory can be fetched through the server API: GET /syscollector/{agent_id}/packages with the parameters name, limit, offset, search, select, query and others. The sample version values in the API specification show what you have to deal with: 8.4.0-1ubuntu1~18.04 and 1:8.2p1-4ubuntu0.2, that is versions with a tilde, a distribution revision and an epoch.
The version field has the type keyword, so it is text. A version range therefore cannot be reliably expressed as a range query on this field in the index. The OpenSearch documentation used here does not describe string comparisons, so I base no assumptions on it. The comparison is done by separate code that fetches the version from the index or the API.
A version from the inventory is an observation from the agent. A version entered by hand in a CMDB or read from purchasing documentation is a declaration and should be marked differently in the report.
What Wazuh itself does
The Vulnerability Detection module correlates the inventory with data from the Wazuh CTI platform. According to the documentation, “a package is flagged as vulnerable when its version falls within the CVE’s vulnerable range”. The CTI sources are operating system vendors (among others Ubuntu, Debian, RHEL, SUSE) and databases such as NVD, OSV, CISA and Microsoft Security Updates. The VDP component normalizes the data to the CVE JSON v5 format, fixes inconsistencies such as “version mismatches and typos”, and combines vendor content with the product name mapping and the baseline rules of the systems. The details of how the module works and its configuration are described in the post on Vulnerability Detection in Wazuh.
The result goes to the index wazuh-states-vulnerabilities-server. The sample document from the documentation contains the fields package.name, package.version, vulnerability.id, vulnerability.severity, vulnerability.score.base and vulnerability.scanner.condition with content like Package less than 136.0.7103.59, and vulnerability.scanner.source with the source name. The scanner.condition field shows which boundary was applied, so in a dispute over a result it is the first place to check. The retention of such indices affects the history of findings, which the post on OpenSearch retention describes.
Your own correlation with other version sources, for example with an inventory of network devices, is not a Wazuh feature, but you can build it alongside it.
What a version range looks like in a CVE record
The CVE JSON 5 format (the CVEProject schema) describes vulnerable versions in the affected array. The product is identified by vendor and product or by collectionURL and packageName. The record must contain versions or defaultStatus. The versions elements have these fields:
| Field | Meaning according to the schema |
|---|---|
| version | A single version or the start of a range. By convention 0 means the earliest possible version |
| status | affected, unaffected or unknown |
| versionType | The numbering system that determines the comparison semantics. Examples: custom, git, maven, python, rpm, semver |
| lessThan | Exclusive upper bound of the range. The pattern may end with an asterisk |
| lessThanOrEqual | Inclusive upper bound of the range |
| changes | Status changes inside the range, fields at and status |
The schema also describes the resolution algorithm. A single entry without lessThan and lessThanOrEqual matches by equality. An entry with a range covers versions V for which version <= V and V < lessThan (or V <= lessThanOrEqual), where the operators are defined by versionType. Then changes with at <= V are applied. If no entry matches, the result is defaultStatus, and when there is none, unknown by default. The schema describes the custom value of versionType as one that “should be avoided”, because the comparison semantics are then undefined.
A synthetic example in this format:
{
"affected": [
{
"vendor": "example-vendor",
"product": "example-lib",
"defaultStatus": "unaffected",
"versions": [
{
"version": "1.9.0",
"status": "affected",
"versionType": "semver",
"lessThan": "1.10.5"
}
]
}
]
}
What a range looks like in NVD
The NVD API 2.0 schema describes product matching in the cpeMatch object with the fields vulnerable, criteria (the CPE name), matchCriteriaId and the boundaries: versionStartIncluding, versionStartExcluding, versionEndIncluding and versionEndExcluding. Configuration nodes have an AND or OR operator and a negate flag. The schema defines field names, it does not define the semantics of comparing version strings, so the same problem as above remains on the consumer side.
{
"vulnerable": true,
"criteria": "cpe:2.3:a:example-vendor:example-lib:*:*:*:*:*:*:*:*",
"matchCriteriaId": "00000000-0000-4000-8000-000000000000",
"versionStartIncluding": "1.9.0",
"versionEndExcluding": "1.10.5"
}
The correspondence of versionStartIncluding to version and versionEndExcluding to lessThan is my reading. The schemas do not state it. When ranges are expressed with different fields, the boundaries have to be translated into one representation before comparison.
Why string comparison fails
The SemVer specification says that every version element “MUST increase numerically”, with the example 1.9.0 -> 1.10.0 -> 1.11.0. Lexical comparison returns the opposite result for this pair. For the range from the example above (1.9.0 <= V < 1.10.5) and the observed version 1.10.2:
| Method | Result | Reasoning |
|---|---|---|
| String comparison | NOT_AFFECTED, wrongly | The string 1.10.2 is smaller than 1.9.0, because the character 1 is smaller than 9 |
| Numeric segment comparison | AFFECTED | 1.9.0 is smaller than 1.10.2, and 1.10.2 is smaller than 1.10.5 |
Further SemVer rules that a parser has to implement:
- A pre-release has lower precedence than the normal version:
1.0.0-alpha < 1.0.0. - Pre-release identifiers made of digits are compared numerically, the others lexically in ASCII order, and numeric ones are lower than non-numeric ones. Example from the document:
1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0. - Build metadata (
+build) does not affect precedence.
Debian packages use a different scheme. Debian Policy defines a version as [epoch:]upstream_version[-debian_revision]. Comparison starts with the epoch (numerically, absence means 0), then upstream_version, then the revision (absence means 0). The parts are compared alternately: a non-digit fragment lexically, with the modification that letters sort before non-letters and the tilde sorts before everything, then a digit fragment numerically. The policy gives the order ~~, ~~a, ~, empty fragment, a. Conventions such as +debNuX and ~debNuX in the revision mean updates of a stable version, and +really means a return to an older upstream version.
The consequence: the version 1:8.2p1-4ubuntu0.2 from the API example is not comparable with a plain boundary 9.0 from a CVE record without a decision on what to do with the epoch and the distribution revision. Wazuh solves this through the system vendors’ data in CTI, and with your own correlation you have to solve it separately or mark the result as ambiguous.
Proposed result model
The model below is a design recommendation. Every match of an asset to a CVE ends in one of four states:
| State | Condition |
|---|---|
| AFFECTED | Confirmed product identity, version from an observation, a known versionType with a working parser, the version in a range with status affected and not overridden by changes |
| NOT_AFFECTED | The same certainty as above, the version outside all vulnerable ranges, or status unaffected from the record, or defaultStatus equal to unaffected with an explicit entry |
| UNKNOWN | No observed version, no product match, or status unknown in the record |
| AMBIGUOUS | The version and product are known, but the result depends on an uncertain step: versionType equal to custom or unsupported, a boundary with an asterisk that the parser does not expand, an epoch or distribution revision without a rule, or the sources give conflicting statuses |
Rules of use:
- Missing data is never turned into NOT_AFFECTED. The UNKNOWN state is a result and must be visible in the report, just like AMBIGUOUS.
- The version parser is chosen by the record’s
versionType, and when the source does not give it, by the package format (package.type). Each parser has tests on range boundaries: equality with the boundary,lessThanversuslessThanOrEqual, pre-release, epoch, tilde. - The result records the boundary used, the
versionTypeand the data source, likevulnerability.scanner.conditionin Wazuh. Without this the decision cannot be reproduced. - A conflict between sources (for example NVD versus the system vendor) gives AMBIGUOUS until someone designates the authoritative source. The documentation does not say which source wins.
A trial run on a copy of the data should not write to the production index or trigger alerts. Only a comparison with the Wazuh result for the same agents shows the discrepancies to explain. The prioritization of confirmed AFFECTED by likelihood of exploitation is described in the post on EPSS and CISA KEV.
What the documentation does not specify
- How the Vulnerability Detection module compares versions for individual package formats and how it treats backports, epochs and
versionTypeequal to custom. - Which source takes precedence when the system vendor and NVD data conflict.
- The semantics of the
versionStart*andversionEnd*fields beyond their names do not follow from the official NVD JSON schema. - Whether the
keywordtype of thepackage.versionfield affects range queries in OpenSearch. The OpenSearch documentation used here does not describe it. - The states AFFECTED, NOT_AFFECTED, UNKNOWN and AMBIGUOUS are the author’s design model. CVE JSON 5 defines only the statuses affected, unaffected and unknown.
Sources
- https://documentation.wazuh.com/current/user-manual/capabilities/vulnerability-detection/how-it-works.html
- https://documentation.wazuh.com/current/user-manual/capabilities/system-inventory/index.html
- https://documentation.wazuh.com/current/user-manual/capabilities/system-inventory/available-inventory-fields.html
- https://documentation.wazuh.com/current/_static/server-api-spec/spec-v4.14.10.yaml
- https://raw.githubusercontent.com/CVEProject/cve-schema/main/schema/CVE_Record_Format.json
- https://csrc.nist.gov/schema/nvd/api/2.0/cve_api_json_2.0.schema
- https://semver.org/
- https://www.debian.org/doc/debian-policy/ch-controlfields.html