|
OpenVAS Scanner 23.40.3
|
Launches the plugins, and manages multithreading. More...
#include "attack.h"#include "../misc/ipc_openvas.h"#include "../misc/kb_cache.h"#include "../misc/network.h"#include "../misc/nvt_categories.h"#include "../misc/pcap_openvas.h"#include "../misc/plugutils.h"#include "../misc/table_driven_lsc.h"#include "../misc/user_agent.h"#include "../nasl/nasl_debug.h"#include "hosts.h"#include "pluginlaunch.h"#include "pluginload.h"#include "pluginscheduler.h"#include "plugs_req.h"#include "processes.h"#include "sighand.h"#include "utils.h"#include <arpa/inet.h>#include <bsd/unistd.h>#include <errno.h>#include <fcntl.h>#include <glib.h>#include <gvm/base/hosts.h>#include <gvm/base/networking.h>#include <gvm/base/prefs.h>#include <gvm/boreas/alivedetection.h>#include <gvm/boreas/boreas_io.h>#include <gvm/util/mqtt.h>#include <gvm/util/nvticache.h>#include <pthread.h>#include <signal.h>#include <stdio.h>#include <string.h>#include <sys/wait.h>#include <unistd.h>

Go to the source code of this file.
Data Structures | |
| struct | attack_start_args |
Macros | |
| #define | ERR_HOST_DEAD -1 |
| #define | MAX_FORK_RETRIES 10 |
| #define | KB_RETRY_DELAY 3 /*In sec*/ |
| #define | INVALID_TARGET_LIST "-1" |
| #define | G_LOG_DOMAIN "sd main" |
| GLib log domain. | |
Functions | |
| static int | connect_main_kb (kb_t *main_kb) |
| Connect to the main kb. Must be released with kb_lnk_reset() after use. | |
| static void | set_kb_readable (int host_kb_index) |
| Add the Host KB index to the list of readable KBs used by ospd-openvas. | |
| static void | set_scan_status (char *status) |
| Set scan status. This helps ospd-openvas to identify if a scan crashed or finished cleanly. | |
| static int | comm_send_status_host_dead (kb_t main_kb, char *ip_str) |
| Send status to the client that the host is dead. | |
| 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. | |
| static void | message_to_client (kb_t kb, const char *msg, const char *ip_str, const char *port, const char *type) |
| static void | report_kb_failure (int errcode) |
| static void | fork_sleep (int n) |
| static void | scan_stop_cleanup (void) |
| static int | scan_is_stopped (void) |
| static int | nvti_category_is_safe (int category) |
| Checks that an NVT category is safe. | |
| static void | append_vhost (const char *vhost, const char *source) |
| static void | call_lsc (struct attack_start_args *args, const char *ip_str) |
| static int | process_ipc_data (struct attack_start_args *args, const gchar *result) |
| static int | read_ipc (struct attack_start_args *args, struct ipc_context *ctx) |
| 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. | |
| static void | attack_host (struct scan_globals *globals, struct in6_addr *ip, struct attack_start_args *args) |
| Attack one host. | |
| static char * | vhosts_to_str (GSList *list) |
| static void | check_deprecated_prefs (void) |
| Check if any deprecated prefs are in pref table and print warning. | |
| 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) |
| static int | check_host_authorization (gvm_host_t *host, const struct in6_addr *addr) |
| static void | attack_start (struct ipc_context *ipcc, struct attack_start_args *args) |
| Set up some data and jump into attack_host(). | |
| static int | apply_hosts_excluded (gvm_hosts_t *hosts) |
| static void | apply_hosts_preferences_ordering (gvm_hosts_t *hosts) |
| static int | apply_hosts_reverse_lookup_preferences (gvm_hosts_t *hosts) |
| static int | check_kb_access (void) |
| static void | set_alive_detection_tid (pthread_t tid) |
| static pthread_t | get_alive_detection_tid () |
| static gboolean | ad_thread_joined (gboolean joined) |
| Set and get if alive detection thread was already joined by main thread. | |
| static void | handle_scan_stop_signal () |
| int | attack_network (struct scan_globals *globals) |
| Attack a whole network. return 0 on successes, -1 if there was a critical error. | |
Variables | |
| int | global_scan_stop = 0 |
| static kb_t | host_kb = NULL |
| static GSList * | host_vhosts = NULL |
| static pthread_t | alive_detection_tid |
Launches the plugins, and manages multithreading.
Definition in file attack.c.
| #define ERR_HOST_DEAD -1 |
Definition at line 52 of file attack.c.
Referenced by attack_host(), and launch_plugin().
| #define INVALID_TARGET_LIST "-1" |
Define value to be sent to the client for invalid target list.
Definition at line 62 of file attack.c.
Referenced by attack_network().
| #define KB_RETRY_DELAY 3 /*In sec*/ |
Wait KB_RETRY_DELAY seconds until trying again to get a new kb.
Definition at line 58 of file attack.c.
Referenced by attack_network().
| #define MAX_FORK_RETRIES 10 |
Definition at line 54 of file attack.c.
Referenced by attack_host(), and attack_network().
|
static |
Set and get if alive detection thread was already joined by main thread.
The status can only be set to TRUE once in the lifetime of the program and retrieved as often as needed. After it is set to TRUE it can not be unset.
| joined | TRUE to set status to joined and FALSE to retrieve status of join. |
Definition at line 1099 of file attack.c.
Referenced by attack_network(), and scan_stop_cleanup().

|
static |
Definition at line 294 of file attack.c.
References host_vhosts.
Referenced by process_ipc_data().

|
static |
Definition at line 916 of file attack.c.
References hosts.
Referenced by attack_network().

|
static |
Definition at line 984 of file attack.c.
References hosts.
Referenced by attack_network().

|
static |
Definition at line 1007 of file attack.c.
References hosts.
Referenced by attack_network().

|
static |
Attack one host.
Definition at line 556 of file attack.c.
References call_lsc(), check_kb_inconsistency(), comm_send_status(), comm_send_status_host_dead(), ERR_CANT_FORK, ERR_HOST_DEAD, ERR_NO_FREE_SLOT, fork_sleep(), get_main_kb(), attack_start_args::host, attack_start_args::host_kb, host_kb, scan_globals::host_pid, host_set_time(), host_vhosts, kb_item_push_str_with_main_kb_check(), launch_plugin(), lsc_has_run(), MAX_FORK_RETRIES, scheduler_plugin::oid, PLUG_RUNNING, pluginlaunch_init(), pluginlaunch_stop(), pluginlaunch_wait(), pluginlaunch_wait_for_free_process(), plugins_scheduler_count_active(), plugins_scheduler_free(), plugins_scheduler_next(), plugins_scheduler_stop(), process_alive(), scan_globals::scan_id, scan_is_stopped(), attack_start_args::sched, and write_host_stats().
Referenced by attack_start().


| int attack_network | ( | struct scan_globals * | globals | ) |
Attack a whole network. return 0 on successes, -1 if there was a critical error.
Definition at line 1168 of file attack.c.
References ad_thread_joined(), apply_hosts_excluded(), apply_hosts_preferences_ordering(), apply_hosts_reverse_lookup_preferences(), attack_start(), check_deprecated_prefs(), check_kb_access(), connect_main_kb(), create_ipc_process(), fork_sleep(), get_alive_detection_tid(), get_max_checks_number(), get_max_hosts_number(), attack_start_args::globals, handle_scan_stop_signal(), attack_start_args::host, host_is_currently_scanned(), attack_start_args::host_kb, hosts, hosts_init(), hosts_new(), hosts_read(), hosts_set_pid(), INVALID_TARGET_LIST, KB_RETRY_DELAY, main_kb, MAX_FORK_RETRIES, message_to_client(), openvas_signal, pid, plugins_scheduler_free(), plugins_scheduler_init(), report_kb_failure(), scan_globals::scan_id, scan_is_stopped(), attack_start_args::sched, set_alive_detection_tid(), set_scan_status(), timeval(), and write_script_stats().
Referenced by openvas().


|
static |
Set up some data and jump into attack_host().
Definition at line 836 of file attack.c.
References attack_host(), check_host_authorization(), get_main_kb(), attack_start_args::globals, attack_start_args::host, attack_start_args::host_kb, attack_start_args::ipc_context, ipcc, kb_item_set_str_with_main_kb_check(), main_kb, message_to_client(), scan_globals::scan_id, scan_is_stopped(), set_kb_readable(), timeval(), and vhosts_to_str().
Referenced by attack_network().


|
static |
Definition at line 317 of file attack.c.
References get_main_kb(), attack_start_args::globals, attack_start_args::host_kb, kb_item_push_str_with_main_kb_check(), run_table_driven_lsc(), and scan_globals::scan_id.
Referenced by attack_host(), and process_ipc_data().


|
static |
Check if any deprecated prefs are in pref table and print warning.
Definition at line 738 of file attack.c.
References connect_main_kb(), main_kb, and message_to_client().
Referenced by attack_network().


|
static |
Definition at line 807 of file attack.c.
References host_authorized().
Referenced by attack_start().


|
static |
Definition at line 1059 of file attack.c.
References report_kb_failure().
Referenced by attack_network().


|
static |
Sends the progress status of of a host's scan.
Status format "current_host/launched/total". Current host is the ip_str of the current host which is vulnerability tested. Launched is the number of plguins(VTs) which got already started. Total is the total number of plugins which will be started for the current host.
| main_kb | Kb to use. |
| ip_str | str representation of host ip |
| curr | Currently launched plugins (VTs) for the host |
| max | Maximum number of plugins which will be launched for the host |
Definition at line 205 of file attack.c.
References kb_item_push_str_with_main_kb_check(), main_kb, and max.
Referenced by attack_host(), Ensure(), Ensure(), and Ensure().


|
static |
Send status to the client that the host is dead.
Originally the progress status is of the format "current_host/launched/total". Current host is the ip_str of the current host which is vulnerability tested. Launched is the number of plguins(VTs) which got already started. Total is the total number of plugins which will be started for the current host. But here we use the format "current_host/0/-1" for implicit singalling that the host is dead.
| main_kb | Kb to use |
| ip_str | str representation of host ip |
Definition at line 171 of file attack.c.
References kb_item_push_str_with_main_kb_check(), and main_kb.
Referenced by attack_host().


|
static |
Connect to the main kb. Must be released with kb_lnk_reset() after use.
| [out] | main_kb | The connection to the kb. |
Definition at line 96 of file attack.c.
References main_kb.
Referenced by attack_network(), check_deprecated_prefs(), scan_stop_cleanup(), set_kb_readable(), and set_scan_status().

|
static |
Definition at line 248 of file attack.c.
Referenced by attack_host(), and attack_network().

|
static |
Definition at line 1082 of file attack.c.
References alive_detection_tid.
Referenced by attack_network(), and scan_stop_cleanup().

|
static |
Definition at line 1108 of file attack.c.
References global_scan_stop.
Referenced by attack_network().

|
static |
Definition at line 782 of file attack.c.
Referenced by check_host_authorization().

|
static |
Launches a nvt. Respects safe check preference (i.e. does not try.
destructive nvt if save_checks is yes).
Does not launch a plugin twice if !save_kb_replay.
Definition at line 449 of file attack.c.
References ERR_CANT_FORK, ERR_HOST_DEAD, ERR_NO_FREE_SLOT, get_main_kb(), attack_start_args::host_kb, ipc_contexts::len, mandatory_requirements_met(), name, nvti_category_is_safe(), oid, scheduler_plugin::oid, pid, plugin_launch(), PLUGIN_STATUS_DONE, PLUGIN_STATUS_UNRUN, pluginlaunch_stop(), procs_get_ipc_contexts(), read_ipc(), requirements_plugin(), scheduler_plugin::running_state, and scan_is_stopped().
Referenced by attack_host().


|
static |
Definition at line 223 of file attack.c.
References kb_item_push_str_with_main_kb_check(), and ipc_context::type.
Referenced by attack_network(), attack_start(), and check_deprecated_prefs().


|
static |
Checks that an NVT category is safe.
| category | Category to check. |
Definition at line 281 of file attack.c.
References ACT_DENIAL, ACT_DESTRUCTIVE_ATTACK, ACT_FLOOD, and ACT_KILL_HOST.
Referenced by launch_plugin(), and main().

|
static |
Definition at line 348 of file attack.c.
References append_vhost(), call_lsc(), attack_start_args::host, ipc_data_destroy(), ipc_data_from_json(), IPC_DT_ERROR, IPC_DT_HOSTNAME, IPC_DT_LSC, IPC_DT_NO_DATA, IPC_DT_USER_AGENT, ipc_get_data_type_from_data(), ipc_get_hostname_from_data(), ipc_get_hostname_source_from_data(), ipc_get_lsc_data_ready_flag(), ipc_get_user_agent_from_data(), scan_is_stopped(), set_lsc_flag(), and user_agent_set().
Referenced by read_ipc().


|
static |
Definition at line 415 of file attack.c.
References IPC_DT_NO_DATA, IPC_MAIN, ipc_retrieve(), len, and process_ipc_data().
Referenced by launch_plugin().


|
static |
Definition at line 236 of file attack.c.
Referenced by attack_network(), and check_kb_access().

|
static |
Definition at line 266 of file attack.c.
References global_scan_stop, and scan_stop_cleanup().
Referenced by attack_host(), attack_network(), attack_start(), launch_plugin(), and process_ipc_data().


|
static |
Definition at line 1114 of file attack.c.
References ad_thread_joined(), connect_main_kb(), get_alive_detection_tid(), hosts_stop_all(), main_kb, pid, and pluginlaunch_stop().
Referenced by scan_is_stopped().


|
static |
Definition at line 1077 of file attack.c.
References alive_detection_tid.
Referenced by attack_network().

|
static |
Add the Host KB index to the list of readable KBs used by ospd-openvas.
| host_kb_index | The Kb index used for the host, to be stored in a list key in the main_kb. |
Definition at line 118 of file attack.c.
References connect_main_kb(), kb_item_add_int_unique_with_main_kb_check(), and main_kb.
Referenced by attack_start().


|
static |
Set scan status. This helps ospd-openvas to identify if a scan crashed or finished cleanly.
| [in] | status | Status to set. |
Definition at line 135 of file attack.c.
References check_kb_inconsistency(), connect_main_kb(), kb_item_set_str_with_main_kb_check(), main_kb, and scan_id.
Referenced by attack_network().


|
static |
Definition at line 715 of file attack.c.
References list::next.
Referenced by attack_start().

|
static |
Definition at line 1074 of file attack.c.
Referenced by get_alive_detection_tid(), and set_alive_detection_tid().
| int global_scan_stop = 0 |
Definition at line 261 of file attack.c.
Referenced by handle_scan_stop_signal(), hosts_new(), hosts_stop_all(), and scan_is_stopped().
|
static |
Definition at line 290 of file attack.c.
Referenced by attack_host(), and check_duplicated_vhost().
|
static |
Definition at line 291 of file attack.c.
Referenced by append_vhost(), and attack_host().