Skip to content

Commit

Permalink
Merge pull request #606 from jjnicola/total-hosts
Browse files Browse the repository at this point in the history
Send message to client with the amount of host to be scanned.
  • Loading branch information
jjnicola authored Oct 13, 2020
2 parents 85215b2 + 3047fcb commit 6359774
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add support for TLSv1.3. [#588](https://github.com/greenbone/openvas/pull/588)[#598](https://github.com/greenbone/openvas/pull/598)
- Add alternative for supporting snmp during scans. [#594](https://github.com/greenbone/openvas/pull/594)
- Add resolve_hostname_to_multiple_ips() NASL function. [#596](https://github.com/greenbone/openvas/pull/596)
- Send message to the client with hosts count. [#606](https://github.com/greenbone/openvas/pull/606)

### Changed
- Downgrade wmi queries log level for common errors. [#602](https://github.com/greenbone/openvas/pull/602)
Expand Down
43 changes: 19 additions & 24 deletions src/attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ comm_send_status (kb_t kb, char *hostname, int curr, int max)
}

static void
error_message_to_client2 (kb_t kb, const char *msg, const char *ip_str,
const char *port)
message_to_client (kb_t kb, const char *msg, const char *ip_str,
const char *port, const char *type)
{
char buf[2048];

sprintf (buf, "ERRMSG|||%s|||%s||| |||%s", ip_str ?: "", port ?: " ",
sprintf (buf, "%s|||%s|||%s||| |||%s", type, ip_str ?: "", port ?: " ",
msg ?: "No error.");
kb_item_push_str (kb, "internal/results", buf);
}
Expand Down Expand Up @@ -676,10 +676,10 @@ attack_start (struct attack_start_args *args)
if (ret_host_auth < 0)
{
if (ret_host_auth == -1)
error_message_to_client2 (kb, "Host access denied.", ip_str, NULL);
message_to_client (kb, "Host access denied.", ip_str, NULL, "ERRMSG");
else
error_message_to_client2 (
kb, "Host access denied (system-wide restriction.)", ip_str, NULL);
message_to_client (kb, "Host access denied (system-wide restriction.)",
ip_str, NULL, "ERRMSG");

kb_item_set_str (kb, "internal/host_deny", "True", 0);
g_warning ("Host %s access denied.", ip_str);
Expand Down Expand Up @@ -1009,9 +1009,9 @@ attack_network (struct scan_globals *globals)
struct timeval then, now;
gvm_hosts_t *hosts;
const gchar *port_range;
kb_t host_kb;
kb_t host_kb, main_kb;
GSList *unresolved;
int duplicated_hosts;
char buf[96];

gboolean test_alive_hosts_only = prefs_get_bool ("test_alive_hosts_only");
gvm_hosts_t *alive_hosts_list = NULL;
Expand All @@ -1035,12 +1035,10 @@ attack_network (struct scan_globals *globals)
port_range = prefs_get ("port_range");
if (validate_port_range (port_range))
{
kb_t main_kb = NULL;

connect_main_kb (&main_kb);
error_message_to_client2 (
message_to_client (
main_kb, "Invalid port list. Ports must be in the range [1-65535]",
NULL, NULL);
NULL, NULL, "ERRMSG");
kb_lnk_reset (main_kb);
g_warning ("Invalid port list. Ports must be in the range [1-65535]. "
"Scan terminated.");
Expand All @@ -1062,16 +1060,13 @@ attack_network (struct scan_globals *globals)

if (plugins_init_error > 0)
{
char buf[96];
kb_t main_kb = NULL;

sprintf (buf,
"%d errors were found during the plugin scheduling. "
"Some plugins have not been launched.",
plugins_init_error);

connect_main_kb (&main_kb);
error_message_to_client2 (main_kb, buf, NULL, NULL);
message_to_client (main_kb, buf, NULL, NULL, "ERRMSG");
kb_lnk_reset (main_kb);
}

Expand All @@ -1081,20 +1076,20 @@ attack_network (struct scan_globals *globals)
hosts = gvm_hosts_new (hostlist);
unresolved = gvm_hosts_resolve (hosts);

/* Duplicated hosts are removed from the list and ospd-openvas
needs to know that less hosts will be scanned, for the scan progress
calculation. Sent the amount of duplicated hosts as dead hosts to not
be taken in account. */
duplicated_hosts = gvm_hosts_duplicated (hosts);
if (duplicated_hosts > 0)
send_dead_hosts_to_ospd_openvas (duplicated_hosts);

while (unresolved)
{
g_warning ("Couldn't resolve hostname '%s'", (char *) unresolved->data);
unresolved = unresolved->next;
}
g_slist_free_full (unresolved, g_free);

/* Send the hosts count to the client, after removing duplicated and
* unresolved hosts.*/
sprintf (buf, "%d", gvm_hosts_count (hosts));
connect_main_kb (&main_kb);
message_to_client (main_kb, buf, NULL, NULL, "HOSTS_COUNT");
kb_lnk_reset (main_kb);

/* Apply Hosts preferences. */
apply_hosts_preferences (hosts);

Expand Down

0 comments on commit 6359774

Please sign in to comment.