Skip to content

Commit 233a92b

Browse files
committed
Add: Setting to enable new CVE scan CPE matching
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.
1 parent 9e5c86e commit 233a92b

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

src/manage.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -3483,11 +3483,18 @@ cve_scan_report_host_json (task_t task,
34833483
* @param[in] task Task.
34843484
* @param[in] report The report to add the host, results and details to.
34853485
* @param[in] gvm_host Host.
3486+
* @param[in] matching_version The CPE-CVE matching version (0 or 1) to use.
3487+
*
3488+
* With version 0 matching, CPEs are only compared to the affected products
3489+
* lists of CVEs.
3490+
* With version 1 matching, CPEs are matched by evaluating the match criteria
3491+
* for the CVEs.
34863492
*
34873493
* @return 0 success, 1 failed to get nthlast report for a host.
34883494
*/
34893495
static int
3490-
cve_scan_host (task_t task, report_t report, gvm_host_t *gvm_host)
3496+
cve_scan_host (task_t task, report_t report, gvm_host_t *gvm_host,
3497+
int matching_version)
34913498
{
34923499
report_host_t report_host;
34933500
gchar *ip, *host;
@@ -3533,7 +3540,8 @@ cve_scan_host (task_t task, report_t report, gvm_host_t *gvm_host)
35333540
start_time = time (NULL);
35343541
prognosis_report_host = 0;
35353542

3536-
if (sql_int64_0 ("SELECT count(1) FROM information_schema.tables"
3543+
if (matching_version == 1 &&
3544+
sql_int64_0 ("SELECT count(1) FROM information_schema.tables"
35373545
" WHERE table_schema = 'scap'"
35383546
" AND table_name = 'cpe_match_nodes';") > 0)
35393547
{
@@ -3780,8 +3788,11 @@ fork_cve_scan_handler (task_t task, target_t target)
37803788
}
37813789
free (exclude_hosts);
37823790

3791+
int matching_version;
3792+
setting_value_int(SETTING_UUID_CVE_CPE_MATCHING_VERSION, &matching_version);
3793+
37833794
while ((gvm_host = gvm_hosts_next (gvm_hosts)))
3784-
if (cve_scan_host (task, global_current_report, gvm_host))
3795+
if (cve_scan_host (task, global_current_report, gvm_host, matching_version))
37853796
{
37863797
set_task_interrupted (task,
37873798
"Failed to get nthlast report."

src/manage_sql.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -16310,6 +16310,17 @@ check_db_settings ()
1631016310
" 'User Interface Date Format',"
1631116311
" 'Preferred date format to be used in client user interfaces.',"
1631216312
" 'system_default' );");
16313+
16314+
if (sql_int ("SELECT count(*) FROM settings"
16315+
" WHERE uuid = '" SETTING_UUID_CVE_CPE_MATCHING_VERSION "'"
16316+
" AND " ACL_IS_GLOBAL () ";")
16317+
== 0)
16318+
sql ("INSERT into settings (uuid, owner, name, comment, value)"
16319+
" VALUES"
16320+
" ('" SETTING_UUID_CVE_CPE_MATCHING_VERSION "', NULL,"
16321+
" 'CVE-CPE Matching Version',"
16322+
" 'Version of the CVE-CPE matching used in CVE scans.',"
16323+
" '0' );");
1631316324
}
1631416325

1631516326
/**
@@ -53565,6 +53576,8 @@ setting_name (const gchar *uuid)
5356553576
return "Feed Import Roles";
5356653577
if (strcmp (uuid, SETTING_UUID_SECINFO_SQL_BUFFER_THRESHOLD) == 0)
5356753578
return "SecInfo SQL Buffer Threshold";
53579+
if (strcmp (uuid, SETTING_UUID_CVE_CPE_MATCHING_VERSION) == 0)
53580+
return "CVE-CPE Matching Version";
5356853581

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

5360953624
return NULL;
5361053625
}
@@ -53700,6 +53715,12 @@ setting_verify (const gchar *uuid, const gchar *value, const gchar *user)
5370053715
return 1;
5370153716
}
5370253717

53718+
if (strcmp (uuid, SETTING_UUID_CVE_CPE_MATCHING_VERSION) == 0)
53719+
{
53720+
if (strcmp (value, "0") && strcmp (value, "1"))
53721+
return 1;
53722+
}
53723+
5370353724
return 0;
5370453725
}
5370553726

@@ -53794,7 +53815,8 @@ manage_modify_setting (GSList *log_config, const db_conn_info_t *database,
5379453815
&& strcmp (uuid, SETTING_UUID_LSC_DEB_MAINTAINER)
5379553816
&& strcmp (uuid, SETTING_UUID_FEED_IMPORT_OWNER)
5379653817
&& strcmp (uuid, SETTING_UUID_FEED_IMPORT_ROLES)
53797-
&& strcmp (uuid, SETTING_UUID_SECINFO_SQL_BUFFER_THRESHOLD))
53818+
&& strcmp (uuid, SETTING_UUID_SECINFO_SQL_BUFFER_THRESHOLD)
53819+
&& strcmp (uuid, SETTING_UUID_CVE_CPE_MATCHING_VERSION))
5379853820
{
5379953821
fprintf (stderr, "Error in setting UUID.\n");
5380053822
return 3;
@@ -53822,7 +53844,8 @@ manage_modify_setting (GSList *log_config, const db_conn_info_t *database,
5382253844
if ((strcmp (uuid, SETTING_UUID_DEFAULT_CA_CERT) == 0)
5382353845
|| (strcmp (uuid, SETTING_UUID_FEED_IMPORT_OWNER) == 0)
5382453846
|| (strcmp (uuid, SETTING_UUID_FEED_IMPORT_ROLES) == 0)
53825-
|| (strcmp (uuid, SETTING_UUID_SECINFO_SQL_BUFFER_THRESHOLD) == 0))
53847+
|| (strcmp (uuid, SETTING_UUID_SECINFO_SQL_BUFFER_THRESHOLD) == 0)
53848+
|| (strcmp (uuid, SETTING_UUID_CVE_CPE_MATCHING_VERSION) == 0))
5382653849
{
5382753850
sql_rollback ();
5382853851
fprintf (stderr,

src/manage_sql.h

+5
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@
152152
*/
153153
#define SETTING_UUID_USER_INTERFACE_DATE_FORMAT "d9857b7c-1159-4193-9bc0-18fae5473a69"
154154

155+
/**
156+
* @brief UUID of 'CVE-CPE Matching Version' setting.
157+
*/
158+
#define SETTING_UUID_CVE_CPE_MATCHING_VERSION "2e8a8ccc-219f-4a82-824a-3ad88b6d4029"
159+
155160
/**
156161
* @brief Trust constant for error.
157162
*/

0 commit comments

Comments
 (0)