Skip to content

Commit

Permalink
Send the correct num of dead hosts to ospd-openvas
Browse files Browse the repository at this point in the history
When we reach the max_scan_hosts limit we do not
send the true number of dead hosts.
The number needed by ospd-opevas for calculating
the correct progress bar and not ending a scan in
the interrupted state is calculated by subtracting
from the number of hosts to test the number of
max_scan_hosts and alive hosts.
  • Loading branch information
ArnoStiefvater committed Jul 2, 2020
1 parent 5e57856 commit c77e637
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
20 changes: 17 additions & 3 deletions boreas/alivedetection.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ scan (alive_test_t alive_test)
{
int number_of_targets;
int number_of_dead_hosts;
int number_of_alive_hosts;
pthread_t sniffer_thread_id;
GHashTableIter target_hosts_iter;
gpointer key, value;
Expand Down Expand Up @@ -186,9 +187,22 @@ scan (alive_test_t alive_test)

stop_sniffer_thread (&scanner, sniffer_thread_id);

/* Send info about dead hosts to ospd-openvas. This is needed for the
* calculation of the progress bar for gsa. */
number_of_dead_hosts = send_dead_hosts_to_ospd_openvas (scanner.hosts_data);
number_of_dead_hosts = count_difference (scanner.hosts_data->targethosts,
scanner.hosts_data->alivehosts);
number_of_alive_hosts = g_hash_table_size (scanner.hosts_data->alivehosts);

/* Send number of dead hosts to ospd-openvas. We need to consider the scan
* restrictions.*/
if (scanner.scan_restrictions->max_scan_hosts_reached)
{
send_dead_hosts_to_ospd_openvas (
number_of_targets
- (number_of_alive_hosts - scanner.scan_restrictions->max_scan_hosts));
}
else
{
send_dead_hosts_to_ospd_openvas (number_of_dead_hosts);
}

gettimeofday (&end_time, NULL);

Expand Down
15 changes: 4 additions & 11 deletions boreas/boreas_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,19 +327,19 @@ handle_scan_restrictions (struct scanner *scanner, gchar *addr_str)
* @brief Send the number of dead hosts to ospd-openvas.
*
* This information is needed for the calculation of the progress bar for gsa in
* ospd-openvas.
* ospd-openvas. The number of dead hosts sent to ospd-openvas may not
* necessarily reflect the acutal number of dead hosts in the target list.
*
* @param hosts_data Includes all data which is needed for calculating the
* number of dead hosts.
*
* @return number of dead hosts, or -1 in case of an error.
*/
int
send_dead_hosts_to_ospd_openvas (struct hosts_data *hosts_data)
void
send_dead_hosts_to_ospd_openvas (int count_dead_hosts)
{
kb_t main_kb;
int maindbid;
int count_dead_hosts;
char dead_host_msg_to_ospd_openvas[2048];

maindbid = atoi (prefs_get ("ov_maindbid"));
Expand All @@ -350,21 +350,14 @@ send_dead_hosts_to_ospd_openvas (struct hosts_data *hosts_data)
g_debug ("%s: Could not connect to main_kb for sending dead hosts to "
"ospd-openvas.",
__func__);
return -1;
}

/* Number of targethosts - alivehosts. */
count_dead_hosts =
count_difference (hosts_data->targethosts, hosts_data->alivehosts);

snprintf (dead_host_msg_to_ospd_openvas,
sizeof (dead_host_msg_to_ospd_openvas), "DEADHOST||| ||| ||| |||%d",
count_dead_hosts);
kb_item_push_str (main_kb, "internal/results", dead_host_msg_to_ospd_openvas);

kb_lnk_reset (main_kb);

return count_dead_hosts;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions boreas/boreas_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ get_host_from_queue (kb_t, gboolean *);
void
put_finish_signal_on_queue (void *);

int
send_dead_hosts_to_ospd_openvas (struct hosts_data *);
void
send_dead_hosts_to_ospd_openvas (int);

void
init_scan_restrictions (struct scanner *, int);
Expand Down

0 comments on commit c77e637

Please sign in to comment.