OpenVAS Scanner  6.0.0~git
Data Structures | Macros | Enumerations | Functions | Variables
attack.c File Reference

Launches the plugins, and manages multithreading. More...

#include "attack.h"
#include "../misc/network.h"
#include "../misc/nvt_categories.h"
#include "../misc/pcap_openvas.h"
#include "../nasl/nasl_debug.h"
#include "comm.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 <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/base/proctitle.h>
#include <gvm/util/nvticache.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

Data Structures

struct  attack_start_args
 

Macros

#define ERR_HOST_DEAD   -1
 
#define ERR_CANT_FORK   -2
 
#define MAX_FORK_RETRIES   10
 
#define PROGRESS_BAR_STYLE   1
 
#define G_LOG_DOMAIN   "sd main"
 GLib log domain. More...
 

Enumerations

enum  net_scan_status { NSS_NONE = 0, NSS_BUSY, NSS_DONE }
 

Functions

static int set_kb_readable (int host_kb_index)
 Add the Host KB index to the list of readable KBs used by ospd-openvas. More...
 
static int comm_send_status (kb_t kb, char *hostname, int curr, int max)
 Sends the status of a host's scan. More...
 
static void error_message_to_client (int soc, const char *msg, const char *hostname, const char *port)
 
static void error_message_to_client2 (kb_t kb, const char *msg, const char *port)
 
static void report_kb_failure (int soc, int errcode)
 
static void fork_sleep (int n)
 
static enum net_scan_status network_scan_status (struct scan_globals *globals)
 
static int scan_is_stopped ()
 
static int all_scans_are_stopped ()
 
static int nvti_category_is_safe (int category)
 Checks that an NVT category is safe. More...
 
static int launch_plugin (struct scan_globals *globals, struct scheduler_plugin *plugin, struct in6_addr *ip, GSList *vhosts, kb_t kb)
 Launches a nvt. Respects safe check preference (i.e. does not try. More...
 
static int kb_duplicate (kb_t dst, kb_t src, const gchar *filter)
 
static kb_t init_host_kb (struct scan_globals *globals, char *ip_str, kb_t *network_kb)
 Inits or loads the knowledge base for a single host. More...
 
static void check_new_vhosts ()
 Check if a plugin process pushed a new vhost value. More...
 
static void attack_host (struct scan_globals *globals, struct in6_addr *ip, GSList *vhosts, plugins_scheduler_t sched, kb_t kb, kb_t *net_kb)
 Attack one host. More...
 
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 char * vhosts_to_str (GSList *list)
 
static int check_host_authorization (gvm_host_t *host, const struct in6_addr *addr, kb_t kb)
 
static void attack_start (struct attack_start_args *args)
 Set up some data and jump into attack_host() More...
 
static void apply_hosts_preferences (gvm_hosts_t *hosts)
 
static int str_in_comma_list (const char *str, const char *comma_list)
 
static int iface_authorized (const char *iface)
 
static int apply_source_iface_preference (int soc)
 
static int check_kb_access (int soc)
 
static void handle_scan_stop_signal ()
 
static void handle_stop_all_scans_signal ()
 
void attack_network (struct scan_globals *globals, kb_t *network_kb)
 Attack a whole network. More...
 

Variables

int global_scan_stop = 0
 
int global_stop_all_scans = 0
 
static kb_t host_kb = NULL
 
static GSList * host_vhosts = NULL
 

Detailed Description

Launches the plugins, and manages multithreading.

Macro Definition Documentation

◆ ERR_CANT_FORK

#define ERR_CANT_FORK   -2

◆ ERR_HOST_DEAD

#define ERR_HOST_DEAD   -1

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "sd main"

GLib log domain.

◆ MAX_FORK_RETRIES

#define MAX_FORK_RETRIES   10

◆ PROGRESS_BAR_STYLE

#define PROGRESS_BAR_STYLE   1

It switches progress bar styles. If set to 1, time oriented style and it take into account only alive host. If set to 0, it not reflect progress adequately in case of dead host, which will take into account with 0% processed, producing jumps in the process bar.

Enumeration Type Documentation

◆ net_scan_status

Enumerator
NSS_NONE 
NSS_BUSY 
NSS_DONE 

Function Documentation

◆ all_scans_are_stopped()

static int all_scans_are_stopped ( )
static

◆ apply_hosts_preferences()

static void apply_hosts_preferences ( gvm_hosts_t *  hosts)
static

◆ apply_source_iface_preference()

static int apply_source_iface_preference ( int  soc)
static

◆ attack_host()

static void attack_host ( struct scan_globals globals,
struct in6_addr *  ip,
GSList *  vhosts,
plugins_scheduler_t  sched,
kb_t  kb,
kb_t *  net_kb 
)
static

Attack one host.

◆ attack_network()

void attack_network ( struct scan_globals globals,
kb_t *  network_kb 
)

Attack a whole network.

◆ attack_start()

static void attack_start ( struct attack_start_args args)
static

Set up some data and jump into attack_host()

◆ check_host_authorization()

static int check_host_authorization ( gvm_host_t *  host,
const struct in6_addr *  addr,
kb_t  kb 
)
static

◆ check_kb_access()

static int check_kb_access ( int  soc)
static

◆ check_new_vhosts()

static void check_new_vhosts ( )
static

Check if a plugin process pushed a new vhost value.

Parameters
kbHost scan KB.
vhostsList of vhosts to add new vhosts to.
Returns
New vhosts list.

◆ comm_send_status()

static int comm_send_status ( kb_t  kb,
char *  hostname,
int  curr,
int  max 
)
static

Sends the status of a host's scan.

◆ error_message_to_client()

static void error_message_to_client ( int  soc,
const char *  msg,
const char *  hostname,
const char *  port 
)
static

◆ error_message_to_client2()

static void error_message_to_client2 ( kb_t  kb,
const char *  msg,
const char *  port 
)
static

◆ fork_sleep()

static void fork_sleep ( int  n)
static

◆ handle_scan_stop_signal()

static void handle_scan_stop_signal ( )
static

◆ handle_stop_all_scans_signal()

static void handle_stop_all_scans_signal ( )
static

◆ host_authorized()

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

◆ iface_authorized()

static int iface_authorized ( const char *  iface)
static

◆ init_host_kb()

static kb_t init_host_kb ( struct scan_globals globals,
char *  ip_str,
kb_t *  network_kb 
)
static

Inits or loads the knowledge base for a single host.

Fills the knowledge base with host-specific login information for local checks if defined.

Parameters
globalsGlobal preference struct.
ip_strIP string of target host.
Returns
A knowledge base.

◆ kb_duplicate()

static int kb_duplicate ( kb_t  dst,
kb_t  src,
const gchar *  filter 
)
static

◆ launch_plugin()

static int launch_plugin ( struct scan_globals globals,
struct scheduler_plugin plugin,
struct in6_addr *  ip,
GSList *  vhosts,
kb_t  kb 
)
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.

Returns
ERR_HOST_DEAD if host died, ERR_CANT_FORK if forking failed, 0 otherwise.

◆ network_scan_status()

static enum net_scan_status network_scan_status ( struct scan_globals globals)
static

◆ nvti_category_is_safe()

static int nvti_category_is_safe ( int  category)
static

Checks that an NVT category is safe.

Parameters
categoryCategory to check.
Returns
0 if category is unsafe, 1 otherwise.

◆ report_kb_failure()

static void report_kb_failure ( int  soc,
int  errcode 
)
static

◆ scan_is_stopped()

static int scan_is_stopped ( )
static

◆ set_kb_readable()

static int set_kb_readable ( int  host_kb_index)
static

Add the Host KB index to the list of readable KBs used by ospd-openvas.

◆ str_in_comma_list()

static int str_in_comma_list ( const char *  str,
const char *  comma_list 
)
static

◆ vhosts_to_str()

static char* vhosts_to_str ( GSList *  list)
static

Variable Documentation

◆ global_scan_stop

int global_scan_stop = 0

◆ global_stop_all_scans

int global_stop_all_scans = 0

◆ host_kb

kb_t host_kb = NULL
static

◆ host_vhosts

GSList* host_vhosts = NULL
static