Skip to content

Commit

Permalink
Change: Filter duplicate results from the scanner during report gener…
Browse files Browse the repository at this point in the history
…ation.

(backport #1938)
  • Loading branch information
timopollmeier authored Apr 26, 2023
2 parents 46470c0 + 93e44c8 commit 60ac3a7
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 44 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ include (CPack)

## Variables

set (GVMD_DATABASE_VERSION 251)
set (GVMD_DATABASE_VERSION 253)

set (GVMD_SCAP_DATABASE_VERSION 20)

Expand Down
29 changes: 16 additions & 13 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
(task, "", "", "",
threat_message_type ("Error"),
"Erroneous scan progress value", "", "",
QOD_DEFAULT, NULL);
QOD_DEFAULT, NULL, NULL);
report_add_result (report, result);
delete_osp_scan (scan_id, host, port, ca_pub, key_pub,
key_priv);
Expand Down Expand Up @@ -1824,7 +1824,7 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
(task, "", "", "",
threat_message_type ("Error"),
"Erroneous scan progress value", "", "",
QOD_DEFAULT, NULL);
QOD_DEFAULT, NULL, NULL);
report_add_result (report, result);
rc = -1;
break;
Expand Down Expand Up @@ -1854,7 +1854,7 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
(task, "", "", "",
threat_message_type ("Error"),
"Task interrupted unexpectedly", "", "",
QOD_DEFAULT, NULL);
QOD_DEFAULT, NULL, NULL);
report_add_result (report, result);
delete_osp_scan (scan_id, host, port, ca_pub, key_pub,
key_priv);
Expand All @@ -1877,7 +1877,7 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
(task, "", "", "",
threat_message_type ("Error"),
"Scan stopped unexpectedly by the server", "", "",
QOD_DEFAULT, NULL);
QOD_DEFAULT, NULL, NULL);
report_add_result (report, result);
delete_osp_scan (scan_id, host, port, ca_pub, key_pub,
key_priv);
Expand Down Expand Up @@ -2748,7 +2748,7 @@ fork_osp_scan_handler (task_t task, target_t target, int from,
g_warning ("OSP start_scan %s: %s", report_id, error);
result = make_osp_result (task, "", "", "",
threat_message_type ("Error"),
error, "", "", QOD_DEFAULT, NULL);
error, "", "", QOD_DEFAULT, NULL, NULL);
report_add_result (global_current_report, result);
set_task_run_status (task, TASK_STATUS_DONE);
set_report_scan_run_status (global_current_report, TASK_STATUS_DONE);
Expand Down Expand Up @@ -2936,7 +2936,7 @@ cve_scan_host (task_t task, report_t report, gvm_host_t *gvm_host)
locations = g_string_new("");

insert_report_host_detail (global_current_report, ip, "cve", cve,
"CVE Scanner", "App", app);
"CVE Scanner", "App", app, NULL);

init_app_locations_iterator (&locations_iter, report_host, app);

Expand All @@ -2957,16 +2957,16 @@ cve_scan_host (task_t task, report_t report, gvm_host_t *gvm_host)
g_string_append (locations, location);

insert_report_host_detail (report, ip, "cve", cve,
"CVE Scanner", app, location);
"CVE Scanner", app, location, NULL);

insert_report_host_detail (report, ip, "cve", cve,
"CVE Scanner", "detected_at",
location);
location, NULL);

insert_report_host_detail (report, ip, "cve", cve,
"CVE Scanner", "detected_by",
/* Detected by itself. */
cve);
cve, NULL);
}

desc = g_strdup_printf ("The host carries the product: %s\n"
Expand Down Expand Up @@ -3010,26 +3010,29 @@ cve_scan_host (task_t task, report_t report, gvm_host_t *gvm_host)
hostname = report_host_hostname (report_host);
if (hostname) {
insert_report_host_detail (report, ip, "cve", "",
"CVE Scanner", "hostname", hostname);
"CVE Scanner", "hostname", hostname,
NULL);
g_free(hostname);
}

best = report_host_best_os_cpe (report_host);
if (best) {
insert_report_host_detail (report, ip, "cve", "",
"CVE Scanner", "best_os_cpe", best);
"CVE Scanner", "best_os_cpe", best,
NULL);
g_free(best);
}

best = report_host_best_os_txt (report_host);
if (best) {
insert_report_host_detail (report, ip, "cve", "",
"CVE Scanner", "best_os_txt", best);
"CVE Scanner", "best_os_txt", best,
NULL);
g_free(best);
}

insert_report_host_detail (report, ip, "cve", "",
"CVE Scanner", "CVE Scan", "1");
"CVE Scanner", "CVE Scan", "1", NULL);
update_report_modification_time (report);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,8 @@ make_result (task_t, const char*, const char*, const char*, const char*,

result_t
make_osp_result (task_t, const char*, const char*, const char*, const char*,
const char *, const char *, const char *, int, const char*);
const char *, const char *, const char *, int, const char*,
const char *);

result_t
make_cve_result (task_t, const char*, const char*, double, const char*);
Expand Down Expand Up @@ -1237,7 +1238,8 @@ host_detail_free (host_detail_t *);

void
insert_report_host_detail (report_t, const char *, const char *, const char *,
const char *, const char *, const char *);
const char *, const char *, const char *,
const char *);

int
manage_report_host_detail (report_t, const char *, const char *);
Expand Down
65 changes: 65 additions & 0 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -2996,6 +2996,69 @@ migrate_250_to_251 ()
return 0;
}

/**
* @brief Migrate the database from version 251 to version 252.
*
* @return 0 success, -1 error.
*/
int
migrate_251_to_252 ()
{
sql_begin_immediate ();

/* Ensure that the database is currently version 251. */

if (manage_db_version () != 251)
{
sql_rollback ();
return -1;
}

/* Update the database. */

sql ("ALTER TABLE IF EXISTS results ADD COLUMN hash_value text;");

/* Set the database version to 252. */

set_db_version (252);

sql_commit ();

return 0;
}

/**
* @brief Migrate the database from version 252 to version 253.
*
* @return 0 success, -1 error.
*/
int
migrate_252_to_253 ()
{
sql_begin_immediate ();

/* Ensure that the database is currently version 252. */

if (manage_db_version () != 252)
{
sql_rollback ();
return -1;
}

/* Update the database. */

sql ("ALTER TABLE IF EXISTS report_host_details ADD COLUMN hash_value text;");

/* Set the database version to 253. */

set_db_version (253);

sql_commit ();

return 0;
}


#undef UPDATE_DASHBOARD_SETTINGS

/**
Expand Down Expand Up @@ -3053,6 +3116,8 @@ static migrator_t database_migrators[] = {
{249, migrate_248_to_249},
{250, migrate_249_to_250},
{251, migrate_250_to_251},
{252, migrate_251_to_252},
{253, migrate_252_to_253},
/* End marker. */
{-1, NULL}};

Expand Down
Loading

0 comments on commit 60ac3a7

Please sign in to comment.