Skip to content

Commit

Permalink
Add: Setting to enable new CVE scan CPE matching
Browse files Browse the repository at this point in the history
The setting "CVE-CPE Matching Version" has been added that allows
switching between the old "affected products" based matching for CVE
scans and the new one based on the extended matching rules.
For now the old version will be used by default.
  • Loading branch information
timopollmeier committed Jan 23, 2025
1 parent 9e5c86e commit 86ef200
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -3483,11 +3483,18 @@ cve_scan_report_host_json (task_t task,
* @param[in] task Task.
* @param[in] report The report to add the host, results and details to.
* @param[in] gvm_host Host.
* @param[in] matching_version The CPE-CVE matching version (0 or 1) to use.
*
* With version 0 matching, CPEs are only compared to the affected products
* lists of CVEs.
* With version 1 matching, CPEs are matched by evaluating the match criteria
* for the CVEs.
*
* @return 0 success, 1 failed to get nthlast report for a host.
*/
static int
cve_scan_host (task_t task, report_t report, gvm_host_t *gvm_host)
cve_scan_host (task_t task, report_t report, gvm_host_t *gvm_host,
int matching_version)
{
report_host_t report_host;
gchar *ip, *host;
Expand Down Expand Up @@ -3533,7 +3540,8 @@ cve_scan_host (task_t task, report_t report, gvm_host_t *gvm_host)
start_time = time (NULL);
prognosis_report_host = 0;

if (sql_int64_0 ("SELECT count(1) FROM information_schema.tables"
if (matching_version == 1 &&
sql_int64_0 ("SELECT count(1) FROM information_schema.tables"
" WHERE table_schema = 'scap'"
" AND table_name = 'cpe_match_nodes';") > 0)
{
Expand Down Expand Up @@ -3780,8 +3788,11 @@ fork_cve_scan_handler (task_t task, target_t target)
}
free (exclude_hosts);

int matching_version;
setting_value_int(SETTING_UUID_CVE_CPE_MATCHING_VERSION, &matching_version);

while ((gvm_host = gvm_hosts_next (gvm_hosts)))
if (cve_scan_host (task, global_current_report, gvm_host))
if (cve_scan_host (task, global_current_report, gvm_host, matching_version))
{
set_task_interrupted (task,
"Failed to get nthlast report."
Expand Down
27 changes: 25 additions & 2 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -16310,6 +16310,17 @@ check_db_settings ()
" 'User Interface Date Format',"
" 'Preferred date format to be used in client user interfaces.',"
" 'system_default' );");

if (sql_int ("SELECT count(*) FROM settings"
" WHERE uuid = '" SETTING_UUID_CVE_CPE_MATCHING_VERSION "'"
" AND " ACL_IS_GLOBAL () ";")
== 0)
sql ("INSERT into settings (uuid, owner, name, comment, value)"
" VALUES"
" ('" SETTING_UUID_CVE_CPE_MATCHING_VERSION "', NULL,"
" 'CVE-CPE Matching Version',"
" 'Version of the CVE-CPE matching used in CVE scans.',"
" '0' );");
}

/**
Expand Down Expand Up @@ -53565,6 +53576,8 @@ setting_name (const gchar *uuid)
return "Feed Import Roles";
if (strcmp (uuid, SETTING_UUID_SECINFO_SQL_BUFFER_THRESHOLD) == 0)
return "SecInfo SQL Buffer Threshold";
if (strcmp (uuid, SETTING_UUID_CVE_CPE_MATCHING_VERSION) == 0)
return "CVE-CPE Matching Version";

return NULL;
}
Expand Down Expand Up @@ -53605,6 +53618,8 @@ setting_description (const gchar *uuid)
if (strcmp (uuid, SETTING_UUID_SECINFO_SQL_BUFFER_THRESHOLD) == 0)
return "Buffer size threshold in MiB for running buffered SQL statements"
" in SecInfo updates before the end of the file being processed.";
if (strcmp (uuid, SETTING_UUID_CVE_CPE_MATCHING_VERSION) == 0)
return "Version of the CVE-CPE matching used in CVE scans.";

return NULL;
}
Expand Down Expand Up @@ -53700,6 +53715,12 @@ setting_verify (const gchar *uuid, const gchar *value, const gchar *user)
return 1;
}

if (strcmp (uuid, SETTING_UUID_CVE_CPE_MATCHING_VERSION) == 0)
{
if (strcmp (value, "0") && strcmp (value, "1"))
return 1;
}

return 0;
}

Expand Down Expand Up @@ -53794,7 +53815,8 @@ manage_modify_setting (GSList *log_config, const db_conn_info_t *database,
&& strcmp (uuid, SETTING_UUID_LSC_DEB_MAINTAINER)
&& strcmp (uuid, SETTING_UUID_FEED_IMPORT_OWNER)
&& strcmp (uuid, SETTING_UUID_FEED_IMPORT_ROLES)
&& strcmp (uuid, SETTING_UUID_SECINFO_SQL_BUFFER_THRESHOLD))
&& strcmp (uuid, SETTING_UUID_SECINFO_SQL_BUFFER_THRESHOLD)
&& strcmp (uuid, SETTING_UUID_CVE_CPE_MATCHING_VERSION))
{
fprintf (stderr, "Error in setting UUID.\n");
return 3;
Expand Down Expand Up @@ -53822,7 +53844,8 @@ manage_modify_setting (GSList *log_config, const db_conn_info_t *database,
if ((strcmp (uuid, SETTING_UUID_DEFAULT_CA_CERT) == 0)
|| (strcmp (uuid, SETTING_UUID_FEED_IMPORT_OWNER) == 0)
|| (strcmp (uuid, SETTING_UUID_FEED_IMPORT_ROLES) == 0)
|| (strcmp (uuid, SETTING_UUID_SECINFO_SQL_BUFFER_THRESHOLD) == 0))
|| (strcmp (uuid, SETTING_UUID_SECINFO_SQL_BUFFER_THRESHOLD) == 0)
|| (strcmp (uuid, SETTING_UUID_CVE_CPE_MATCHING_VERSION) == 0))
{
sql_rollback ();
fprintf (stderr,
Expand Down
5 changes: 5 additions & 0 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@
*/
#define SETTING_UUID_USER_INTERFACE_DATE_FORMAT "d9857b7c-1159-4193-9bc0-18fae5473a69"

/**
* @brief UUID of 'CVE-CPE Matching Version' setting.
*/
#define SETTING_UUID_CVE_CPE_MATCHING_VERSION "2e8a8ccc-219f-4a82-824a-3ad88b6d4029"

/**
* @brief Trust constant for error.
*/
Expand Down

0 comments on commit 86ef200

Please sign in to comment.