|
OpenVAS Scanner 23.32.3
|
glue between openvas and nasl scripts. More...
#include "nasl_scanner_glue.h"#include "../misc/ipc_openvas.h"#include "../misc/kb_cache.h"#include "../misc/network.h"#include "../misc/plugutils.h"#include "../misc/support.h"#include "../misc/table_driven_lsc.h"#include "../misc/vendorversion.h"#include "nasl_debug.h"#include "nasl_func.h"#include "nasl_global_ctxt.h"#include "nasl_lex_ctxt.h"#include "nasl_tree.h"#include "nasl_var.h"#include <ctype.h>#include <errno.h>#include <fcntl.h>#include <glib.h>#include <gvm/base/logging.h>#include <gvm/base/networking.h>#include <gvm/base/prefs.h>#include <gvm/util/kb.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <unistd.h>
Go to the source code of this file.
Macros | |
| #define | G_LOG_DOMAIN "lib nasl" |
| GLib logging domain. | |
Typedefs | |
| typedef void(* | proto_post_something_t) (const char *, struct script_infos *, int, const char *, const char *, const char *) |
| typedef void(* | post_something_t) (const char *, struct script_infos *, int, const char *, const char *) |
Variables | |
| static int | notus_err = 0 |
| Error code for Notus. | |
glue between openvas and nasl scripts.
This file contains all the functions that make the "glue" between as NASL script and openvas. (script_*(), kb(), scanner_*())
Definition in file nasl_scanner_glue.c.
| #define G_LOG_DOMAIN "lib nasl" |
GLib logging domain.
Definition at line 49 of file nasl_scanner_glue.c.
| typedef void(* post_something_t) (const char *, struct script_infos *, int, const char *, const char *) |
Function is used when the script wants to report a problem back to openvas.
Definition at line 950 of file nasl_scanner_glue.c.
| typedef void(* proto_post_something_t) (const char *, struct script_infos *, int, const char *, const char *, const char *) |
Function is used when the script wants to report a problem back to openvas.
Definition at line 944 of file nasl_scanner_glue.c.
Definition at line 1146 of file nasl_scanner_glue.c.
References post_error(), proto_post_error(), and security_something().

Get the kb index of the host running the current script.
| [in] | lexic | NASL lexer. |
Definition at line 765 of file nasl_scanner_glue.c.
References alloc_typed_cell(), CONST_INT, TC::i_val, script_infos::key, struct_lex_ctxt::script_infos, val, and TC::x.

Definition at line 713 of file nasl_scanner_glue.c.
References alloc_typed_cell(), CONST_DATA, CONST_INT, get_int_var_by_num(), get_str_var_by_num(), TC::i_val, len, plug_get_key(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, TC::type, val, and TC::x.

Definition at line 652 of file nasl_scanner_glue.c.
References add_var_to_array(), alloc_typed_cell(), deref_cell(), DYN_ARRAY, FAKE_CELL, get_str_var_by_num(), nasl_perror(), plug_get_kb(), TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, struct_lex_ctxt::script_infos, st_a_nasl_var::v, st_a_nasl_var::v_int, st_a_nasl_var::v_str, VAR2_DATA, VAR2_INT, st_a_nasl_var::var_type, and TC::x.

Return the OID of the current script.
| [in] | lexic | NASL lexer. |
Definition at line 634 of file nasl_scanner_glue.c.
References alloc_typed_cell(), CONST_DATA, oid, struct_lex_ctxt::oid, TC::size, TC::str_val, and TC::x.

|
static |
Definition at line 54 of file nasl_scanner_glue.c.
References len.
Referenced by script_get_preference().

Definition at line 1138 of file nasl_scanner_glue.c.
References post_log_with_uri(), proto_post_log(), and security_something().

Definition at line 1152 of file nasl_scanner_glue.c.
References alloc_typed_cell(), CONST_DATA, get_str_var_by_num(), name, nasl_perror(), TC::size, TC::str_val, and TC::x.

Directly runs a LSC with the given package list and OS release.
This function runs a Notus scan using the provided package list and OS release. In case of success, it returns a list of Notus results in a JSON-like format. If an error occurs, it returns NULL and sets the notus_err variable to the appropriate error code. The error can be gathered using the notus_error function.
| [in] | lexic | Lexical context of the NASL interpreter. |
Definition at line 1263 of file nasl_scanner_glue.c.
References add_var_to_array(), add_var_to_list(), advisories::advisories, advisories_free(), alloc_typed_cell(), advisories::count, advisory::count, deref_cell(), DYN_ARRAY, get_str_var_by_name(), vulnerable_pkg::install_version, name, notus_err, notus_get_response(), advisory::oid, oid, vulnerable_pkg::pkg_name, advisory::pkgs, process_notus_response(), RANGE, vulnerable_pkg::range, TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, SINGLE, fixed_version::specifier, version_range::start, version_range::stop, vulnerable_pkg::type, st_a_nasl_var::v, st_a_nasl_var::v_arr, st_a_nasl_var::v_str, VAR2_ARRAY, VAR2_STRING, st_a_nasl_var::var_type, fixed_version::version, vulnerable_pkg::version, and TC::x.

Get the last Notus error as string.
| [in] | lexic | Lexical context of the NASL interpreter. |
Definition at line 1404 of file nasl_scanner_glue.c.
References alloc_typed_cell(), CONST_STR, notus_err, TC::size, TC::str_val, and TC::x.

Definition at line 1479 of file nasl_scanner_glue.c.
References FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), scanner_add_port(), and struct_lex_ctxt::script_infos.

If the plugin is a port scanner, it needs to report the list of open ports back to openvas scanner, and it also needs to know which ports are to be scanned.
Definition at line 1439 of file nasl_scanner_glue.c.
References alloc_typed_cell(), CONST_INT, get_int_var_by_num(), getpts(), TC::i_val, nasl_perror(), and TC::x.

Definition at line 1495 of file nasl_scanner_glue.c.
References FAKE_CELL.
Communicate to the parent process that LSC data is ready for use in the host kb.
| [in] | lexic | Lexical context of the NASL interpreter. |
Definition at line 1203 of file nasl_scanner_glue.c.
References ARG_STRING, get_str_var_by_name(), script_infos::ipc_context, ipc_data_destroy(), ipc_data_to_json(), ipc_data_type_from_lsc(), IPC_MAIN, ipc_send(), plug_set_key(), and struct_lex_ctxt::script_infos.

Definition at line 1175 of file nasl_scanner_glue.c.
References alloc_typed_cell(), CONST_DATA, TC::size, TC::str_val, vendor_version_get(), and TC::x.

Definition at line 784 of file nasl_scanner_glue.c.
References ARG_INT, ARG_STRING, FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), get_var_type_by_name(), len, name, nasl_perror(), plug_replace_key(), plug_replace_key_len(), struct_lex_ctxt::script_infos, and VAR2_INT.

Definition at line 616 of file nasl_scanner_glue.c.
References alloc_typed_cell(), CONST_INT, TC::i_val, and TC::x.
Referenced by plugin_run_openvas_tcp_scanner().


Definition at line 439 of file nasl_scanner_glue.c.
References FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), name, nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Definition at line 259 of file nasl_scanner_glue.c.
References FAKE_CELL, get_int_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Definition at line 252 of file nasl_scanner_glue.c.
References FAKE_CELL.
Definition at line 116 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Definition at line 283 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_num(), nasl_perror(), plug_set_dep(), and struct_lex_ctxt::script_infos.

Definition at line 380 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Definition at line 276 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Get a preferences of the current script.
Search the preference by preference name or by preferences id.
| [in] | lexic | NASL lexer. |
Definition at line 496 of file nasl_scanner_glue.c.
References alloc_typed_cell(), CONST_DATA, CONST_INT, FAKE_CELL, get_int_var_by_name(), get_plugin_preference(), get_str_var_by_num(), TC::i_val, isalldigit(), nasl_perror(), struct_lex_ctxt::oid, TC::size, TC::str_val, TC::type, and TC::x.

Definition at line 533 of file nasl_scanner_glue.c.
References alloc_typed_cell(), CONST_DATA, FAKE_CELL, get_plugin_preference(), get_plugin_preference_file_content(), get_plugin_preference_file_size(), get_str_var_by_num(), nasl_perror(), struct_lex_ctxt::oid, struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Definition at line 577 of file nasl_scanner_glue.c.
References alloc_typed_cell(), CONST_DATA, get_plugin_preference(), get_plugin_preference_fname(), get_str_var_by_num(), len, nasl_perror(), struct_lex_ctxt::oid, struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Definition at line 333 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_name(), get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Definition at line 238 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.
Referenced by nasl_perror(), and nasl_trace().


Definition at line 109 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Definition at line 309 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Definition at line 403 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Definition at line 421 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Definition at line 198 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_name(), name, nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Add timeout preference to VT preferences.
VT timeout is handled as normal VT preference. Because of backward compatibility issues the timeout preference is always located at the VT pref location with id NVTPREF_TIMEOUT_ID.
| [in] | lexic | lexic |
| [in] | to | script timeout |
Definition at line 91 of file nasl_scanner_glue.c.
References FAKE_CELL, get_int_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Definition at line 245 of file nasl_scanner_glue.c.
References FAKE_CELL.
Add a cross reference to the meta data.
The parameter "name" of the command defines actually the type, for example "URL" or "OSVDB". The parameter "value" is the actual reference. Alternative to "value", "csv" can be used with a list of comma-separated values.
In fact, if name is "cve", it is equivalent to call script_cve_id(), for example script_cve_id ("CVE-2019-12345"); is identical to script_xref (name: "cve", value: "CVE-2019-12345");
This even works with multiple comma-separated elements like script_xref (name: "cve", csv: "CVE-2019-12345,CVE-2019-54321");
| lexic | The parser context. |
Definition at line 154 of file nasl_scanner_glue.c.
References FAKE_CELL, get_str_var_by_name(), name, nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Send a security message to the client.
| [in] | lexic | NASL lexer. |
Definition at line 1132 of file nasl_scanner_glue.c.
References post_alarm(), proto_post_alarm(), and security_something().

Definition at line 1012 of file nasl_scanner_glue.c.
References FAKE_CELL, get_main_kb(), get_var_by_name(), get_variable_by_name(), script_infos::ip, kb_item_push_str_with_main_kb_check(), st_nasl_array::max_idx, name, nasl_get_var_by_num(), nasl_perror(), oid, TC::ref_val, st_nasl_string::s_val, struct_lex_ctxt::script_infos, st_n_nasl_var::u, st_a_nasl_var::v, st_a_nasl_var::v_arr, st_a_nasl_var::v_str, VAR2_ARRAY, st_a_nasl_var::var_type, and TC::x.

|
static |
Definition at line 954 of file nasl_scanner_glue.c.
References FAKE_CELL, get_int_var_by_name(), get_int_var_by_num(), get_str_var_by_name(), get_var_size_by_name(), len, struct_lex_ctxt::oid, struct_lex_ctxt::script_infos, and script_infos::standalone.
Referenced by error_message2(), log_message(), and security_message().


Set a kb item.
If expire is set the key will be removed after it expired.
| [in] | lexic | NASL lexer. |
| [in] | name | Name of Item. |
| [in] | value | Value of Item. |
| [in] | expire | Optional expire for item in seconds. |
Definition at line 894 of file nasl_scanner_glue.c.
References ARG_INT, ARG_STRING, FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), get_var_type_by_name(), len, name, nasl_perror(), plug_set_key(), plug_set_key_len(), struct_lex_ctxt::script_infos, set_kb_item_volatile(), and VAR2_INT.

Set a volatile kb item.
| [in] | lexic | NASL lexer. |
| [in] | name | Name of Item. |
| [in] | value | Value of Item. |
| [in] | expire | Optional expire for item in seconds. |
Definition at line 836 of file nasl_scanner_glue.c.
References ARG_INT, ARG_STRING, FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), get_var_type_by_name(), len, name, nasl_perror(), plug_set_key_len_volatile(), plug_set_key_volatile(), struct_lex_ctxt::script_infos, and VAR2_INT.
Referenced by set_kb_item().


|
static |
Error code for Notus.
The last occurred error code is stored in this variable.
Definition at line 1241 of file nasl_scanner_glue.c.
Referenced by nasl_notus(), and nasl_notus_error().