From ad4950cca173bc8652f302d104d6eca47c004637 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Tue, 12 Mar 2019 14:58:00 +0100 Subject: [PATCH 01/16] Add scanner type "OSP-OpenVAS" This new scanner type uses OpenVAS scan configs and connects to an OSP scanner (ospd-openvas). --- src/gmp.c | 3 +- src/gvmd.c | 4 + src/manage.c | 246 ++++++++++++++++++++++++++++++++++++++++++++++- src/manage.h | 1 + src/manage_sql.c | 9 +- 5 files changed, 257 insertions(+), 6 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index e0f0d808c..51a2f429e 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -17123,7 +17123,8 @@ handle_get_scanners (gmp_parser_t *gmp_parser, GError **error) cleanup_iterator (&tasks); SEND_TO_CLIENT_OR_FAIL (""); } - if (scanner_iterator_type (&scanners) == SCANNER_TYPE_OSP + if ((scanner_iterator_type (&scanners) == SCANNER_TYPE_OSP + || scanner_iterator_type (&scanners) == SCANNER_TYPE_OSP_OPENVAS) && get_scanners_data->get.details) { char *s_name = NULL, *s_ver = NULL; diff --git a/src/gvmd.c b/src/gvmd.c index 7c04b2065..b274ff797 100644 --- a/src/gvmd.c +++ b/src/gvmd.c @@ -2155,6 +2155,8 @@ main (int argc, char** argv) type = SCANNER_TYPE_OPENVAS; else if (!strcasecmp (scanner_type, "OSP")) type = SCANNER_TYPE_OSP; + else if (!strcasecmp (scanner_type, "OSP-OpenVAS")) + type = SCANNER_TYPE_OSP_OPENVAS; else { printf ("Invalid scanner type value.\n"); @@ -2192,6 +2194,8 @@ main (int argc, char** argv) type = SCANNER_TYPE_OPENVAS; else if (strcasecmp (scanner_type, "OSP") == 0) type = SCANNER_TYPE_OSP; + else if (strcasecmp (scanner_type, "OSP-OpenVAS") == 0) + type = SCANNER_TYPE_OSP_OPENVAS; else { g_warning ("Invalid scanner type value"); diff --git a/src/manage.c b/src/manage.c index 8ff460f96..5e2fe8dce 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4203,6 +4203,238 @@ launch_osp_task (task_t task, target_t target, const char *scan_id, return ret; } +/** + * @brief Get the SSH credential of a target as an osp_credential_t + * + * @param[in] target The target to get the credential from. + * + * @return Pointer to a newly allocated osp_credential_t + */ +static osp_credential_t * +target_osp_ssh_credential (target_t target) +{ + credential_t credential; + credential = target_ssh_credential (target); + if (credential) + { + iterator_t iter; + char *ssh_port; + osp_credential_t *osp_credential; + + init_credential_iterator_one (&iter, credential); + if (!next (&iter)) + { + g_warning ("%s: SSH Credential not found.", __FUNCTION__); + cleanup_iterator (&iter); + return NULL; + } + if (strcmp (credential_iterator_type (&iter), "up")) + { + g_warning ("%s: SSH Credential not a user/pass pair.", __FUNCTION__); + cleanup_iterator (&iter); + return NULL; + } + + ssh_port = target_ssh_port (target); + osp_credential + = osp_credential_new ("up", + "ssh", + ssh_port, + credential_iterator_login (&iter), + credential_iterator_password (&iter)); + cleanup_iterator (&iter); + g_free (ssh_port); + return osp_credential; + } + return NULL; +} + +/** + * @brief Get the SMB credential of a target as an osp_credential_t + * + * @param[in] target The target to get the credential from. + * + * @return Pointer to a newly allocated osp_credential_t + */ +static osp_credential_t * +target_osp_smb_credential (target_t target) +{ + credential_t credential; + credential = target_smb_credential (target); + if (credential) + { + iterator_t iter; + osp_credential_t *osp_credential; + + init_credential_iterator_one (&iter, credential); + if (!next (&iter)) + { + g_warning ("%s: SMB Credential not found.", __FUNCTION__); + cleanup_iterator (&iter); + return NULL; + } + if (strcmp (credential_iterator_type (&iter), "up")) + { + g_warning ("%s: SMB Credential not a user/pass pair.", __FUNCTION__); + cleanup_iterator (&iter); + return NULL; + } + + osp_credential + = osp_credential_new ("up", + "smb", + NULL, + credential_iterator_login (&iter), + credential_iterator_password (&iter)); + cleanup_iterator (&iter); + return osp_credential; + } + return NULL; +} + +/** + * @brief Launch an OpenVAS via OSP task. + * + * @param[in] task The task. + * @param[in] target The target. + * @param[out] scan_id The new scan uuid. + * @param[out] error Error return. + * + * @return 0 success, -1 if scanner is down. + */ +static int +launch_osp_openvas_task (task_t task, target_t target, const char *scan_id, + char **error) +{ + osp_connection_t *connection; + char *hosts_str, *ports_str; + osp_target_t *osp_target; + GSList *osp_targets, *vts; + GHashTable *vts_hash_table; + osp_credential_t *ssh_credential, *smb_credential; + GHashTable *scanner_options; + int ret; + config_t config; + iterator_t scanner_prefs_iter, families, prefs; + + config = task_config (task); + + connection = NULL; + + /* Set up target(s) */ + hosts_str = target_hosts (target); + ports_str = target_port_range (target); + + osp_target = osp_target_new (hosts_str, ports_str); + osp_targets = g_slist_append (NULL, osp_target); + + ssh_credential = target_osp_ssh_credential (target); + if (ssh_credential) + osp_target_add_credential (osp_target, ssh_credential); + + smb_credential = target_osp_smb_credential (target); + if (smb_credential) + osp_target_add_credential (osp_target, smb_credential); + + /* Setup general scanner preferences */ + scanner_options + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + init_otp_pref_iterator (&scanner_prefs_iter, config, "SERVER_PREFS"); + while (next (&scanner_prefs_iter)) + { + const char *name, *value; + name = otp_pref_iterator_name (&scanner_prefs_iter); + value = otp_pref_iterator_value (&scanner_prefs_iter); + if (name && value) + g_hash_table_replace (scanner_options, + g_strdup (name), + g_strdup (value)); + } + + /* Setup vulnerability tests (without preferences) */ + vts = NULL; + vts_hash_table + = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + + init_family_iterator (&families, 0, NULL, 1); + while (next (&families)) + { + const char *family = family_iterator_name (&families); + if (family) + { + iterator_t nvts; + init_nvt_iterator (&nvts, 0, config, family, NULL, 1, NULL); + while (next (&nvts)) + { + const char *oid; + osp_vt_single_t *new_vt; + + oid = nvt_iterator_oid (&nvts); + new_vt = osp_vt_single_new (oid); + + vts = g_slist_prepend (vts, new_vt); + g_hash_table_replace (vts_hash_table, g_strdup (oid), new_vt); + } + cleanup_iterator (&nvts); + } + } + cleanup_iterator (&families); + + /* Setup VT preferences */ + init_otp_pref_iterator (&prefs, config, "PLUGINS_PREFS"); + while (next (&prefs)) + { + const char *full_name, *value; + osp_vt_single_t *osp_vt; + gchar **split_name; + + full_name = otp_pref_iterator_name (&prefs); + value = otp_pref_iterator_value (&prefs); + split_name = g_strsplit (full_name, ":", 3); + + osp_vt = NULL; + if (split_name && split_name[0] && split_name[1] && split_name[2]) + { + const char *oid = split_name[0]; + const char *pref_id = split_name[2]; + g_message ("full:\"%s\" - id:\"%s\"", full_name, pref_id); + osp_vt = g_hash_table_lookup (vts_hash_table, oid); + if (osp_vt) + osp_vt_single_add_value (osp_vt, pref_id, value); + } + + g_strfreev (split_name); + } + cleanup_iterator (&prefs); + + /* Start the scan */ + connection = osp_scanner_connect (task_scanner (task)); + if (!connection) + { + if (error) + *error = g_strdup ("Could not connect to Scanner"); + return -1; + } + + ret = osp_start_scan_ext (connection, + osp_targets, + NULL, /* vt_groups */ + vts, + scanner_options, + 1, /* parallel */ + scan_id, + error); + + osp_connection_close (connection); + g_slist_free_full (osp_targets, (GDestroyNotify) osp_target_free); + // Credentials are freed with target + g_slist_free_full (vts, (GDestroyNotify) osp_vt_single_free); + g_hash_table_destroy (scanner_options); + free (hosts_str); + free (ports_str); + return ret; +} + /** * @brief Fork a child to handle an OSP scan's fetching and inserting. * @@ -4256,7 +4488,17 @@ fork_osp_scan_handler (task_t task, target_t target) */ reinit_manage_process (); manage_session_init (current_credentials.uuid); - if (launch_osp_task (task, target, report_id, &error)) + + if (scanner_type (task_scanner (task)) == SCANNER_TYPE_OSP_OPENVAS) + { + rc = launch_osp_openvas_task (task, target, report_id, &error); + } + else + { + rc = launch_osp_task (task, target, report_id, &error); + } + + if (rc) { result_t result; @@ -4301,7 +4543,7 @@ fork_osp_scan_handler (task_t task, target_t target) } /** - * @brief Start a task on an OSP scanner. + * @brief Start a task on an OSP or OpenVAS via OSP scanner. * * @param[in] task The task. * diff --git a/src/manage.h b/src/manage.h index 8c4ddee00..1ae2cfec9 100644 --- a/src/manage.h +++ b/src/manage.h @@ -317,6 +317,7 @@ typedef enum scanner_type SCANNER_TYPE_OPENVAS, SCANNER_TYPE_CVE, SCANNER_TYPE_GMP, + SCANNER_TYPE_OSP_OPENVAS, SCANNER_TYPE_MAX, } scanner_type_t; diff --git a/src/manage_sql.c b/src/manage_sql.c index b38da657f..c53d6b1db 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -36922,7 +36922,8 @@ create_task_check_config_scanner (config_t config, scanner_t scanner) ctype = config_type (config); stype = scanner_type (scanner); - if (ctype == 0 && stype == SCANNER_TYPE_OPENVAS) + if (ctype == 0 + && (stype == SCANNER_TYPE_OPENVAS || stype == SCANNER_TYPE_OSP_OPENVAS)) return 1; if (ctype == 0 && stype == SCANNER_TYPE_GMP) return 1; @@ -36995,7 +36996,8 @@ modify_task_check_config_scanner (task_t task, const char *config_id, return 0; /* OpenVAS Scanner with OpenVAS config. */ - if (stype == SCANNER_TYPE_OPENVAS && ctype == 0) + if ((stype == SCANNER_TYPE_OPENVAS || stype == SCANNER_TYPE_OSP_OPENVAS) + && ctype == 0) return 0; /* GMP Scanner with OpenVAS config. */ @@ -49232,7 +49234,8 @@ verify_scanner (const char *scanner_id, char **version) cleanup_iterator (&scanner); return 0; } - else if (scanner_iterator_type (&scanner) == SCANNER_TYPE_OSP) + else if (scanner_iterator_type (&scanner) == SCANNER_TYPE_OSP + || scanner_iterator_type (&scanner) == SCANNER_TYPE_OSP_OPENVAS) { int ret = osp_get_version_from_iterator (&scanner, NULL, version, NULL, NULL, NULL, NULL); From 1372610d8370acc209b65fba27874e619f29699b Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Tue, 12 Mar 2019 17:31:38 +0100 Subject: [PATCH 02/16] Convert OpenVAS config preferences to OSP OSP expects boolean preferences to be 1 or 0 instead of "yes" or "no" and only the selected value for selection preferences. --- src/manage.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/manage.c b/src/manage.c index 5e2fe8dce..ccddf25fb 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4346,9 +4346,20 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id, name = otp_pref_iterator_name (&scanner_prefs_iter); value = otp_pref_iterator_value (&scanner_prefs_iter); if (name && value) - g_hash_table_replace (scanner_options, - g_strdup (name), - g_strdup (value)); + { + const char *osp_value; + + // Workaround for boolean scanner preferences + if (strcmp (value, "yes") == 0) + osp_value = "1"; + else if (strcmp (value, "no") == 0) + osp_value = "0"; + else + osp_value = value; + g_hash_table_replace (scanner_options, + g_strdup (name), + g_strdup (osp_value)); + } } /* Setup vulnerability tests (without preferences) */ @@ -4396,11 +4407,30 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id, if (split_name && split_name[0] && split_name[1] && split_name[2]) { const char *oid = split_name[0]; + const char *type = split_name[1]; const char *pref_id = split_name[2]; - g_message ("full:\"%s\" - id:\"%s\"", full_name, pref_id); + gchar *osp_value = NULL; + + if (strcmp (type, "checkbox") == 0) + { + if (strcmp (value, "yes") == 0) + osp_value = g_strdup ("1"); + else + osp_value = g_strdup ("0"); + } + else if (strcmp (type, "radio") == 0) + { + gchar** split_value; + split_value = g_strsplit (value, ";", 2); + osp_value = g_strdup (split_value[0]); + g_strfreev (split_value); + } + osp_vt = g_hash_table_lookup (vts_hash_table, oid); if (osp_vt) - osp_vt_single_add_value (osp_vt, pref_id, value); + osp_vt_single_add_value (osp_vt, pref_id, + osp_value ? osp_value : value); + g_free (osp_value); } g_strfreev (split_name); From 17d1f3ca5b3e6784cab57632ac5732002558713b Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 22 May 2019 11:44:55 +0200 Subject: [PATCH 03/16] Fetch OSP results while scan is running Without this OSP tasks had to wait until the end of the scan before fetching any results, which could take a long time for scanners like the OpenVAS one and tasks with many target hosts. --- src/manage.c | 39 ++++++++++++++++++++++----------------- src/manage_sql.c | 17 +++++++---------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/manage.c b/src/manage.c index 4c0e6079f..8d62952b4 100644 --- a/src/manage.c +++ b/src/manage.c @@ -3998,6 +3998,7 @@ delete_osp_scan (const char *report_id, const char *host, int port, * @param[in] key_pub Certificate. * @param[in] key_priv Private key. * @param[in] details 1 for detailed report, 0 otherwise. + * @param[in] pop_results 1 to pop results, 0 to leave results intact. * @param[out] report_xml Scan report. * * @return -1 on error, progress value between 0 and 100 on success. @@ -4005,7 +4006,8 @@ delete_osp_scan (const char *report_id, const char *host, int port, static int get_osp_scan_report (const char *scan_id, const char *host, int port, const char *ca_pub, const char *key_pub, const char - *key_priv, int details, char **report_xml) + *key_priv, int details, int pop_results, + char **report_xml) { osp_connection_t *connection; int progress; @@ -4017,7 +4019,8 @@ get_osp_scan_report (const char *scan_id, const char *host, int port, g_warning ("Couldn't connect to OSP scanner on %s:%d", host, port); return -1; } - progress = osp_get_scan (connection, scan_id, report_xml, details, &error); + progress = osp_get_scan_pop (connection, scan_id, report_xml, details, + pop_results, &error); if (progress > 100 || progress < 0) { g_warning ("OSP get_scan %s: %s", scan_id, error); @@ -4064,8 +4067,8 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id) break; } int progress = get_osp_scan_report (scan_id, host, port, ca_pub, key_pub, - key_priv, 0, NULL); - if (progress == -1) + key_priv, 0, 0, &report_xml); + if (progress < 0 || progress > 100) { result_t result = make_osp_result (task, "", "", threat_message_type ("Error"), @@ -4075,17 +4078,12 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id) rc = -1; break; } - else if (progress < 100) - { - set_report_slave_progress (report, progress); - gvm_sleep (10); - } - else if (progress == 100) + else { /* Get the full OSP report. */ progress = get_osp_scan_report (scan_id, host, port, ca_pub, key_pub, - key_priv, 1, &report_xml); - if (progress != 100) + key_priv, 1, 1, &report_xml); + if (progress < 0 || progress > 100) { result_t result = make_osp_result (task, "", "", threat_message_type ("Error"), @@ -4095,11 +4093,18 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id) rc = -1; break; } - parse_osp_report (task, report, report_xml); - g_free (report_xml); - delete_osp_scan (scan_id, host, port, ca_pub, key_pub, key_priv); - rc = 0; - break; + else + { + set_report_slave_progress (report, progress); + parse_osp_report (task, report, report_xml); + g_free (report_xml); + if (progress == 100) + { + delete_osp_scan (scan_id, host, port, ca_pub, key_pub, + key_priv); + break; + } + } } } diff --git a/src/manage_sql.c b/src/manage_sql.c index 2a480621a..8e6eabc30 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -32514,21 +32514,18 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) sql_begin_immediate (); /* Set the report's start and end times. */ str = entity_attribute (entity, "start_time"); - if (!str) + if (str) { - g_warning ("Missing start_time in OSP report %s", report_xml); - goto end_parse_osp_report; + start_time = atoi (str); + set_scan_start_time_epoch (report, start_time); } - start_time = atoi (str); - set_scan_start_time_epoch (report, start_time); + str = entity_attribute (entity, "end_time"); - if (!str) + if (str) { - g_warning ("Missing end_time in OSP report %s", report_xml); - goto end_parse_osp_report; + end_time = atoi (str); + set_scan_end_time_epoch (report, end_time); } - end_time = atoi (str); - set_scan_end_time_epoch (report, end_time); /* Insert results. */ child = entity_child (entity, "results"); From 6e93b8710d299ec12baab4915afa78adaa21cfdb Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 22 May 2019 17:23:36 +0200 Subject: [PATCH 04/16] Handle OpenVAS scanner host details in OSP This parses results with the "general/Host_Details" port as host details as it is done in OTP. This should eventually be handled by the "Host Detail" result type once there is a well-defined way to handle the source info in OSP. --- src/manage_sql.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index 8e6eabc30..4158e9a7a 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -32598,9 +32598,25 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) qod_int = atoi (qod); if (qod_int <= 0 || qod_int > 100) qod_int = QOD_DEFAULT; - result = make_osp_result (task, host, nvt_id, type, desc, port ?: "", - severity_str ?: severity, qod_int); - report_add_result (report, result); + if (port && strcmp (port, "general/Host_Details") == 0) + { + /* TODO: This should probably be handled by the "Host Detail" + * result type with extra source info in OSP. + */ + if (manage_report_host_detail (global_current_report, + host, + desc)) + g_warning ("%s: Failed to add report detail for host '%s': %s", + __FUNCTION__, + host, + desc); + } + else + { + result = make_osp_result (task, host, nvt_id, type, desc, port ?: "", + severity_str ?: severity, qod_int); + report_add_result (report, result); + } g_free (nvt_id); g_free (desc); g_free (severity_str); From 417211df2650dda97548a2a9cdee6893a5e931db Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 23 May 2019 15:16:42 +0200 Subject: [PATCH 05/16] Adjust OSP credentials auth data The credentials for OSP scans are adjusted for the change in gvm-libs to use the new method of storing the authentication data like username and password. --- src/manage.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/manage.c b/src/manage.c index 8d62952b4..3375b7ac8 100644 --- a/src/manage.c +++ b/src/manage.c @@ -77,6 +77,7 @@ #include #include #include +#include #include #include #include @@ -4220,7 +4221,7 @@ target_osp_ssh_credential (target_t target) if (credential) { iterator_t iter; - char *ssh_port; + const char *type, *ssh_port; osp_credential_t *osp_credential; init_credential_iterator_one (&iter, credential); @@ -4230,22 +4231,23 @@ target_osp_ssh_credential (target_t target) cleanup_iterator (&iter); return NULL; } - if (strcmp (credential_iterator_type (&iter), "up")) + type = credential_iterator_type (&iter); + if (strcmp (type, "up")) { g_warning ("%s: SSH Credential not a user/pass pair.", __FUNCTION__); cleanup_iterator (&iter); return NULL; } - ssh_port = target_ssh_port (target); - osp_credential - = osp_credential_new ("up", - "ssh", - ssh_port, - credential_iterator_login (&iter), - credential_iterator_password (&iter)); + ssh_port = target_iterator_ssh_port (&iter); + osp_credential = osp_credential_new (type, "ssh", ssh_port); + osp_credential_set_auth_data (osp_credential, + "username", + credential_iterator_login (&iter)); + osp_credential_set_auth_data (osp_credential, + "password", + credential_iterator_password (&iter)); cleanup_iterator (&iter); - g_free (ssh_port); return osp_credential; } return NULL; @@ -4282,12 +4284,13 @@ target_osp_smb_credential (target_t target) return NULL; } - osp_credential - = osp_credential_new ("up", - "smb", - NULL, - credential_iterator_login (&iter), - credential_iterator_password (&iter)); + osp_credential = osp_credential_new ("up", "smb", NULL); + osp_credential_set_auth_data (osp_credential, + "username", + credential_iterator_login (&iter)); + osp_credential_set_auth_data (osp_credential, + "password", + credential_iterator_password (&iter)); cleanup_iterator (&iter); return osp_credential; } From a1c241f33b8b55eeece074d07d9e20f37e9d5fbd Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 23 May 2019 15:26:35 +0200 Subject: [PATCH 06/16] Allow usk credentials in target_osp_ssh_credential This allows using SSH private key authentication in OSPd-OpenVAS scans. --- src/manage.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/manage.c b/src/manage.c index 3375b7ac8..cc147bdfd 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4232,9 +4232,10 @@ target_osp_ssh_credential (target_t target) return NULL; } type = credential_iterator_type (&iter); - if (strcmp (type, "up")) + if (strcmp (type, "up") && strcmp (type, "usk")) { - g_warning ("%s: SSH Credential not a user/pass pair.", __FUNCTION__); + g_warning ("%s: SSH Credential not a user/pass pair" + " or user/ssh key.", __FUNCTION__); cleanup_iterator (&iter); return NULL; } @@ -4247,6 +4248,13 @@ target_osp_ssh_credential (target_t target) osp_credential_set_auth_data (osp_credential, "password", credential_iterator_password (&iter)); + if (strcmp (type, "usk") == 0) + { + const char *private_key = credential_iterator_private_key (&iter); + osp_credential_set_auth_data (osp_credential, + "private", + private_key); + } cleanup_iterator (&iter); return osp_credential; } From 441085460b801ec01f6c71eac6efc6ae424e2346 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Thu, 23 May 2019 17:10:42 +0200 Subject: [PATCH 07/16] Add ESXi and SNMP credentials for OSP scans --- src/manage.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) diff --git a/src/manage.c b/src/manage.c index cc147bdfd..1eced5094 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4305,6 +4305,114 @@ target_osp_smb_credential (target_t target) return NULL; } +/** + * @brief Get the SMB credential of a target as an osp_credential_t + * + * @param[in] target The target to get the credential from. + * + * @return Pointer to a newly allocated osp_credential_t + */ +static osp_credential_t * +target_osp_esxi_credential (target_t target) +{ + credential_t credential; + credential = target_esxi_credential (target); + if (credential) + { + iterator_t iter; + osp_credential_t *osp_credential; + + init_credential_iterator_one (&iter, credential); + if (!next (&iter)) + { + g_warning ("%s: ESXi Credential not found.", __FUNCTION__); + cleanup_iterator (&iter); + return NULL; + } + if (strcmp (credential_iterator_type (&iter), "up")) + { + g_warning ("%s: ESXi Credential not a user/pass pair.", + __FUNCTION__); + cleanup_iterator (&iter); + return NULL; + } + + osp_credential = osp_credential_new ("up", "esxi", NULL); + osp_credential_set_auth_data (osp_credential, + "username", + credential_iterator_login (&iter)); + osp_credential_set_auth_data (osp_credential, + "password", + credential_iterator_password (&iter)); + cleanup_iterator (&iter); + return osp_credential; + } + return NULL; +} + +/** + * @brief Get the SMB credential of a target as an osp_credential_t + * + * @param[in] target The target to get the credential from. + * + * @return Pointer to a newly allocated osp_credential_t + */ +static osp_credential_t * +target_osp_snmp_credential (target_t target) +{ + credential_t credential; + credential = target_credential (target, "snmp"); + if (credential) + { + iterator_t iter; + osp_credential_t *osp_credential; + + init_credential_iterator_one (&iter, credential); + if (!next (&iter)) + { + g_warning ("%s: SNMP Credential not found.", __FUNCTION__); + cleanup_iterator (&iter); + return NULL; + } + if (strcmp (credential_iterator_type (&iter), "snmp")) + { + g_warning ("%s: SNMP Credential not of type 'snmp'.", + __FUNCTION__); + cleanup_iterator (&iter); + return NULL; + } + + osp_credential = osp_credential_new ("snmp", "snmp", NULL); + osp_credential_set_auth_data (osp_credential, + "username", + credential_iterator_login (&iter) + ?: ""); + osp_credential_set_auth_data (osp_credential, + "password", + credential_iterator_password (&iter) + ?: ""); + osp_credential_set_auth_data (osp_credential, + "community", + credential_iterator_community (&iter) + ?: ""); + osp_credential_set_auth_data (osp_credential, + "auth_algorithm", + credential_iterator_auth_algorithm (&iter) + ?: ""); + osp_credential_set_auth_data (osp_credential, + "privacy_algorithm", + credential_iterator_privacy_algorithm + (&iter) ?: ""); + osp_credential_set_auth_data (osp_credential, + "privacy_password", + credential_iterator_privacy_password + (&iter) ?: ""); + cleanup_iterator (&iter); + return osp_credential; + } + return NULL; +} + /** * @brief Launch an OpenVAS via OSP task. * @@ -4324,7 +4432,8 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id, osp_target_t *osp_target; GSList *osp_targets, *vts; GHashTable *vts_hash_table; - osp_credential_t *ssh_credential, *smb_credential; + osp_credential_t *ssh_credential, *smb_credential, *esxi_credential; + osp_credential_t *snmp_credential; GHashTable *scanner_options; int ret; config_t config; @@ -4349,6 +4458,14 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id, if (smb_credential) osp_target_add_credential (osp_target, smb_credential); + esxi_credential = target_osp_esxi_credential (target); + if (esxi_credential) + osp_target_add_credential (osp_target, esxi_credential); + + snmp_credential = target_osp_snmp_credential (target); + if (snmp_credential) + osp_target_add_credential (osp_target, snmp_credential); + /* Setup general scanner preferences */ scanner_options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); From b19e24804c99e1216d93d4a292cedcaee856638b Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Fri, 24 May 2019 15:51:13 +0200 Subject: [PATCH 08/16] Don't get unused connecting to OSP file socket The osp_scanner_connect function will no longer try to get the port, ca_pub, key_pub and key_priv from the scanner as they are not needed and getting the private key could fail if the scanner has no credential. --- src/manage_sql.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index 4158e9a7a..2bc3fde4c 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -49143,10 +49143,20 @@ osp_scanner_connect (scanner_t scanner) assert (scanner); host = scanner_host (scanner); - port = scanner_port (scanner); - ca_pub = scanner_ca_pub (scanner); - key_pub = scanner_key_pub (scanner); - key_priv = scanner_key_priv (scanner); + if (host && *host == '/') + { + port = 0; + ca_pub = NULL; + key_pub = NULL; + key_priv = NULL; + } + else + { + port = scanner_port (scanner); + ca_pub = scanner_ca_pub (scanner); + key_pub = scanner_key_pub (scanner); + key_priv = scanner_key_priv (scanner); + } connection = osp_connection_new (host, port, ca_pub, key_pub, key_priv); g_free (host); From 2adcf6473ab61951611f89398596ccf34694b657 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Fri, 24 May 2019 17:51:47 +0200 Subject: [PATCH 09/16] Handle HOST_START and HOST_END in OSP scans OSP results with "HOST_START" and "HOST_END" as NVT id will be used to set the start and end time of a host. --- src/manage_sql.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index 2bc3fde4c..e78700023 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -32603,14 +32603,20 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) /* TODO: This should probably be handled by the "Host Detail" * result type with extra source info in OSP. */ - if (manage_report_host_detail (global_current_report, - host, - desc)) + if (manage_report_host_detail (report, host, desc)) g_warning ("%s: Failed to add report detail for host '%s': %s", __FUNCTION__, host, desc); } + else if (host && nvt_id && desc && (strcmp (nvt_id, "HOST_START") == 0)) + { + set_scan_host_start_time_otp (report, host, desc); + } + else if (host && nvt_id && desc && (strcmp (nvt_id, "HOST_END") == 0)) + { + set_scan_host_end_time_otp (report, host, desc); + } else { result = make_osp_result (task, host, nvt_id, type, desc, port ?: "", From e29df9e3adaa76fc9e8f908e7cd5a61f13730366 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Tue, 28 May 2019 17:10:03 +0200 Subject: [PATCH 10/16] Add exclude_hosts parameter for osp_target_new() --- src/manage.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/manage.c b/src/manage.c index e61362a26..bdb256008 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4428,7 +4428,7 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id, char **error) { osp_connection_t *connection; - char *hosts_str, *ports_str; + char *hosts_str, *ports_str, *exclude_hosts_str; osp_target_t *osp_target; GSList *osp_targets, *vts; GHashTable *vts_hash_table; @@ -4446,8 +4446,9 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id, /* Set up target(s) */ hosts_str = target_hosts (target); ports_str = target_port_range (target); + exclude_hosts_str = target_exclude_hosts (target); - osp_target = osp_target_new (hosts_str, ports_str); + osp_target = osp_target_new (hosts_str, ports_str, exclude_hosts_str); osp_targets = g_slist_append (NULL, osp_target); ssh_credential = target_osp_ssh_credential (target); @@ -4592,6 +4593,7 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id, g_hash_table_destroy (scanner_options); free (hosts_str); free (ports_str); + free (exclude_hosts_str); return ret; } From 6117fb6b724bd3484815dc7d088ccc9ccb226c32 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Tue, 28 May 2019 18:03:14 +0200 Subject: [PATCH 11/16] Get hostname for OSP scan results The parse_osp_report() function will now get the hostname attribute from OSP results and make_osp_result() will store it in the results table. --- src/manage.c | 9 ++++++--- src/manage.h | 2 +- src/manage_sql.c | 36 ++++++++++++++++++++++++------------ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/manage.c b/src/manage.c index bdb256008..64f05d872 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4072,7 +4072,8 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id) if (progress < 0 || progress > 100) { result_t result = make_osp_result - (task, "", "", threat_message_type ("Error"), + (task, "", "", "", + threat_message_type ("Error"), "Erroneous scan progress value", "", "", QOD_DEFAULT); report_add_result (report, result); @@ -4087,7 +4088,8 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id) if (progress < 0 || progress > 100) { result_t result = make_osp_result - (task, "", "", threat_message_type ("Error"), + (task, "", "", "", + threat_message_type ("Error"), "Erroneous scan progress value", "", "", QOD_DEFAULT); report_add_result (report, result); @@ -4665,7 +4667,8 @@ fork_osp_scan_handler (task_t task, target_t target) result_t result; g_warning ("OSP start_scan %s: %s", report_id, error); - result = make_osp_result (task, "", "", threat_message_type ("Error"), + result = make_osp_result (task, "", "", "", + threat_message_type ("Error"), error, "", "", QOD_DEFAULT); report_add_result (global_current_report, result); set_task_run_status (task, TASK_STATUS_DONE); diff --git a/src/manage.h b/src/manage.h index 95a0e3d65..11852c61d 100644 --- a/src/manage.h +++ b/src/manage.h @@ -1215,7 +1215,7 @@ 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 *, int); + const char *, const char *, const char *, int); result_t make_cve_result (task_t, const char*, const char*, double, const char*); diff --git a/src/manage_sql.c b/src/manage_sql.c index 4aefd6338..33772b923 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -20741,6 +20741,7 @@ result_nvt_notice (const gchar *nvt) * * @param[in] task The task associated with the result. * @param[in] host Target host of result. + * @param[in] hostname Hostname of the result. * @param[in] nvt The uuid of oval definition that produced the * result, a title for the result otherwise. * @param[in] type Type of result. "Alarm", etc. @@ -20752,12 +20753,12 @@ result_nvt_notice (const gchar *nvt) * @return A result descriptor for the new result, 0 if error. */ result_t -make_osp_result (task_t task, const char *host, const char *nvt, - const char *type, const char *description, +make_osp_result (task_t task, const char *host, const char *hostname, + const char *nvt, const char *type, const char *description, const char *port, const char *severity, int qod) { char *nvt_revision = NULL, *quoted_desc, *quoted_nvt, *result_severity; - char *quoted_port; + char *quoted_port, *quoted_hostname; assert (task); assert (type); @@ -20767,6 +20768,7 @@ make_osp_result (task_t task, const char *host, const char *nvt, quoted_desc = sql_quote (description ?: ""); quoted_nvt = sql_quote (nvt ?: ""); quoted_port = sql_quote (port ?: ""); + quoted_hostname = sql_quote (hostname ? hostname : ""); if (!severity || !strcmp (severity, "")) { if (!strcmp (type, severity_to_type (SEVERITY_ERROR))) @@ -20803,17 +20805,18 @@ make_osp_result (task_t task, const char *host, const char *nvt, result_severity = sql_quote (severity); result_nvt_notice (quoted_nvt); sql ("INSERT into results" - " (owner, date, task, host, port, nvt, nvt_version, severity, type," - " qod, qod_type, description, uuid)" - " VALUES (NULL, m_now(), %llu, '%s', '%s', '%s', '%s', '%s', '%s'," - " %d, '', '%s', make_uuid ());", - task, host ?: "", quoted_port, quoted_nvt, nvt_revision ?: "", - result_severity ?: "0", type, qod, quoted_desc); + " (owner, date, task, host, hostname, port, nvt," + " nvt_version, severity, type, qod, qod_type, description, uuid)" + " VALUES (NULL, m_now(), %llu, '%s', '%s', '%s', '%s'," + " '%s', '%s', '%s', %d, '', '%s', make_uuid ());", + task, host ?: "", quoted_hostname, quoted_port, quoted_nvt, + nvt_revision ?: "", result_severity ?: "0", type, qod, quoted_desc); g_free (result_severity); g_free (nvt_revision); g_free (quoted_desc); g_free (quoted_nvt); g_free (quoted_port); + g_free (quoted_hostname); return sql_last_insert_id (); } @@ -32544,7 +32547,8 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) while (results) { result_t result; - const char *type, *name, *severity, *host, *test_id, *port, *qod; + const char *type, *name, *severity, *host, *hostname, *test_id, *port; + const char *qod; char *desc = NULL, *nvt_id = NULL, *severity_str = NULL; entity_t r_entity = results->data; int qod_int; @@ -32561,6 +32565,7 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) severity = entity_attribute (r_entity, "severity"); test_id = entity_attribute (r_entity, "test_id"); host = entity_attribute (r_entity, "host"); + hostname = entity_attribute (r_entity, "hostname"); port = entity_attribute (r_entity, "port") ?: ""; qod = entity_attribute (r_entity, "qod") ?: ""; if (!name || !type || !severity || !test_id || !host) @@ -32624,8 +32629,15 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) } else { - result = make_osp_result (task, host, nvt_id, type, desc, port ?: "", - severity_str ?: severity, qod_int); + result = make_osp_result (task, + host, + hostname, + nvt_id, + type, + desc, + port ?: "", + severity_str ?: severity, + qod_int); report_add_result (report, result); } g_free (nvt_id); From 1294b42059100ef855c9058654d4ab6a56e7fbac Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 5 Jun 2019 08:59:11 +0200 Subject: [PATCH 12/16] Use OSP for all OpenVAS scans The OSP-OpenVAS scanner type is removed again in favor of running all OpenVAS scans via OSP instead of OTP. --- src/gmp.c | 2 +- src/gvmd.c | 4 ---- src/manage.c | 9 ++++++--- src/manage.h | 1 - src/manage_sql.c | 43 ++++--------------------------------------- 5 files changed, 11 insertions(+), 48 deletions(-) diff --git a/src/gmp.c b/src/gmp.c index a31e5d67a..b3846f81c 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -17178,7 +17178,7 @@ handle_get_scanners (gmp_parser_t *gmp_parser, GError **error) SEND_TO_CLIENT_OR_FAIL (""); } if ((scanner_iterator_type (&scanners) == SCANNER_TYPE_OSP - || scanner_iterator_type (&scanners) == SCANNER_TYPE_OSP_OPENVAS) + || scanner_iterator_type (&scanners) == SCANNER_TYPE_OPENVAS) && get_scanners_data->get.details) { char *s_name = NULL, *s_ver = NULL; diff --git a/src/gvmd.c b/src/gvmd.c index 4ea914a38..a6c74ab4d 100644 --- a/src/gvmd.c +++ b/src/gvmd.c @@ -2344,8 +2344,6 @@ main (int argc, char** argv) type = SCANNER_TYPE_OPENVAS; else if (!strcasecmp (scanner_type, "OSP")) type = SCANNER_TYPE_OSP; - else if (!strcasecmp (scanner_type, "OSP-OpenVAS")) - type = SCANNER_TYPE_OSP_OPENVAS; else { printf ("Invalid scanner type value.\n"); @@ -2383,8 +2381,6 @@ main (int argc, char** argv) type = SCANNER_TYPE_OPENVAS; else if (strcasecmp (scanner_type, "OSP") == 0) type = SCANNER_TYPE_OSP; - else if (strcasecmp (scanner_type, "OSP-OpenVAS") == 0) - type = SCANNER_TYPE_OSP_OPENVAS; else { g_warning ("Invalid scanner type value"); diff --git a/src/manage.c b/src/manage.c index 64f05d872..50079c1d6 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4653,7 +4653,7 @@ fork_osp_scan_handler (task_t task, target_t target) reinit_manage_process (); manage_session_init (current_credentials.uuid); - if (scanner_type (task_scanner (task)) == SCANNER_TYPE_OSP_OPENVAS) + if (scanner_type (task_scanner (task)) == SCANNER_TYPE_OPENVAS) { rc = launch_osp_openvas_task (task, target, report_id, &error); } @@ -6127,9 +6127,11 @@ run_task (const char *task_id, char **report_id, int from) if (scanner_type (scanner) == SCANNER_TYPE_GMP) return run_gmp_task (task, scanner, from, report_id); - if (scanner_type (scanner) != SCANNER_TYPE_OPENVAS) + if (scanner_type (scanner) == SCANNER_TYPE_OPENVAS + || scanner_type (scanner) == SCANNER_TYPE_OSP) return run_osp_task (task); + // TODO: Remove OTP task handling return run_otp_task (task, scanner, from, report_id); } @@ -6288,7 +6290,8 @@ stop_task (const char *task_id) if (task == 0) return 3; - if (config_type (task_config (task)) != 0) + if (scanner_type (task_scanner (task)) == SCANNER_TYPE_OPENVAS + || scanner_type (task_scanner (task)) == SCANNER_TYPE_OSP) return stop_osp_task (task); return stop_task_internal (task); diff --git a/src/manage.h b/src/manage.h index 11852c61d..5c1935203 100644 --- a/src/manage.h +++ b/src/manage.h @@ -317,7 +317,6 @@ typedef enum scanner_type SCANNER_TYPE_OPENVAS, SCANNER_TYPE_CVE, SCANNER_TYPE_GMP, - SCANNER_TYPE_OSP_OPENVAS, SCANNER_TYPE_MAX, } scanner_type_t; diff --git a/src/manage_sql.c b/src/manage_sql.c index b1998fa28..9b3484a57 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -37053,8 +37053,7 @@ create_task_check_config_scanner (config_t config, scanner_t scanner) ctype = config_type (config); stype = scanner_type (scanner); - if (ctype == 0 - && (stype == SCANNER_TYPE_OPENVAS || stype == SCANNER_TYPE_OSP_OPENVAS)) + if (ctype == 0 && stype == SCANNER_TYPE_OPENVAS) return 1; if (ctype == 0 && stype == SCANNER_TYPE_GMP) return 1; @@ -37127,7 +37126,7 @@ modify_task_check_config_scanner (task_t task, const char *config_id, return 0; /* OpenVAS Scanner with OpenVAS config. */ - if ((stype == SCANNER_TYPE_OPENVAS || stype == SCANNER_TYPE_OSP_OPENVAS) + if ((stype == SCANNER_TYPE_OPENVAS) && ctype == 0) return 0; @@ -49473,7 +49472,7 @@ verify_scanner (const char *scanner_id, char **version) return 0; } else if (scanner_iterator_type (&scanner) == SCANNER_TYPE_OSP - || scanner_iterator_type (&scanner) == SCANNER_TYPE_OSP_OPENVAS) + || scanner_iterator_type (&scanner) == SCANNER_TYPE_OPENVAS) { int ret = osp_get_version_from_iterator (&scanner, NULL, version, NULL, NULL, NULL, NULL); @@ -49482,44 +49481,10 @@ verify_scanner (const char *scanner_id, char **version) return 2; return 0; } - else if (scanner_iterator_type (&scanner) == SCANNER_TYPE_OPENVAS) - { - const char *host = scanner_iterator_host (&scanner); - - if (host && *host == '/') - openvas_scanner_set_unix (host); - else - { - if (openvas_scanner_set_address (scanner_iterator_host (&scanner), - scanner_iterator_port (&scanner)) - == -1) - { - cleanup_iterator (&scanner); - return 2; - } - - if (set_certs (scanner_iterator_ca_pub (&scanner), - scanner_iterator_key_pub (&scanner), - scanner_iterator_key_priv (&scanner))) - { - cleanup_iterator (&scanner); - return 3; - } - } - cleanup_iterator (&scanner); - if (openvas_scanner_connected ()) - openvas_scanner_close (); - if (openvas_scanner_connect () || openvas_scanner_init (0) - || openvas_scanner_close ()) - return 2; - if (version) - *version = g_strdup ("OTP/2.0"); - return 0; - } else if (scanner_iterator_type (&scanner) == SCANNER_TYPE_CVE) { if (version) - *version = g_strdup ("OTP/2.0"); + *version = g_strdup ("GVM/" GVMD_VERSION); cleanup_iterator (&scanner); return 0; } From cdda304705b5f1df8e107c42ecf1eb4feb3bb50d Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 5 Jun 2019 09:29:59 +0200 Subject: [PATCH 13/16] Get report from task in stop_osp_task The process running the function may not have global_current_report set, so the current report has to be fetched from the task. --- src/manage.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/manage.c b/src/manage.c index 50079c1d6..54e009b7b 100644 --- a/src/manage.c +++ b/src/manage.c @@ -6175,14 +6175,16 @@ stop_osp_task (task_t task) { osp_connection_t *connection; int ret = -1; + report_t scan_report; char *scan_id; + scan_report = task_running_report (task); + scan_id = report_uuid (scan_report); + if (!scan_id) + goto end_stop_osp; connection = osp_scanner_connect (task_scanner (task)); if (!connection) goto end_stop_osp; - scan_id = report_uuid (task_running_report (task)); - if (!scan_id) - goto end_stop_osp; set_task_run_status (task, TASK_STATUS_STOP_REQUESTED); ret = osp_stop_scan (connection, scan_id, NULL); osp_connection_close (connection); @@ -6190,9 +6192,12 @@ stop_osp_task (task_t task) end_stop_osp: set_task_end_time_epoch (task, time (NULL)); - set_scan_end_time_epoch (global_current_report, time (NULL)); set_task_run_status (task, TASK_STATUS_STOPPED); - set_report_scan_run_status (global_current_report, TASK_STATUS_STOPPED); + if (scan_report) + { + set_scan_end_time_epoch (scan_report, time (NULL)); + set_report_scan_run_status (scan_report, TASK_STATUS_STOPPED); + } if (ret) return -1; return 0; From 3559900246d9232d92e27b79233e17581aebbe43 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 5 Jun 2019 12:46:48 +0200 Subject: [PATCH 14/16] Use new struct-based osp_start_scan_ext The osp_start_scan_ext function has been changed to have most options passed in as a new struct type (osp_start_scan_opts_t). --- src/manage.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/manage.c b/src/manage.c index 0a4d49fb7..f05f8bf1c 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4440,6 +4440,7 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id, int ret; config_t config; iterator_t scanner_prefs_iter, families, prefs; + osp_start_scan_opts_t start_scan_opts; config = task_config (task); @@ -4579,13 +4580,15 @@ launch_osp_openvas_task (task_t task, target_t target, const char *scan_id, return -1; } + start_scan_opts.targets = osp_targets; + start_scan_opts.vt_groups = NULL; + start_scan_opts.vts = vts; + start_scan_opts.scanner_params = scanner_options; + start_scan_opts.parallel = 1; + start_scan_opts.scan_id = scan_id; + ret = osp_start_scan_ext (connection, - osp_targets, - NULL, /* vt_groups */ - vts, - scanner_options, - 1, /* parallel */ - scan_id, + start_scan_opts, error); osp_connection_close (connection); From 70de168e6c8dfb7adcbacadd42b669090f2f4d94 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Fri, 7 Jun 2019 12:23:19 +0200 Subject: [PATCH 15/16] Add warning if OSP connection fails The osp_scanner_connect function will now log a warning message containing the hostname or socket path. --- src/manage_sql.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/manage_sql.c b/src/manage_sql.c index d74fa5777..41300bd26 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -49251,6 +49251,14 @@ osp_scanner_connect (scanner_t scanner) } connection = osp_connection_new (host, port, ca_pub, key_pub, key_priv); + if (connection == NULL) + { + if (port) + g_warning ("Could not connect to Scanner at %s:%d", host, port); + else + g_warning ("Could not connect to Scanner at %s", host); + } + g_free (host); g_free (ca_pub); g_free (key_pub); From 53836d1d8406a1dc4aafaecb9c023e57a5e2395d Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Fri, 7 Jun 2019 12:56:01 +0200 Subject: [PATCH 16/16] Fix uninitialized variables The variables start_time and end_time in the parse_osp_report function and rc in the handle_osp_scan function were not initialized. --- src/manage.c | 3 +++ src/manage_sql.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/manage.c b/src/manage.c index f05f8bf1c..b26d911bc 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4055,6 +4055,8 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id) ca_pub = scanner_ca_pub (scanner); key_pub = scanner_key_pub (scanner); key_priv = scanner_key_priv (scanner); + rc = -1; + while (1) { char *report_xml = NULL; @@ -4107,6 +4109,7 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id) key_priv); break; } + rc = 0; } } } diff --git a/src/manage_sql.c b/src/manage_sql.c index 41300bd26..44aa5799f 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -32591,6 +32591,7 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) sql_begin_immediate (); /* Set the report's start and end times. */ + start_time = 0; str = entity_attribute (entity, "start_time"); if (str) { @@ -32598,6 +32599,7 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) set_scan_start_time_epoch (report, start_time); } + end_time = 0; str = entity_attribute (entity, "end_time"); if (str) {