37#include <bsd/unistd.h>
42#include <gnutls/gnutls.h>
44#include <gvm/base/logging.h>
45#include <gvm/base/nvti.h>
46#include <gvm/base/prefs.h>
47#include <gvm/base/version.h>
48#include <gvm/util/kb.h>
49#include <gvm/util/mqtt.h>
50#include <gvm/util/nvticache.h>
51#include <gvm/util/uuidutils.h>
62#ifdef GIT_REV_AVAILABLE
63#include "gitrevision.h"
66#if GNUTLS_VERSION_NUMBER < 0x030300
74#define G_LOG_DOMAIN "sd main"
76#define PROCTITLE_WAITING "openvas: Waiting for incoming connections"
77#define PROCTITLE_LOADING "openvas: Loading Handler"
78#define PROCTITLE_RELOADING "openvas: Reloading"
79#define PROCTITLE_SERVING "openvas: Serving %s"
111 {
"plugins_folder", OPENVAS_NVT_DIR},
112 {
"include_folders", OPENVAS_NVT_DIR},
113 {
"plugins_timeout", G_STRINGIFY (NVT_TIMEOUT)},
114 {
"scanner_plugins_timeout", G_STRINGIFY (SCANNER_NVT_TIMEOUT)},
115 {
"db_address", KB_PATH_DEFAULT},
131 g_message (
"(%d) %s", level, text);
139 if ((str = prefs_get (
"max_hosts")) != NULL)
146 if ((str = prefs_get (
"max_checks")) != NULL)
153 if ((str = prefs_get (
"max_sysload")) != NULL)
160 if ((str = prefs_get (
"min_free_mem")) != NULL)
205 struct kb_item *res = NULL;
207 g_debug (
"Start loading scan preferences.");
211 snprintf (key,
sizeof (key),
"internal/%s/scanprefs", globals->
scan_id);
213 kb = kb_find (prefs_get (
"db_address"), key);
220 res = kb_item_get_all (kb, key);
226 gchar **pref = g_strsplit (res->v_str,
"|||", 2);
229 gchar **pref_name = g_strsplit (pref[0],
":", 3);
230 if (pref_name[1] && pref_name[2] && !strncmp (pref_name[2],
"file", 4)
231 && strcmp (pref[1],
""))
233 char *file_uuid = gvm_uuid_make ();
235 prefs_set (pref[0], file_uuid);
236 ret =
store_file (globals, pref[1], file_uuid);
238 g_debug (
"Load preference: Failed to upload file "
239 "for nvt %s preference.",
245 g_warning (
"%s is a scanner only preference. It can not be written "
246 "by the client and will be ignored.",
249 prefs_set (pref[0], pref[1] ? pref[1] :
"");
250 g_strfreev (pref_name);
256 kb_del_items (kb, key);
257 snprintf (key,
sizeof (key),
"internal/%s", globals->
scan_id);
262 g_debug (
"End loading scan preferences.");
276 static gchar *log_config_file_name = NULL;
279 log_config_file_name =
280 g_build_filename (OPENVAS_SYSCONF_DIR,
"openvas_log.conf", NULL);
281 if (g_file_test (log_config_file_name, G_FILE_TEST_EXISTS))
282 log_config = load_log_configuration (log_config_file_name);
286 g_warning (
"%s: Can not open or create log file or directory. "
287 "Please check permissions of log files listed in %s.",
288 __func__, log_config_file_name);
289 g_free (log_config_file_name);
292 g_free (log_config_file_name);
300 if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P))
302 gcry_check_version (NULL);
303 gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN);
304 gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
305 gcry_control (GCRYCTL_RESUME_SECMEM_WARN);
306 gcry_control (GCRYCTL_INITIALIZATION_FINISHED);
315#if GNUTLS_VERSION_NUMBER < 0x030300
317 g_message (
"Could not initialize openvas SSL!");
320 if (prefs_get (
"debug_tls") != NULL && atoi (prefs_get (
"debug_tls")) > 0)
322 g_warning (
"TLS debug is enabled and should only be used with care, "
323 "since it may reveal sensitive information in the scanner "
324 "logs and might make openvas fill your disk rather quickly.");
326 gnutls_global_set_log_level (atoi (prefs_get (
"debug_tls")));
336#ifdef OPENVAS_GIT_REVISION
337 g_message (
"openvas %s (GIT revision %s) started", OPENVAS_VERSION,
338 OPENVAS_GIT_REVISION);
340 g_message (
"openvas %s started", OPENVAS_VERSION);
362 snprintf (key,
sizeof (key),
"internal/%s",
get_scan_id ());
363 kb = kb_find (prefs_get (
"db_address"), key);
367 pid = kb_item_get_int (kb,
"internal/ovas_pid");
378 killpg (
pid, SIGUSR1);
394 snprintf (key,
sizeof (key),
"internal/%s/scanprefs",
get_scan_id ());
395 kb = kb_find (prefs_get (
"db_address"), key);
396 kb_item_push_str (kb,
"internal/results", msg);
397 snprintf (key,
sizeof (key),
"internal/%s",
get_scan_id ());
398 kb_item_set_str (kb, key,
"finished", 0);
413 const char *mqtt_server_uri;
414 const char *openvasd_server_uri;
417 prefs_config (config_file);
420 if (prefs_get (
"vendor_version") != NULL)
427 g_message (
"Failed to initialize nvti cache.");
429 "ERRMSG||| ||| ||| ||| |||NVTI cache initialization failed");
436 openvasd_server_uri = prefs_get (
"openvasd_server");
437 if (openvasd_server_uri)
439 g_message (
"%s: LSC via openvasd", __func__);
440 prefs_set (
"openvasd_lsc_enabled",
"yes");
444 mqtt_server_uri = prefs_get (
"mqtt_server_uri");
448 const char *mqtt_user = prefs_get (
"mqtt_user");
449 const char *mqtt_pass = prefs_get (
"mqtt_pass");
450 if ((mqtt_init_auth (mqtt_server_uri, mqtt_user, mqtt_pass)) != 0)
452 if ((mqtt_init (mqtt_server_uri)) != 0)
455 g_message (
"%s: INIT MQTT: FAIL", __func__);
457 "ERRMSG||| ||| ||| ||| |||MQTT initialization failed");
461 g_message (
"%s: INIT MQTT: SUCCESS", __func__);
462 prefs_set (
"mqtt_enabled",
"yes");
467 g_message (
"%s: Neither openvasd_server nor mqtt_server_uri given, "
481 g_warning (
"No preferences found for the scan %s", globals->
scan_id);
498 setproctitle_init (argc, argv, env);
501 static gboolean display_version = FALSE;
502 static gchar *config_file = NULL;
504 static gchar *stop_scan_id = NULL;
505 static gboolean print_specs = FALSE;
506 static gboolean print_sysconfdir = FALSE;
507 static gboolean update_vt_info = FALSE;
508 GError *error = NULL;
509 GOptionContext *option_context;
510 static GOptionEntry entries[] = {
511 {
"version",
'V', 0, G_OPTION_ARG_NONE, &display_version,
512 "Display version information", NULL},
513 {
"config-file",
'c', 0, G_OPTION_ARG_FILENAME, &config_file,
514 "Configuration file",
"<filename>"},
515 {
"cfg-specs",
's', 0, G_OPTION_ARG_NONE, &print_specs,
516 "Print configuration settings", NULL},
517 {
"sysconfdir",
'y', 0, G_OPTION_ARG_NONE, &print_sysconfdir,
518 "Print system configuration directory (set at compile time)", NULL},
519 {
"update-vt-info",
'u', 0, G_OPTION_ARG_NONE, &update_vt_info,
520 "Updates VT info into redis store from VT files", NULL},
521 {
"scan-start",
'\0', 0, G_OPTION_ARG_STRING, &
scan_id,
522 "ID of scan to start. ID and related data must be stored into redis "
525 {
"scan-stop",
'\0', 0, G_OPTION_ARG_STRING, &stop_scan_id,
526 "ID of scan to stop",
"<string>"},
528 {NULL, 0, 0, 0, NULL, NULL, NULL}};
531 g_option_context_new (
"- Open Vulnerability Assessment Scanner");
532 g_option_context_add_main_entries (option_context, entries, NULL);
533 if (!g_option_context_parse (option_context, &argc, &argv, &error))
535 g_print (
"%s\n\n", error->message);
538 g_option_context_free (option_context);
541 if (print_sysconfdir)
543 g_print (
"%s\n", SYSCONFDIR);
550 printf (
"OpenVAS %s\n", OPENVAS_VERSION);
551#ifdef OPENVAS_GIT_REVISION
552 printf (
"GIT revision %s\n", OPENVAS_GIT_REVISION);
554 printf (
"gvm-libs %s\n", gvm_libs_version ());
555 printf (
"Most new code since 2005: (C) 2024 Greenbone AG\n");
557 "Nessus origin: (C) 2004 Renaud Deraison <deraison@nessus.org>\n");
558 printf (
"License GPLv2: GNU GPL version 2\n");
560 "This is free software: you are free to change and redistribute it.\n"
561 "There is NO WARRANTY, to the extent permitted by law.\n\n");
566 if (setenv (
"TZ",
"utc 0", 1) == -1)
568 g_print (
"%s\n\n", strerror (errno));
573#ifdef LOG_REFERENCES_AVAILABLE
577 set_log_reference (stop_scan_id);
584 g_message (
"Sentry is enabled. This can log sensitive information.");
589 config_file = OPENVAS_CONF;
594 prefs_config (config_file);
599 return err ? EXIT_FAILURE : EXIT_SUCCESS;
606 prefs_config (config_file);
609 g_message (
"Failed to initialize nvti cache. Not possible to "
620#ifdef LOG_REFERENCES_AVAILABLE
621 free_log_reference ();
623 return err ? EXIT_FAILURE : EXIT_SUCCESS;
629 int attack_error = 0;
645#ifdef LOG_REFERENCES_AVAILABLE
646 free_log_reference ();
651 g_warning (
"Scan ending with FAILURE status");
660 prefs_config (config_file);
int attack_network(struct scan_globals *globals)
Attack a whole network. return 0 on successes, -1 if there was a critical error.
int init_sentry(void)
Init sentry.
debug_utils.c headerfile.
void set_main_kb(kb_t kb)
sets the shared database between ospd and openvas as a main_kb for further usage. @description this s...
Header file to cache main_kb.
void nasl_okrb5_clean(void)
int openvas_SSL_init()
Initializes SSL support.
Header file for module network.
static volatile int termination_signal
int openvas(int argc, char *argv[], char *env[])
openvas.
static void my_gnutls_log_func(int level, const char *text)
static int attack_network_init(struct scan_globals *globals, const gchar *config_file)
Set up data needed for attack_network().
static void openvas_print_start_msg()
Print start message.
static void set_globals_from_preferences(void)
GSList * log_config
Logging parameters, as passed to setup_log_handlers.
static int overwrite_openvas_prefs_with_prefs_from_client(struct scan_globals *globals)
Read the scan preferences from redis.
static void set_default_openvas_prefs()
Set the prefs from the openvas_defaults array.
static void send_message_to_client_and_finish_scan(const char *msg)
Send a failure message and set the scan as finished.
static openvas_option openvas_defaults[]
Default values for scanner options. Must be NULL terminated.
static void handle_termination_signal(int sig)
static void init_signal_handlers(void)
Initializes main scanner process' signal handlers.
static int init_logging()
Init logging.
static void gcrypt_init(void)
static int stop_single_task_scan(void)
Search in redis the process ID of a running scan and sends it the kill signal SIGUSR1,...
static void check_tls()
Check TLS.
int plugins_init(void)
main function for loading all the plugins
int plugins_cache_init(void)
Main function for nvticache initialization without loading the plugins.
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....
int kb_item_set_int_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_set_int....
Header file for module plugutils.
void procs_terminate_childs(void)
This function terminates all processes spawned with create_process. Calls terminate_child for each pr...
int set_scan_id(const char *new_scan_id)
const char * get_scan_id()
void destroy_scan_globals(struct scan_globals *globals)
void(*)(int) openvas_signal(int signum, void(*handler)(int))
void sighand_chld(int sig)
headerfile for sighand.c.
int is_scanner_only_pref(const char *pref)
int store_file(struct scan_globals *globals, const char *file, const char *file_hash)
Stores a file type preference in a hash table.
void vendor_version_set(const gchar *version)
Set vendor version.
Header file: vendor version functions prototypes.