Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter duplicate results from the scanner during report generation. #1938

Merged
merged 3 commits into from Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -96,7 +96,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
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
Expand Up @@ -1182,7 +1182,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 @@ -1234,7 +1235,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
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