|
OpenVAS Scanner 22.7.9
|
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 <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 int | run_table_driven_lsc (const char *scan_id, kb_t kb, const char *ip_str, const char *hostname) |
| Publish the necessary data to start a Table driven LSC scan. | |
| static void | process_ipc_data (const gchar *result) |
| static void | read_ipc (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 void | 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 () |
| void | attack_network (struct scan_globals *globals) |
| Attack a whole network. | |
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 INVALID_TARGET_LIST "-1" |
| #define KB_RETRY_DELAY 3 /*In sec*/ |
|
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 1179 of file attack.c.
Referenced by attack_network(), and scan_stop_cleanup().

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

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

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

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

|
static |
Attack one host.
Definition at line 630 of file attack.c.
References 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(), 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(), run_table_driven_lsc(), scan_globals::scan_id, scan_is_stopped(), and attack_start_args::sched.
Referenced by attack_start().


| void attack_network | ( | struct scan_globals * | globals | ) |
Attack a whole network.
Definition at line 1247 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(), scan_globals::files_translation, 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(), and timeval().
Referenced by openvas().


|
static |
Set up some data and jump into attack_host()
Definition at line 917 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 |
Check if any deprecated prefs are in pref table and print warning.
Definition at line 819 of file attack.c.
References connect_main_kb(), main_kb, and message_to_client().
Referenced by attack_network().


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


|
static |
Definition at line 1139 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 204 of file attack.c.
References kb_item_push_str_with_main_kb_check(), main_kb, and max.
Referenced by attack_host(), 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 170 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 95 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 247 of file attack.c.
Referenced by attack_host(), and attack_network().

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

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

|
static |
Definition at line 863 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 525 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 222 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 280 of file attack.c.
References ACT_DENIAL, ACT_DESTRUCTIVE_ATTACK, ACT_FLOOD, and ACT_KILL_HOST.
Referenced by launch_plugin().

|
static |
Definition at line 454 of file attack.c.
References append_vhost(), ipc_data_destroy(), ipc_data_from_json(), IPC_DT_ERROR, IPC_DT_HOSTNAME, IPC_DT_USER_AGENT, ipc_get_data_type_from_data(), ipc_get_hostname_from_data(), ipc_get_hostname_source_from_data(), ipc_get_user_agent_from_data(), and user_agent_set().
Referenced by read_ipc().


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


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

|
static |
Publish the necessary data to start a Table driven LSC scan.
If the gather-package-list.nasl plugin was launched, and it generated a valid package list for a supported OS, the table driven LSC scan which is subscribed to the topic will perform a scan an publish the the results to be handle by the sensor/client.
| scan_id | Scan Id. |
| kb | |
| ip_str | IP string of host. |
| hostname | Name of host. |
Definition at line 331 of file attack.c.
References get_status_of_table_driven_lsc_from_json(), hostname, make_table_driven_lsc_info_json_str(), payload, and scan_id.
Referenced by attack_host().


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


|
static |
Definition at line 1194 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 1157 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 117 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 134 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 796 of file attack.c.
References list::next.
Referenced by attack_start().

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