34#include <bsd/unistd.h>
38#include <gvm/base/hosts.h>
39#include <gvm/base/networking.h>
40#include <gvm/base/prefs.h>
41#include <gvm/boreas/alivedetection.h>
42#include <gvm/boreas/boreas_io.h>
43#include <gvm/util/mqtt.h>
44#include <gvm/util/nvticache.h>
52#define ERR_HOST_DEAD -1
54#define MAX_FORK_RETRIES 10
58#define KB_RETRY_DELAY 3
62#define INVALID_TARGET_LIST "-1"
68#define G_LOG_DOMAIN "sd main"
98 int i = atoi (prefs_get (
"ov_maindbid"));
100 *
main_kb = kb_direct_conn (prefs_get (
"db_address"), i);
106 g_warning (
"Not possible to get the main kb connection.");
149 snprintf (buffer,
sizeof (buffer),
"internal/%s",
scan_id);
174 const gchar *host_dead_status_code =
"0/-1";
175 const gchar *topic =
"internal/status";
179 if (strlen (ip_str) > 1998)
181 status = g_strjoin (
"/", ip_str, host_dead_status_code, NULL);
207 char status_buf[2048];
212 if (strlen (ip_str) > (
sizeof (status_buf) - 50))
215 snprintf (status_buf,
sizeof (status_buf),
"%s/%d/%d", ip_str, curr,
max);
224 const char *port,
const char *
type)
228 buf = g_strdup_printf (
"%s|||%s|||%s|||%s||| |||%s",
type,
229 ip_str ? ip_str :
"", ip_str ? ip_str :
"",
230 port ? port :
" ", msg ? msg :
"No error.");
240 errcode = abs (errcode);
241 msg = g_strdup_printf (
"WARNING: Cannot connect to KB at '%s': %s'",
242 prefs_get (
"db_address"), strerror (errcode));
243 g_warning (
"%s", msg);
252 now = then = time (NULL);
253 while (now - then < n)
255 waitpid (-1, NULL, WNOHANG);
296 GSList *vhosts = NULL;
302 gvm_vhost_t *tmp = vhosts->data;
304 if (!strcmp (tmp->value, vhost))
306 g_info (
"%s: vhost '%s' exists already", __func__, vhost);
309 vhosts = vhosts->next;
312 host_vhosts, gvm_vhost_new (g_strdup (vhost), g_strdup (source)));
313 g_info (
"%s: add vhost '%s' from '%s'", __func__, vhost, source);
319 char *package_list = NULL;
320 char *os_release = NULL;
326 os_release = kb_item_get_str (hostkb,
"ssh/login/release_notus");
328 package_list = kb_item_get_str (hostkb,
"ssh/login/package_list_notus");
335 snprintf (buffer,
sizeof (buffer),
336 "ERRMSG|||%s||| ||| ||| ||| Unable to "
337 "launch table driven lsc",
341 g_warning (
"%s: Unable to launch table driven LSC", __func__);
343 g_free (package_list);
359 g_warning (
"%s: Unknown data type.", __func__);
366 g_warning (
"%s: ihost data is NULL ignoring new vhost", __func__);
374 g_warning (
"%s: iuser_agent data is NULL, ignoring new user agent",
378 gchar *old_ua = NULL;
380 g_debug (
"%s: The User-Agent %s has been overwritten with %s",
389 && (prefs_get_bool (
"mqtt_enabled")
390 || prefs_get_bool (
"openvasd_lsc_enabled")))
392 struct in6_addr hostip;
393 gchar ip_str[INET6_ADDRSTRLEN];
397 g_warning (
"%s: Unknown data type.", __func__);
402 gvm_host_get_addr6 (args->
host, &hostip);
403 addr6_to_str (&hostip, ip_str);
424 for (
int j = 0; results[j] !=
'\0'; j++)
425 if (results[j] ==
'}')
427 gchar *message = NULL;
429 message = g_malloc0 (
sizeof (gchar) * (
len + 1));
430 memcpy (message, &results[pos],
len);
452 struct in6_addr *ip, GSList *vhosts,
455 int optimize = prefs_get_bool (
"optimize_test");
456 int launch_error,
pid, ret = 0;
457 char *
oid, *
name, *error = NULL, ip_str[INET6_ADDRSTRLEN];
461 addr6_to_str (ip, ip_str);
463 nvti = nvticache_get_nvt (
oid);
468 g_message (
"Plugin '%s' missing from nvticache.",
oid);
470 goto finish_launch_plugin;
475 goto finish_launch_plugin;
478 if (prefs_get_bool (
"safe_checks")
481 if (prefs_get_bool (
"log_whole_attack"))
483 name = nvticache_get_filename (
oid);
484 g_message (
"Not launching %s (%s) against %s because safe checks are"
485 " enabled (this is not an error)",
490 goto finish_launch_plugin;
496 error =
"because a mandatory key is missing";
501 if (prefs_get_bool (
"log_whole_attack"))
503 name = nvticache_get_filename (
oid);
505 "Not launching %s (%s) against %s %s (this is not an error)",
name,
509 goto finish_launch_plugin;
513 if (kb_item_get_int (args->
host_kb,
"Host/dead") > 0)
515 g_message (
"The remote host %s is dead", ip_str);
519 goto finish_launch_plugin;
539 goto finish_launch_plugin;
542 if (prefs_get_bool (
"log_whole_attack"))
544 name = nvticache_get_filename (
oid);
545 g_message (
"Launching %s (%s) against %s [%d]",
name,
oid, ip_str,
pid);
562 int num_plugs, forks_retry = 0, all_plugs_launched = 0;
563 char ip_str[INET6_ADDRSTRLEN];
567 addr6_to_str (ip, ip_str);
573 setproctitle (
"openvas: testing %s", ip_str);
596 killpg (parent, SIGUSR1);
606 static int last_status = 0, cur_plug = 0;
620 buffer,
sizeof (buffer),
621 "LOG|||%s||| |||general/Host_Details||| |||<host><detail>"
622 "<name>Host dead</name><value>1</value><source>"
623 "<description/><type/><name/></source></detail></host>",
636 g_warning (
"Launch failed for %s. No free slot available "
637 "in the internal process table for starting a "
650 "fork() failed for %s - sleeping %d seconds (%s)",
651 plugin->
oid, forks_retry, strerror (errno));
657 g_warning (
"fork() failed too many times - aborting");
663 if ((cur_plug * 100) / num_plugs >= last_status
666 last_status = (cur_plug * 100) / num_plugs + 2;
673 else if (plugin == NULL)
683 && (prefs_get_bool (
"mqtt_enabled")
684 || prefs_get_bool (
"openvasd_lsc_enabled")))
695 all_plugs_launched = 1;
700 g_message (
"Vulnerability scan %s for host %s: not all plugins "
723 string = g_string_new (((gvm_vhost_t *)
list->data)->value);
724 if (g_slist_length (
list) == 1)
725 return g_string_free (
string, FALSE);
729 g_string_append (
string,
", ");
730 g_string_append (
string, ((gvm_vhost_t *)
list->data)->value);
733 return g_string_free (
string, FALSE);
742 const gchar *source_iface = prefs_get (
"source_iface");
743 const gchar *ifaces_allow = prefs_get (
"ifaces_allow");
744 const gchar *ifaces_deny = prefs_get (
"ifaces_deny");
745 const gchar *sys_ifaces_allow = prefs_get (
"sys_ifaces_allow");
746 const gchar *sys_ifaces_deny = prefs_get (
"sys_ifaces_deny");
748 if (source_iface || ifaces_allow || ifaces_deny || sys_ifaces_allow
754 msg = g_strdup_printf (
755 "The following provided settings are deprecated since the 22.4 "
756 "release and will be ignored: %s%s%s%s%s",
757 source_iface ?
"source_iface (task setting) " :
"",
758 ifaces_allow ?
"ifaces_allow (user setting) " :
"",
759 ifaces_deny ?
"ifaces_deny (user setting) " :
"",
760 sys_ifaces_allow ?
"sys_ifaces_allow (scanner only setting) " :
"",
761 sys_ifaces_deny ?
"sys_ifaces_deny (scanner only setting)" :
"");
762 g_warning (
"%s: %s", __func__, msg);
771#ifndef FEATURE_HOSTS_ALLOWED_ONLY
785 const gvm_hosts_t *hosts_allow,
const gvm_hosts_t *hosts_deny)
791 if (hosts_deny && gvm_host_in_hosts (
host, addr, hosts_deny))
793 if (hosts_allow && !gvm_host_in_hosts (
host, addr, hosts_allow))
811 gvm_hosts_t *hosts_allow, *hosts_deny;
812 gvm_hosts_t *sys_hosts_allow, *sys_hosts_deny;
815 hosts_allow = gvm_hosts_new (prefs_get (
"hosts_allow"));
816 hosts_deny = gvm_hosts_new (prefs_get (
"hosts_deny"));
820 sys_hosts_allow = gvm_hosts_new (prefs_get (
"sys_hosts_allow"));
821 sys_hosts_deny = gvm_hosts_new (prefs_get (
"sys_hosts_deny"));
825 gvm_hosts_free (hosts_allow);
826 gvm_hosts_free (hosts_deny);
827 gvm_hosts_free (sys_hosts_allow);
828 gvm_hosts_free (sys_hosts_deny);
841 char ip_str[INET6_ADDRSTRLEN], *hostnames;
842 struct in6_addr hostip;
852 gettimeofday (&then, NULL);
860 if (prefs_get_bool (
"expand_vhosts"))
861 gvm_host_add_reverse_lookup (args->
host);
862 if ((ret = gvm_vhosts_exclude (args->
host, prefs_get (
"exclude_hosts"))) > 0)
863 g_message (
"exclude_hosts: Skipped %d vhost(s).", ret);
864 gvm_host_get_addr6 (args->
host, &hostip);
865 addr6_to_str (&hostip, ip_str);
867#ifndef FEATURE_HOSTS_ALLOWED_ONLY
869 if (ret_host_auth < 0)
871 if (ret_host_auth == -1)
875 ip_str, NULL,
"ERRMSG");
878 g_warning (
"Host %s access denied.", ip_str);
883 if (prefs_get_bool (
"test_empty_vhost"))
886 gvm_vhost_new (g_strdup (ip_str), g_strdup (
"IP-address"));
887 args->
host->vhosts = g_slist_prepend (args->
host->vhosts, vhost);
891 g_message (
"Vulnerability scan %s started for host: %s (Vhosts: %s)",
892 globals->
scan_id, ip_str, hostnames);
894 g_message (
"Vulnerability scan %s started for host: %s", globals->
scan_id,
904 gettimeofday (&now, NULL);
905 if (now.tv_usec < then.tv_usec)
908 now.tv_usec += 1000000;
911 "Vulnerability scan %s finished for host %s in %ld.%.2ld seconds",
912 globals->
scan_id, ip_str, (
long) (now.tv_sec - then.tv_sec),
913 (
long) ((now.tv_usec - then.tv_usec) / 10000));
920 const char *exclude_hosts = prefs_get (
"exclude_hosts");
926 ret = gvm_hosts_exclude (
hosts, exclude_hosts);
929 g_message (
"exclude_hosts: Skipped %d host(s).", ret);
931 g_message (
"exclude_hosts: Error.");
936#ifdef FEATURE_HOSTS_ALLOWED_ONLY
938print_host_access_denied (gpointer data, gpointer systemwide)
941 int *sw = systemwide;
948 "Host access denied (system-wide restriction).",
949 (gchar *) data, NULL,
"ERRMSG");
953 g_warning (
"Host %s access denied.", (gchar *) data);
957apply_hosts_allow_deny (gvm_hosts_t *
hosts)
959 GSList *removed = NULL;
960 const char *allow_hosts = prefs_get (
"hosts_allow");
961 const char *deny_hosts = prefs_get (
"hosts_deny");
963 if (allow_hosts || deny_hosts)
966 removed = gvm_hosts_allowed_only (
hosts, deny_hosts, allow_hosts);
967 g_slist_foreach (removed, print_host_access_denied,
968 (gpointer) &systemwide);
969 g_slist_free_full (removed, g_free);
972 const char *sys_allow_hosts = prefs_get (
"sys_hosts_allow");
973 const char *sys_deny_hosts = prefs_get (
"sys_hosts_deny");
974 if (sys_allow_hosts || sys_deny_hosts)
977 removed = gvm_hosts_allowed_only (
hosts, sys_deny_hosts, sys_allow_hosts);
978 g_slist_foreach (removed, print_host_access_denied,
979 (gpointer) &systemwide);
980 g_slist_free_full (removed, g_free);
988 const char *ordering = prefs_get (
"hosts_ordering");
993 if (!strcmp (ordering,
"random"))
995 gvm_hosts_shuffle (
hosts);
996 g_debug (
"hosts_ordering: Random.");
998 else if (!strcmp (ordering,
"reverse"))
1000 gvm_hosts_reverse (
hosts);
1001 g_debug (
"hosts_ordering: Reverse.");
1005 g_debug (
"hosts_ordering: Sequential.");
1011#ifdef FEATURE_REVERSE_LOOKUP_EXCLUDED
1012 const char *exclude_hosts = prefs_get (
"exclude_hosts");
1013 int hosts_excluded = 0;
1015 if (prefs_get_bool (
"reverse_lookup_unify"))
1017 gvm_hosts_t *excluded;
1019 excluded = gvm_hosts_reverse_lookup_unify_excluded (
hosts);
1020 g_debug (
"reverse_lookup_unify: Skipped %zu host(s).", excluded->count);
1026 hosts_excluded += gvm_hosts_exclude (excluded, exclude_hosts);
1028 gvm_hosts_free (excluded);
1031 if (prefs_get_bool (
"reverse_lookup_only"))
1033 gvm_hosts_t *excluded;
1035 excluded = gvm_hosts_reverse_lookup_only_excluded (
hosts);
1036 g_debug (
"reverse_lookup_unify: Skipped %zu host(s).", excluded->count);
1041 hosts_excluded += gvm_hosts_exclude (excluded, exclude_hosts);
1042 gvm_hosts_free (excluded);
1044 return exclude_hosts ? hosts_excluded : 0;
1047 if (prefs_get_bool (
"reverse_lookup_unify"))
1048 g_debug (
"reverse_lookup_unify: Skipped %d host(s).",
1049 gvm_hosts_reverse_lookup_unify (
hosts));
1052 if (prefs_get_bool (
"reverse_lookup_only"))
1053 g_debug (
"reverse_lookup_only: Skipped %d host(s).",
1054 gvm_hosts_reverse_lookup_only (
hosts));
1066 rc = kb_new (&kb, prefs_get (
"db_address"));
1103 static gboolean alive_detection_thread_already_joined = FALSE;
1105 alive_detection_thread_already_joined = TRUE;
1106 return alive_detection_thread_already_joined;
1120 static int already_called = 0;
1122 if (already_called == 1)
1126 pid = kb_item_get_str (
main_kb, (
"internal/ovas_pid"));
1131 if (
pid && (atoi (
pid) == getpid ()))
1137 if (prefs_get_bool (
"test_alive_hosts_only"))
1143 "Alive detection thread was already joined by other "
1144 "thread. Cancel operation not permitted or not needed.");
1152 "%s: pthread_cancel() returned ESRCH; No thread with the "
1153 "supplied ID could be found.",
1172 int max_hosts = 0, max_checks;
1173 const char *hostlist;
1176 int fork_retries = 0;
1179 const gchar *port_range;
1180 int allow_simultaneous_ips;
1188 gboolean test_alive_hosts_only = prefs_get_bool (
"test_alive_hosts_only");
1189 gvm_hosts_t *alive_hosts_list = NULL;
1190 kb_t alive_hosts_kb = NULL;
1191 if (test_alive_hosts_only)
1194 gettimeofday (&then, NULL);
1202 hostlist = prefs_get (
"TARGET");
1203 if (hostlist == NULL)
1210 port_range = prefs_get (
"port_range");
1211 if (validate_port_range (port_range))
1215 main_kb,
"Invalid port list. Ports must be in the range [1-65535]",
1216 NULL, NULL,
"ERRMSG");
1218 g_warning (
"Invalid port list. Ports must be in the range [1-65535]. "
1219 "Scan terminated.");
1227 int plugins_init_error = 0;
1229 prefs_get_bool (
"auto_enable_dependencies"),
1230 &plugins_init_error);
1233 g_message (
"Couldn't initialize the plugin scheduler");
1239 if (plugins_init_error > 0)
1242 "%d errors were found during the plugin scheduling. "
1243 "Some plugins have not been launched.",
1244 plugins_init_error);
1254 hosts = gvm_hosts_new (hostlist);
1258 buffer = g_strdup_printf (
"Invalid target list: %s.", hostlist);
1267 g_warning (
"Invalid target list. Scan terminated.");
1273 unresolved = gvm_hosts_resolve (
hosts);
1276 g_warning (
"Couldn't resolve hostname '%s'", (
char *) unresolved->data);
1277 unresolved = unresolved->next;
1279 g_slist_free_full (unresolved, g_free);
1284 int already_excluded = 0;
1287#ifdef FEATURE_HOSTS_ALLOWED_ONLY
1291 apply_hosts_allow_deny (
hosts);
1299 sprintf (buf,
"%d", exc + already_excluded);
1306 sprintf (buf,
"%d", gvm_hosts_count (
hosts));
1317 g_message (
"Vulnerability scan %s started: Target has %d hosts: "
1318 "%s, with max_hosts = %d and max_checks = %d",
1319 globals->
scan_id, gvm_hosts_count (
hosts), hostlist, max_hosts,
1322 if (test_alive_hosts_only)
1325 gboolean ad_finished = FALSE;
1328 struct in6_addr tmpaddr;
1332 err = pthread_create (&tid, NULL, start_alive_detection, (
void *)
hosts);
1335 "%s: pthread_create() returned EAGAIN: Insufficient resources "
1336 "to create thread.",
1339 g_debug (
"%s: started alive detection.", __func__);
1341 for (
host = get_host_from_queue (alive_hosts_kb, &ad_finished);
1343 host = get_host_from_queue (alive_hosts_kb, &ad_finished))
1348 if (gvm_host_get_addr6 (
host, &tmpaddr) == 0)
1353 "%s: Get first host to test from Queue. This host is used for "
1354 "initialising the alive_hosts_list.",
1357 alive_hosts_list = gvm_hosts_new (gvm_host_value_str (
host));
1360 if (prefs_get (
"report_scripts"))
1362 char *path = g_strdup_printf (
1363 "%s/%s-stats.json", prefs_get (
"report_scripts"), globals->
scan_id);
1370 allow_simultaneous_ips = prefs_get_bool (
"allow_simultaneous_ips");
1378 if (!test_alive_hosts_only
1383 gvm_hosts_move_current_host_to_end (
hosts);
1390 rc = kb_new (&arg_host_kb, prefs_get (
"db_address"));
1391 if (rc < 0 && rc != -2)
1405 host_str = gvm_host_value_str (
host);
1409 kb_delete (arg_host_kb);
1416 kb_delete (arg_host_kb);
1435 g_warning (
"fork() failed - %s. %s won't be tested",
1436 strerror (errno), host_str);
1441 g_debug (
"fork() failed - "
1442 "sleeping %d seconds and trying again...",
1449 if (test_alive_hosts_only)
1451 struct in6_addr tmpaddr;
1452 gvm_host_t *alive_buf;
1457 gboolean ad_finished = FALSE;
1458 for (
host = get_host_from_queue (alive_hosts_kb, &ad_finished);
1460 host = get_host_from_queue (alive_hosts_kb, &ad_finished))
1465 if (
host && !allow_simultaneous_ips
1468 struct in6_addr hostip;
1469 char ip_str[INET6_ADDRSTRLEN];
1472 gvm_host_get_addr6 (
host, &hostip);
1473 addr6_to_str (&hostip, ip_str);
1477 flag_set = finish_signal_on_queue (alive_hosts_kb);
1479 put_host_on_queue (alive_hosts_kb, ip_str);
1480 g_debug (
"Reallocating the host %s at the end of the queue",
1483 gvm_host_free (
host);
1488 g_debug (
"Reallocating finish signal in the host queue");
1489 realloc_finish_signal_on_queue (alive_hosts_kb);
1496 if (
host && gvm_host_get_addr6 (
host, &tmpaddr) == 0)
1500 gvm_host_free (alive_buf);
1505 gvm_hosts_add (alive_hosts_list, gvm_duplicate_host (
host));
1507 g_debug (
"%s: got NULL host, stop/finish scan", __func__);
1520 killpg (getpid (), SIGUSR1);
1522 g_debug (
"Test complete");
1526 if (test_alive_hosts_only)
1531 kb_lnk_reset (alive_hosts_kb);
1532 g_debug (
"%s: free alive detection data ", __func__);
1535 g_debug (
"%s: waiting for alive detection thread to be finished...",
1540 g_debug (
"%s: pthread_join() returned EDEADLK.", __func__);
1542 g_debug (
"%s: pthread_join() returned EINVAL.", __func__);
1544 g_debug (
"%s: pthread_join() returned ESRCH.", __func__);
1545 if (retval == PTHREAD_CANCELED)
1546 g_debug (
"%s: pthread_join() returned PTHREAD_CANCELED.", __func__);
1550 g_debug (
"%s: Finished waiting for alive detection thread.", __func__);
1555 gettimeofday (&now, NULL);
1556 if (test_alive_hosts_only)
1558 g_message (
"Vulnerability scan %s finished in %ld seconds: "
1559 "%d alive hosts of %d",
1560 globals->
scan_id, now.tv_sec - then.tv_sec,
1561 gvm_hosts_count (alive_hosts_list), gvm_hosts_count (
hosts));
1564 g_message (
"Vulnerability scan %s finished in %ld seconds: %d hosts",
1565 globals->
scan_id, now.tv_sec - then.tv_sec,
1566 gvm_hosts_count (
hosts));
1568 if (prefs_get (
"report_scripts"))
1571 g_strdup_printf (
"},\"scan_time\": {\"start\": %ld, \"stop\": %ld}}",
1572 then.tv_sec, now.tv_sec);
1573 char *path = g_strdup_printf (
1574 "%s/%s-stats.json", prefs_get (
"report_scripts"), globals->
scan_id);
1582 gvm_hosts_free (
hosts);
1583 if (alive_hosts_list)
1584 gvm_hosts_free (alive_hosts_list);
static int process_ipc_data(struct attack_start_args *args, const gchar *result)
Definition attack.c:348
static int comm_send_status(kb_t main_kb, char *ip_str, int curr, int max)
Sends the progress status of of a host's scan.
Definition attack.c:205
static int scan_is_stopped(void)
Definition attack.c:266
static void attack_start(struct ipc_context *ipcc, struct attack_start_args *args)
Set up some data and jump into attack_host()
Definition attack.c:838
int global_scan_stop
Definition attack.c:261
static int apply_hosts_reverse_lookup_preferences(gvm_hosts_t *hosts)
Definition attack.c:1009
static int nvti_category_is_safe(int category)
Checks that an NVT category is safe.
Definition attack.c:281
static void set_kb_readable(int host_kb_index)
Add the Host KB index to the list of readable KBs used by ospd-openvas.
Definition attack.c:118
static int apply_hosts_excluded(gvm_hosts_t *hosts)
Definition attack.c:918
static int comm_send_status_host_dead(kb_t main_kb, char *ip_str)
Send status to the client that the host is dead.
Definition attack.c:171
static void handle_scan_stop_signal()
Definition attack.c:1110
static int check_host_authorization(gvm_host_t *host, const struct in6_addr *addr)
Definition attack.c:809
static void attack_host(struct scan_globals *globals, struct in6_addr *ip, struct attack_start_args *args)
Attack one host.
Definition attack.c:558
static GSList * host_vhosts
Definition attack.c:291
static void set_alive_detection_tid(pthread_t tid)
Definition attack.c:1079
static void append_vhost(const char *vhost, const char *source)
Definition attack.c:294
static void call_lsc(struct attack_start_args *args, const char *ip_str)
Definition attack.c:317
static void fork_sleep(int n)
Definition attack.c:248
static void check_deprecated_prefs(void)
Check if any deprecated prefs are in pref table and print warning.
Definition attack.c:740
static int connect_main_kb(kb_t *main_kb)
Connect to the main kb. Must be released with kb_lnk_reset() after use.
Definition attack.c:96
static int launch_plugin(struct scan_globals *globals, struct scheduler_plugin *plugin, struct in6_addr *ip, GSList *vhosts, struct attack_start_args *args)
Launches a nvt. Respects safe check preference (i.e. does not try.
Definition attack.c:451
static int host_authorized(const gvm_host_t *host, const struct in6_addr *addr, const gvm_hosts_t *hosts_allow, const gvm_hosts_t *hosts_deny)
Definition attack.c:784
#define ERR_HOST_DEAD
Definition attack.c:52
static pthread_t alive_detection_tid
Definition attack.c:1076
static void report_kb_failure(int errcode)
Definition attack.c:236
static int check_kb_access(void)
Definition attack.c:1061
static int read_ipc(struct attack_start_args *args, struct ipc_context *ctx)
Definition attack.c:415
static void apply_hosts_preferences_ordering(gvm_hosts_t *hosts)
Definition attack.c:986
#define INVALID_TARGET_LIST
Definition attack.c:62
static void message_to_client(kb_t kb, const char *msg, const char *ip_str, const char *port, const char *type)
Definition attack.c:223
#define KB_RETRY_DELAY
Definition attack.c:58
#define MAX_FORK_RETRIES
Definition attack.c:54
static kb_t host_kb
Definition attack.c:290
static gboolean ad_thread_joined(gboolean joined)
Set and get if alive detection thread was already joined by main thread.
Definition attack.c:1101
static char * vhosts_to_str(GSList *list)
Definition attack.c:717
static pthread_t get_alive_detection_tid()
Definition attack.c:1084
int attack_network(struct scan_globals *globals)
Attack a whole network. return 0 on successes, -1 if there was a critical error.
Definition attack.c:1170
static void set_scan_status(char *status)
Set scan status. This helps ospd-openvas to identify if a scan crashed or finished cleanly.
Definition attack.c:135
static void scan_stop_cleanup(void)
Definition attack.c:1116
static struct host * hosts
Definition hosts.c:49
void host_set_time(kb_t kb, char *ip, char *type)
Add star_scan and end_scan results to the main kb.
Definition hosts.c:64
int host_is_currently_scanned(gvm_host_t *host_to_check)
Returns 1 if the host is being scanned. 0 otherwise.
Definition hosts.c:271
void hosts_stop_all(void)
Definition hosts.c:203
int hosts_set_pid(char *name, pid_t pid)
Definition hosts.c:177
int hosts_read(void)
Returns -1 if client asked to stop all tests or connection was lost or error. 0 otherwise.
Definition hosts.c:253
int hosts_init(int max_hosts)
Definition hosts.c:144
int hosts_new(char *name, kb_t kb, kb_t main_kb)
Definition hosts.c:151
char * ipc_retrieve(struct ipc_context *context, enum ipc_relation from)
retrieves data for the relation based on the context
Definition ipc.c:95
void(* ipc_process_func)(struct ipc_context *, void *)
Definition ipc.h:47
@ IPC_MAIN
Definition ipc.h:18
ipc_data_t * ipc_data_from_json(const char *json, size_t len)
transforms json string to a ipc_data struct
Definition ipc_openvas.c:400
gchar * ipc_get_hostname_from_data(ipc_data_t *data)
Get the hostname from IPC data.
Definition ipc_openvas.c:82
enum ipc_data_type ipc_get_data_type_from_data(ipc_data_t *data)
Get the data type in data.
Definition ipc_openvas.c:67
void ipc_data_destroy(ipc_data_t **data)
destroys ipc_data.
Definition ipc_openvas.c:294
gchar * ipc_get_user_agent_from_data(ipc_data_t *data)
Get the User-Agent from IPC data.
Definition ipc_openvas.c:114
gboolean ipc_get_lsc_data_ready_flag(ipc_data_t *data)
Get the package list from LSC IPC data.
Definition ipc_openvas.c:130
gchar * ipc_get_hostname_source_from_data(ipc_data_t *data)
Get the vhost hostname source from IPC data.
Definition ipc_openvas.c:98
struct ipc_data ipc_data_t
Definition ipc_openvas.h:23
@ IPC_DT_NO_DATA
Definition ipc_openvas.h:17
@ IPC_DT_HOSTNAME
Definition ipc_openvas.h:18
@ IPC_DT_USER_AGENT
Definition ipc_openvas.h:19
@ IPC_DT_ERROR
Definition ipc_openvas.h:16
@ IPC_DT_LSC
Definition ipc_openvas.h:20
kb_t get_main_kb(void)
gets the main_kb. @description returns the previously set main_kb; when asserts are enabled it will a...
Definition kb_cache.c:41
kb_t main_kb
Definition kb_cache.c:15
Header file to cache main_kb.
const char * oid
Definition nasl_builtin_find_service.c:51
static struct timeval timeval(unsigned long val)
Definition nasl_builtin_synscan.c:94
static pid_t pid
Definition nasl_cmd_exec.c:39
const char * name
Definition nasl_init.c:436
uint8_t len
Definition nasl_packet_forgery.c:1
#define max
Definition nasl_wmi.c:34
Header file for module network.
Category (ACT_*) definitions.
@ ACT_KILL_HOST
Definition nvt_categories.h:32
@ ACT_DESTRUCTIVE_ATTACK
Definition nvt_categories.h:30
@ ACT_FLOOD
Definition nvt_categories.h:33
@ ACT_DENIAL
Definition nvt_categories.h:31
Header file for module pcap.
void pluginlaunch_init(const char *host)
Definition pluginlaunch.c:324
int plugin_launch(struct scan_globals *globals, struct scheduler_plugin *plugin, struct in6_addr *ip, GSList *vhosts, kb_t kb, kb_t main_kb, nvti_t *nvti, int *error)
Start a plugin.
Definition pluginlaunch.c:480
void pluginlaunch_wait_for_free_process(kb_t main_kb, kb_t kb)
Waits and 'pushes' processes until the number of running processes has changed.
Definition pluginlaunch.c:550
void pluginlaunch_stop(void)
Definition pluginlaunch.c:363
void pluginlaunch_wait(kb_t main_kb, kb_t kb)
Waits and 'pushes' processes until num_running_processes is 0.
Definition pluginlaunch.c:517
#define ERR_CANT_FORK
Error for when it is not possible to fork a new plugin process.
Definition pluginlaunch.h:22
#define ERR_NO_FREE_SLOT
Error for when the process table is full.
Definition pluginlaunch.h:26
void plugins_scheduler_stop(plugins_scheduler_t sched)
Definition pluginscheduler.c:483
void plugins_scheduler_free(plugins_scheduler_t sched)
Definition pluginscheduler.c:518
int plugins_scheduler_count_active(plugins_scheduler_t sched)
Definition pluginscheduler.c:323
struct scheduler_plugin * plugins_scheduler_next(plugins_scheduler_t h)
Definition pluginscheduler.c:426
plugins_scheduler_t plugins_scheduler_init(const char *plugins_list, int autoload, int *error)
Definition pluginscheduler.c:302
header for pluginscheduler.c
@ PLUGIN_STATUS_DONE
Definition pluginscheduler.h:24
@ PLUGIN_STATUS_UNRUN
Definition pluginscheduler.h:22
struct plugins_scheduler * plugins_scheduler_t
Definition pluginscheduler.h:34
#define PLUG_RUNNING
Definition pluginscheduler.h:36
char * requirements_plugin(kb_t kb, nvti_t *nvti)
Determine if the plugin requirements are met.
Definition plugs_req.c:251
int mandatory_requirements_met(kb_t kb, nvti_t *nvti)
Check whether mandatory requirements for plugin are met.
Definition plugs_req.c:234
int kb_item_set_str_with_main_kb_check(kb_t kb, const char *name, const char *value, size_t len)
Check if the current kb corresponds to the original scanid, if it matches it call kb_item_set_str....
Definition plugutils.c:557
int kb_item_push_str_with_main_kb_check(kb_t kb, const char *name, const char *value)
Check if the current kb corresponds to the original scanid, if it matches it kb_item_push_str....
Definition plugutils.c:532
int kb_item_add_int_unique_with_main_kb_check(kb_t kb, const char *name, int value)
Check if the current kb corresponds to the original scanid, if it matches it call kb_item_add_int_uni...
Definition plugutils.c:656
int check_kb_inconsistency(kb_t main_kb)
Check if the current main kb corresponds to the original scan main kb. @description Compares the scan...
Definition plugutils.c:441
Header file for module plugutils.
const struct ipc_contexts * procs_get_ipc_contexts(void)
returns ipc_contexts.
Definition processes.c:239
static struct ipc_contexts * ipcc
Definition processes.c:39
pid_t create_ipc_process(ipc_process_func func, void *args)
initializes a communication channels and calls a function with a new process
Definition processes.c:195
const char * scan_id
Definition scan_id.c:10
void(*)(int) openvas_signal(int signum, void(*handler)(int))
Definition sighand.c:79
headerfile for sighand.c.
struct scan_globals * globals
Definition attack.c:76
kb_t host_kb
Definition attack.c:77
struct ipc_context * ipc_context
Definition attack.c:78
plugins_scheduler_t sched
Definition attack.c:79
gvm_host_t * host
Definition attack.c:80
Host information, implemented as doubly linked list.
Definition hosts.c:37
enum ipc_protocol type
Definition ipc.h:33
int len
Definition ipc.h:42
Definition nasl_builtin_synscan.c:249
struct list * next
Definition nasl_builtin_synscan.c:254
Definition scanneraux.h:19
char * scan_id
Definition scanneraux.h:22
pid_t host_pid
Definition scanneraux.h:23
Definition pluginscheduler.h:28
enum plugin_status running_state
Definition pluginscheduler.h:31
char * oid
Definition pluginscheduler.h:29
Define a string struct for storing the response.
Definition table_driven_lsc.c:831
int run_table_driven_lsc(const char *scan_id, const char *ip_str, const char *hostname, const char *package_list, const char *os_release)
Publish the necessary data to start a Table driven LSC scan.
Definition table_driven_lsc.c:1122
int lsc_has_run(void)
Get lsc_flag value.
Definition table_driven_lsc.c:48
void set_lsc_flag(void)
Set lsc_flag to 1.
Definition table_driven_lsc.c:40
gchar * user_agent_set(const gchar *ua)
Set user-agent.
Definition user_agent.c:89
Header file: user agent functions prototypes.
void write_script_stats(const char *buf, const char *path, int mode)
Writes scripts stats into a file.
Definition utils.c:271
void write_host_stats(kb_t kb, const char *scan_id, const char *ip)
Reads the script stats from the kb and generate a string in json format to be stored in the disk.
Definition utils.c:308
int get_max_hosts_number(void)
Definition utils.c:137
int get_max_checks_number(void)
Definition utils.c:168
int process_alive(pid_t pid)
Definition utils.c:198