Skip to content

Commit

Permalink
Fix: fix an issue which produces an interrupted scan, originated on a…
Browse files Browse the repository at this point in the history
… wrong count of excluded hosts. (#1509)

Since excluded hosts are handled in OSPD, we need to keep the total host count which includes the hosts which will be excluded later
  • Loading branch information
jjnicola committed Oct 11, 2023
1 parent 6022fd8 commit 9542a1c
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions src/attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,44 @@ apply_hosts_preferences_ordering (gvm_hosts_t *hosts)
g_debug ("hosts_ordering: Sequential.");
}

static void
static int
apply_hosts_reverse_lookup_preferences (gvm_hosts_t *hosts)
{
#ifdef FEATURE_REVERSE_LOOKUP_EXCLUDED
const char *exclude_hosts = prefs_get ("exclude_hosts");
int hosts_excluded = 0;

if (prefs_get_bool ("reverse_lookup_unify"))
{
gvm_hosts_t *excluded;

excluded = gvm_hosts_reverse_lookup_unify_excluded (hosts);
g_debug ("reverse_lookup_unify: Skipped %lu host(s).", excluded->count);

// Get the amount of hosts which are excluded now for this option,
// but they are already in the exclude list.
// This is to avoid issues with the scan progress calculation, since
// the amount of excluded host could be duplicated.
hosts_excluded += gvm_hosts_exclude (excluded, exclude_hosts);

gvm_hosts_free (excluded);
}

if (prefs_get_bool ("reverse_lookup_only"))
{
gvm_hosts_t *excluded;

excluded = gvm_hosts_reverse_lookup_only_excluded (hosts);
g_debug ("reverse_lookup_unify: Skipped %lu host(s).", excluded->count);
// Get the amount of hosts which are excluded now for this option,
// but they are already in the exclude list.
// This is to avoid issues with the scan progress calculation, since
// the amount of excluded host could be duplicated.
hosts_excluded += gvm_hosts_exclude (excluded, exclude_hosts);
gvm_hosts_free (excluded);
}
return exclude_hosts ? hosts_excluded : 0;
#else
/* Reverse-lookup unify ? */
if (prefs_get_bool ("reverse_lookup_unify"))
g_debug ("reverse_lookup_unify: Skipped %d host(s).",
Expand All @@ -1095,6 +1130,9 @@ apply_hosts_reverse_lookup_preferences (gvm_hosts_t *hosts)
if (prefs_get_bool ("reverse_lookup_only"))
g_debug ("reverse_lookup_only: Skipped %d host(s).",
gvm_hosts_reverse_lookup_only (hosts));

return 0;
#endif
}

static int
Expand Down Expand Up @@ -1311,7 +1349,9 @@ attack_network (struct scan_globals *globals)

/* Apply Hosts preferences. */
apply_hosts_preferences_ordering (hosts);
apply_hosts_reverse_lookup_preferences (hosts);

int already_excluded = 0;
already_excluded = apply_hosts_reverse_lookup_preferences (hosts);

#ifdef FEATURE_HOSTS_ALLOWED_ONLY
// Remove hosts which are denied and/or keep the ones in the allowed host
Expand All @@ -1322,7 +1362,7 @@ attack_network (struct scan_globals *globals)

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

0 comments on commit 9542a1c

Please sign in to comment.