OpenVAS Scanner 23.40.3
nasl_scanner_glue.c File Reference

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 <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
Include dependency graph for nasl_scanner_glue.c:

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 *)

Functions

static int isalldigit (char *str, int len)
tree_cellscript_timeout (lex_ctxt *lexic)
 Add timeout preference to VT preferences.
tree_cellscript_oid (lex_ctxt *lexic)
tree_cellscript_cve_id (lex_ctxt *lexic)
tree_cellscript_xref (lex_ctxt *lexic)
 Add a cross reference to the meta data.
tree_cellscript_tag (lex_ctxt *lexic)
tree_cellscript_name (lex_ctxt *lexic)
tree_cellscript_version (lex_ctxt *lexic)
tree_cellscript_copyright (lex_ctxt *lexic)
tree_cellscript_category (lex_ctxt *lexic)
tree_cellscript_family (lex_ctxt *lexic)
tree_cellscript_dependencies (lex_ctxt *lexic)
tree_cellscript_require_keys (lex_ctxt *lexic)
tree_cellscript_mandatory_keys (lex_ctxt *lexic)
tree_cellscript_exclude_keys (lex_ctxt *lexic)
tree_cellscript_require_ports (lex_ctxt *lexic)
tree_cellscript_require_udp_ports (lex_ctxt *lexic)
tree_cellscript_add_preference (lex_ctxt *lexic)
tree_cellscript_get_preference (lex_ctxt *lexic)
 Get a preferences of the current script.
tree_cellscript_get_preference_file_content (lex_ctxt *lexic)
tree_cellscript_get_preference_file_location (lex_ctxt *lexic)
tree_cellsafe_checks (lex_ctxt *lexic)
tree_cellget_script_oid (lex_ctxt *lexic)
 Return the OID of the current script.
tree_cellget_kb_list (lex_ctxt *lexic)
tree_cellget_kb_item (lex_ctxt *lexic)
tree_cellget_host_kb_index (lex_ctxt *lexic)
 Get the kb index of the host running the current script.
tree_cellreplace_kb_item (lex_ctxt *lexic)
static tree_cellset_kb_item_volatile (lex_ctxt *lexic)
 Set a volatile kb item.
tree_cellset_kb_item (lex_ctxt *lexic)
 Set a kb item.
static tree_cellsecurity_something (lex_ctxt *lexic, proto_post_something_t proto_post_func, post_something_t post_func)
static unsigned char * get_notus_result_message (lex_ctxt *lexic, named_nasl_var *var)
tree_cellsecurity_notus (lex_ctxt *lexic)
tree_cellsecurity_message (lex_ctxt *lexic)
 Send a security message to the client.
tree_celllog_message (lex_ctxt *lexic)
tree_cellerror_message2 (lex_ctxt *lexic)
tree_cellnasl_get_preference (lex_ctxt *lexic)
tree_cellnasl_vendor_version (lex_ctxt *lexic)
tree_cellnasl_update_table_driven_lsc_data (lex_ctxt *lexic)
 Communicate to the parent process that LSC data is ready for use in the host kb.
static tree_cellparse_notus (advisories_t *advisories)
static tree_cellparse_skiron (advisories_t *adv)
tree_cellnasl_notus (lex_ctxt *lexic)
 Directly runs a LSC with the given package list and OS release.
tree_cellnasl_notus_type (lex_ctxt *lexic)
 Get the Notus scan type.
tree_cellnasl_notus_error (lex_ctxt *lexic)
 Get the last Notus error as string.
tree_cellnasl_scanner_get_port (lex_ctxt *lexic)
tree_cellnasl_scanner_add_port (lex_ctxt *lexic)
tree_cellnasl_scanner_status (lex_ctxt *lexic)

Variables

static int notus_type = 0
 Type of Notus scan. This is either Notus or Skiron.
static int notus_err = 0
 Error code for Notus.

Detailed Description

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.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib nasl"

GLib logging domain.

Definition at line 50 of file nasl_scanner_glue.c.

Typedef Documentation

◆ post_something_t

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 951 of file nasl_scanner_glue.c.

◆ proto_post_something_t

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 945 of file nasl_scanner_glue.c.

Function Documentation

◆ error_message2()

tree_cell * error_message2 ( lex_ctxt * lexic)

Definition at line 1179 of file nasl_scanner_glue.c.

1180{
1182}
static tree_cell * security_something(lex_ctxt *lexic, proto_post_something_t proto_post_func, post_something_t post_func)
void proto_post_error(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
Definition plugutils.c:811
void post_error(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Definition plugutils.c:818

References post_error(), proto_post_error(), and security_something().

Here is the call graph for this function:

◆ get_host_kb_index()

tree_cell * get_host_kb_index ( lex_ctxt * lexic)

Get the kb index of the host running the current script.

Parameters
[in]lexicNASL lexer.
Returns
lex cell containing the host kb index value as positive integer. NULL otherwise

Definition at line 766 of file nasl_scanner_glue.c.

767{
768 struct script_infos *script_infos = lexic->script_infos;
769 int val;
770 tree_cell *retc;
771
772 val = kb_get_kb_index (script_infos->key);
773 if (val >= 0)
774 {
776 retc->x.i_val = val;
777 }
778 else
779 return NULL;
780
781 return retc;
782}
const char * val
Definition nasl_init.c:441
tree_cell * alloc_typed_cell(int typ)
Definition nasl_tree.c:25
@ CONST_INT
Definition nasl_tree.h:79
struct TC tree_cell
long int i_val
Definition nasl_tree.h:104
union TC::@332262321161220155002104006201360276211317150140 x
struct script_infos * script_infos

References alloc_typed_cell(), CONST_INT, TC::i_val, script_infos::key, struct_lex_ctxt::script_infos, val, and TC::x.

Here is the call graph for this function:

◆ get_kb_item()

tree_cell * get_kb_item ( lex_ctxt * lexic)

Definition at line 714 of file nasl_scanner_glue.c.

715{
716 struct script_infos *script_infos = lexic->script_infos;
717
718 char *kb_entry = get_str_var_by_num (lexic, 0);
719 char *val;
720 tree_cell *retc;
721 int type = -1, single = get_int_var_by_num (lexic, 1, 0);
722 size_t len;
723
724 if (kb_entry == NULL)
725 return NULL;
726
727 val = plug_get_key (script_infos, kb_entry, &type, &len, !!single);
728
729 if (val == NULL && type == -1)
730 return NULL;
731
733 if (type == KB_TYPE_INT)
734 {
735 retc->x.i_val = GPOINTER_TO_SIZE (val);
736 g_free (val);
737 return retc;
738 }
739 else
740 {
741 retc->type = CONST_DATA;
742 if (val != NULL)
743 {
744 retc->size = len;
745 retc->x.str_val = val;
746 }
747 else
748 {
749 retc->size = 0;
750 retc->x.str_val = NULL;
751 }
752 }
753
754 return retc;
755}
char * get_str_var_by_num(lex_ctxt *, int)
Definition nasl_var.c:1108
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition nasl_var.c:1094
uint8_t len
@ CONST_DATA
Definition nasl_tree.h:82
void * plug_get_key(struct script_infos *args, char *name, int *type, size_t *len, int single)
Get values from a kb under the given key name.
Definition plugutils.c:1231
long int size
Definition nasl_tree.h:99
char * str_val
Definition nasl_tree.h:103
short type
Definition nasl_tree.h:95

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.

Here is the call graph for this function:

◆ get_kb_list()

tree_cell * get_kb_list ( lex_ctxt * lexic)

Definition at line 653 of file nasl_scanner_glue.c.

654{
655 struct script_infos *script_infos = lexic->script_infos;
656 kb_t kb = plug_get_kb (script_infos);
657 char *kb_mask = get_str_var_by_num (lexic, 0);
658 tree_cell *retc;
659 int num_elems = 0;
660 nasl_array *a;
661 struct kb_item *res, *top;
662
663 if (kb_mask == NULL)
664 {
665 nasl_perror (lexic, "get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
666 return NULL;
667 }
668
669 if (kb == NULL)
670 return NULL;
671
673 retc->x.ref_val = a = g_malloc0 (sizeof (nasl_array));
674
675 if (strchr (kb_mask, '*'))
676 top = res = kb_item_get_pattern (kb, kb_mask);
677 else
678 top = res = kb_item_get_all (kb, kb_mask);
679
680 while (res != NULL)
681 {
683 bzero (&v, sizeof (v));
684
685 if (res->type == KB_TYPE_INT)
686 {
687 v.var_type = VAR2_INT;
688 v.v.v_int = res->v_int;
689 add_var_to_array (a, res->name, &v);
690 num_elems++;
691 }
692 else if (res->type == KB_TYPE_STR)
693 {
695 v.v.v_str.s_val = (unsigned char *) res->v_str;
696 v.v.v_str.s_siz = strlen (res->v_str);
697 add_var_to_array (a, res->name, &v);
698 num_elems++;
699 }
700 res = res->next;
701 }
702
703 kb_item_free (top);
704
705 if (num_elems == 0)
706 {
707 deref_cell (retc);
708 return FAKE_CELL;
709 }
710 return retc;
711}
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition nasl_debug.c:105
void deref_cell(tree_cell *c)
Definition nasl_tree.c:178
@ DYN_ARRAY
Definition nasl_tree.h:90
#define FAKE_CELL
Definition nasl_tree.h:110
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
Definition nasl_var.c:1277
struct st_a_nasl_var anon_nasl_var
struct st_nasl_array nasl_array
@ VAR2_DATA
Definition nasl_var.h:18
@ VAR2_INT
Definition nasl_var.h:16
kb_t plug_get_kb(struct script_infos *args)
Definition plugutils.c:1157
void * ref_val
Definition nasl_tree.h:105
nasl_string_t v_str
Definition nasl_var.h:47
union st_a_nasl_var::@154137074032032170165360023270032033276061363156 v
long int v_int
Definition nasl_var.h:48
unsigned char * s_val
Definition nasl_var.h:26
long int s_siz
Definition nasl_var.h:27

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.

Here is the call graph for this function:

◆ get_notus_result_message()

unsigned char * get_notus_result_message ( lex_ctxt * lexic,
named_nasl_var * var )
static

Definition at line 1018 of file nasl_scanner_glue.c.

1019{
1020 named_nasl_var *vul_packages, *name, *version, *fixed, *fixed_version,
1021 *specifier, *start, *end;
1022 anon_nasl_var *pkg;
1023 int i;
1024 GString *result_buf, *buf;
1025
1026 vul_packages = get_var_by_name (&var->u.v.v_arr, "vulnerable_packages");
1027 if (vul_packages == NULL || vul_packages->u.var_type != VAR2_ARRAY)
1028 {
1029 nasl_perror (lexic, "security_lsc: vul_packages is not an array\n");
1030 return NULL;
1031 }
1032 result_buf = g_string_new (NULL);
1033 for (i = 0; i < vul_packages->u.v.v_arr.max_idx; i++)
1034 {
1035 pkg = nasl_get_var_by_num (lexic, &vul_packages->u.v.v_arr, i, 0);
1036 if (pkg == NULL)
1037 continue;
1038
1039 name = get_var_by_name (&pkg->v.v_arr, "name");
1040 version = get_var_by_name (&pkg->v.v_arr, "installed");
1041 fixed = get_var_by_name (&pkg->v.v_arr, "fixed");
1042 if (fixed == NULL)
1043 continue;
1044 fixed_version = get_var_by_name (&fixed->u.v.v_arr, "version");
1045 specifier = get_var_by_name (&fixed->u.v.v_arr, "specifier");
1046 start = get_var_by_name (&fixed->u.v.v_arr, "start");
1047 end = get_var_by_name (&fixed->u.v.v_arr, "end");
1048
1049 if (name == NULL || version == NULL)
1050 {
1051 continue;
1052 }
1053
1054 if (fixed_version != NULL && specifier != NULL)
1055 {
1056 buf = g_string_new (NULL);
1057 g_string_printf (buf,
1058 "\n"
1059 "Vulnerable package: %s\n"
1060 "Installed version: %s-%s\n"
1061 "Fixed version: %2s%s-%s\n",
1062 name->u.v.v_str.s_val, name->u.v.v_str.s_val,
1063 version->u.v.v_str.s_val, specifier->u.v.v_str.s_val,
1064 name->u.v.v_str.s_val,
1065 fixed_version->u.v.v_str.s_val);
1066 }
1067 else if (start != NULL && end != NULL)
1068 {
1069 buf = g_string_new (NULL);
1070 g_string_printf (buf,
1071 "\n"
1072 "Vulnerable package: %s\n"
1073 "Installed version: %s-%s\n"
1074 "Fixed version: < %s-%s\n"
1075 "Fixed version: >=%s-%s\n",
1076 name->u.v.v_str.s_val, name->u.v.v_str.s_val,
1077 version->u.v.v_str.s_val, name->u.v.v_str.s_val,
1078 start->u.v.v_str.s_val, name->u.v.v_str.s_val,
1079 end->u.v.v_str.s_val);
1080 }
1081 else
1082 {
1083 continue;
1084 }
1085 g_string_append (result_buf, buf->str);
1086 g_string_free (buf, TRUE);
1087 }
1088 return (unsigned char *) result_buf->str;
1089}
const char * name
Definition nasl_init.c:440
named_nasl_var * get_var_by_name(nasl_array *a, const char *s)
Definition nasl_var.c:75
anon_nasl_var * nasl_get_var_by_num(void *ctxt, nasl_array *a, int num, int create)
Definition nasl_var.c:43
@ VAR2_ARRAY
Definition nasl_var.h:19
struct st_n_nasl_var named_nasl_var
Fixed version.
nasl_array v_arr
Definition nasl_var.h:49
struct st_a_nasl_var u
Definition nasl_var.h:56

References get_var_by_name(), st_nasl_array::max_idx, name, nasl_get_var_by_num(), nasl_perror(), st_nasl_string::s_val, st_n_nasl_var::u, st_a_nasl_var::v, st_a_nasl_var::v_arr, st_a_nasl_var::v_str, VAR2_ARRAY, and st_a_nasl_var::var_type.

Referenced by security_notus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_script_oid()

tree_cell * get_script_oid ( lex_ctxt * lexic)

Return the OID of the current script.

Parameters
[in]lexicNASL lexer.
Returns
lex cell containing the OID as a string.

Definition at line 635 of file nasl_scanner_glue.c.

636{
637 const char *oid = lexic->oid;
638 tree_cell *retc = NULL;
639
640 if (oid)
641 {
643 retc->x.str_val = g_strdup (oid);
644 retc->size = strlen (oid);
645 }
646
647 return retc;
648}
const char * oid
const char * oid

References alloc_typed_cell(), CONST_DATA, oid, struct_lex_ctxt::oid, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ isalldigit()

int isalldigit ( char * str,
int len )
static

Definition at line 55 of file nasl_scanner_glue.c.

56{
57 int i;
58 char buf[1024];
59 for (i = 0; i < len; i++)
60 {
61 if (!isdigit (str[i]))
62 return 0;
63 }
64
65 snprintf (buf, sizeof (buf), "%d", atoi (str));
66 if (strcmp (buf, str) != 0)
67 return 0;
68 else
69 return 1;
70}

References len.

Referenced by script_get_preference().

Here is the caller graph for this function:

◆ log_message()

tree_cell * log_message ( lex_ctxt * lexic)

Definition at line 1171 of file nasl_scanner_glue.c.

1172{
1174}
void proto_post_log(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
Post a log message.
Definition plugutils.c:784
void post_log_with_uri(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Post a log message about a tcp port with a uri.
Definition plugutils.c:804

References post_log_with_uri(), proto_post_log(), and security_something().

Here is the call graph for this function:

◆ nasl_get_preference()

tree_cell * nasl_get_preference ( lex_ctxt * lexic)

Definition at line 1185 of file nasl_scanner_glue.c.

1186{
1187 tree_cell *retc;
1188 char *name;
1189 const char *value;
1190
1191 name = get_str_var_by_num (lexic, 0);
1192 if (name == NULL)
1193 {
1194 nasl_perror (lexic, "get_preference: no name\n");
1195 return NULL;
1196 }
1197 value = prefs_get (name);
1198 if (value == NULL)
1199 return NULL;
1200
1202 retc->x.str_val = strdup (value);
1203 retc->size = strlen (value);
1204 return retc;
1205}

References alloc_typed_cell(), CONST_DATA, get_str_var_by_num(), name, nasl_perror(), TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ nasl_notus()

tree_cell * nasl_notus ( lex_ctxt * lexic)

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. As there are currently 2 types of LSC scanner, with different result formats, the result depends on the used scanner type. In case of Notus it returns a list of 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 case of Skiron, it returns a dictionary with the OIDs and corresponding result messages.

NASL Function: notus\n
NASL Named Parameters:\n
  • pkg_list String containing the gathered package list.
  • product The OS release.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
List of Notus results in a JSON-like format, NULL on error.

Definition at line 1444 of file nasl_scanner_glue.c.

1445{
1446 char *response;
1447 advisories_t *advisories = NULL;
1448 char *pkg_list = get_str_var_by_name (lexic, "pkg_list");
1449 char *product = get_str_var_by_name (lexic, "product");
1450
1451 notus_err = 0;
1452
1453 if (product == NULL || pkg_list == NULL)
1454 {
1455 g_warning ("%s: Missing data for running LSC", __func__);
1456 notus_err = -1;
1457 return NULL;
1458 }
1459
1460 response = lsc_get_response (pkg_list, product);
1461
1462 if (!response)
1463 {
1464 g_warning ("%s: Unable to get the response", __func__);
1465 notus_err = -2;
1466
1467 return NULL;
1468 }
1469
1470 advisories = lsc_process_response (response, strlen (response));
1471 g_free (response);
1472
1473 if (!advisories)
1474 {
1475 g_warning ("%s: Unable to process the response", __func__);
1476 notus_err = -4;
1477
1478 return NULL;
1479 }
1480
1482
1483 if (notus_type == NOTUS)
1484 // TODO: Remove notus, when it is deprecated
1485 return parse_notus (advisories);
1486 else
1487 return parse_skiron (advisories);
1488}
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1118
static int notus_err
Error code for Notus.
static tree_cell * parse_skiron(advisories_t *adv)
static tree_cell * parse_notus(advisories_t *advisories)
static int notus_type
Type of Notus scan. This is either Notus or Skiron.
advisory_type_t type
char * lsc_get_response(const char *pkg_list, const char *os)
Sent the installed package list and OS to notus.
advisories_t * lsc_process_response(const gchar *resp, const size_t len)
Process a json object which contains advisories and vulnerable packages.
struct advisories advisories_t
@ NOTUS

References get_str_var_by_name(), lsc_get_response(), lsc_process_response(), NOTUS, notus_err, notus_type, parse_notus(), parse_skiron(), and advisories::type.

Here is the call graph for this function:

◆ nasl_notus_error()

tree_cell * nasl_notus_error ( lex_ctxt * lexic)

Get the last Notus error as string.

NASL Function: notus_error\n
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
Error message as a string.

Definition at line 1523 of file nasl_scanner_glue.c.

1524{
1525 tree_cell *retc;
1526 char *notus_err_str;
1527 (void) lexic;
1528
1529 switch (notus_err)
1530 {
1531 case -1:
1532 notus_err_str = strdup ("Missing data for running LSC");
1533 break;
1534 case -2:
1535 notus_err_str = strdup ("Unable to get the response");
1536 break;
1537 case -3:
1538 notus_err_str = strdup ("Unknown fixed version type for advisory");
1539 break;
1540 case -4:
1541 notus_err_str = strdup ("Unable to process the response");
1542 break;
1543 default:
1544 return NULL;
1545 }
1546
1547 retc = alloc_typed_cell (CONST_STR);
1548 retc->x.str_val = notus_err_str;
1549 retc->size = strlen (notus_err_str);
1550
1551 return retc;
1552}
@ CONST_STR
Definition nasl_tree.h:80

References alloc_typed_cell(), CONST_STR, notus_err, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ nasl_notus_type()

tree_cell * nasl_notus_type ( lex_ctxt * lexic)

Get the Notus scan type.

0 for Notus, 1 for Skiron.

NASL Function: notus_type\n
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
Scan type as integer.

Definition at line 1502 of file nasl_scanner_glue.c.

1503{
1504 tree_cell *retc;
1505 (void) lexic;
1506
1507 retc = alloc_typed_cell (CONST_INT);
1508 retc->x.i_val = (int) notus_type;
1509 return retc;
1510}

References alloc_typed_cell(), CONST_INT, TC::i_val, notus_type, and TC::x.

Here is the call graph for this function:

◆ nasl_scanner_add_port()

tree_cell * nasl_scanner_add_port ( lex_ctxt * lexic)

Definition at line 1601 of file nasl_scanner_glue.c.

1602{
1603 struct script_infos *script_infos = lexic->script_infos;
1604
1605 int port = get_int_var_by_name (lexic, "port", -1);
1606 char *proto = get_str_var_by_name (lexic, "proto");
1607
1608 if (port >= 0)
1609 {
1610 scanner_add_port (script_infos, port, proto ? proto : "tcp");
1611 }
1612
1613 return FAKE_CELL;
1614}
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition nasl_var.c:1101
void scanner_add_port(struct script_infos *args, int port, char *proto)
Definition plugutils.c:1151

References FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), scanner_add_port(), and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ nasl_scanner_get_port()

tree_cell * nasl_scanner_get_port ( lex_ctxt * lexic)

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 1561 of file nasl_scanner_glue.c.

1562{
1563 tree_cell *retc;
1564 int idx = get_int_var_by_num (lexic, 0, -1);
1565 const char *prange = prefs_get ("port_range");
1566 static int num = 0;
1567 static u_short *ports = NULL;
1568
1569 if (prange == NULL)
1570 return NULL;
1571
1572 if (idx < 0)
1573 {
1574 nasl_perror (lexic, "Argument error in scanner_get_port()\n");
1575 nasl_perror (lexic, "Correct usage is : num = scanner_get_port(<num>)\n");
1576 nasl_perror (lexic,
1577 "Where <num> should be 0 the first time you call it\n");
1578 return NULL;
1579 }
1580
1581 if (ports == NULL)
1582 {
1583 ports = (u_short *) getpts ((char *) prange, &num);
1584 if (ports == NULL)
1585 {
1586 return NULL;
1587 }
1588 }
1589
1590 if (idx >= num)
1591 {
1592 return NULL;
1593 }
1594
1595 retc = alloc_typed_cell (CONST_INT);
1596 retc->x.i_val = ports[idx];
1597 return retc;
1598}
unsigned short * getpts(char *origexpr, int *len)
Converts a string like "-100,200-1024,3000-4000,60000-" into an array.
Definition network.c:2296

References alloc_typed_cell(), CONST_INT, get_int_var_by_num(), getpts(), TC::i_val, nasl_perror(), and TC::x.

Here is the call graph for this function:

◆ nasl_scanner_status()

tree_cell * nasl_scanner_status ( lex_ctxt * lexic)

Definition at line 1617 of file nasl_scanner_glue.c.

1618{
1619 /* Kept for backward compatibility. */
1620 (void) lexic;
1621 return FAKE_CELL;
1622}

References FAKE_CELL.

◆ nasl_update_table_driven_lsc_data()

tree_cell * nasl_update_table_driven_lsc_data ( lex_ctxt * lexic)

Communicate to the parent process that LSC data is ready for use in the host kb.

NASL Function: update_table_driven_lsc_data\n
NASL Named Parameters:\n
  • pkg_list String containing the gathered package list.
  • os_release The OS release.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
NULL

Definition at line 1236 of file nasl_scanner_glue.c.

1237{
1238 struct script_infos *script_infos = lexic->script_infos;
1239 ipc_data_t *lsc = NULL;
1240 const char *json = NULL;
1241 gchar *pkg_list = get_str_var_by_name (lexic, "pkg_list");
1242 gchar *os_version = get_str_var_by_name (lexic, "os_release");
1243
1244 if (os_version == NULL || pkg_list == NULL)
1245 {
1246 g_warning ("%s: Missing data for running LSC", __func__);
1247 return NULL;
1248 }
1249
1250 plug_set_key (script_infos, "ssh/login/package_list_notus", ARG_STRING,
1251 pkg_list);
1252 plug_set_key (script_infos, "ssh/login/release_notus", ARG_STRING,
1253 os_version);
1254
1255 lsc = ipc_data_type_from_lsc (TRUE);
1256 if (!lsc)
1257 return NULL;
1258
1259 json = ipc_data_to_json (lsc);
1260 ipc_data_destroy (&lsc);
1261 if (ipc_send (lexic->script_infos->ipc_context, IPC_MAIN, json, strlen (json))
1262 < 0)
1263 g_warning ("Unable to send the package list for LSC to the host process");
1264
1265 g_free ((void *) json);
1266 return NULL;
1267}
int ipc_send(struct ipc_context *context, enum ipc_relation to, const char *msg, size_t len)
sends given msg to the target based on the given context
Definition ipc.c:46
@ IPC_MAIN
Definition ipc.h:18
void ipc_data_destroy(ipc_data_t **data)
destroys ipc_data.
ipc_data_t * ipc_data_type_from_lsc(gboolean data_ready)
initializes ipc_data for the table driven LSC.
const char * ipc_data_to_json(ipc_data_t *data)
transforms ipc_data to a json string
struct ipc_data ipc_data_t
Definition ipc_openvas.h:23
void plug_set_key(struct script_infos *args, char *name, int type, const void *value)
Definition plugutils.c:1060
#define ARG_STRING
Definition plugutils.h:19
struct ipc_context * ipc_context
Definition scanneraux.h:31

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.

Here is the call graph for this function:

◆ nasl_vendor_version()

tree_cell * nasl_vendor_version ( lex_ctxt * lexic)

Definition at line 1208 of file nasl_scanner_glue.c.

1209{
1210 tree_cell *retc;
1211 gchar *version = g_strdup (vendor_version_get ());
1212 (void) lexic;
1214 retc->x.str_val = strdup (version);
1215 retc->size = strlen (version);
1216 g_free (version);
1217
1218 return retc;
1219}
const gchar * vendor_version_get()
Get vendor version.

References alloc_typed_cell(), CONST_DATA, TC::size, TC::str_val, vendor_version_get(), and TC::x.

Here is the call graph for this function:

◆ parse_notus()

tree_cell * parse_notus ( advisories_t * advisories)
static

Definition at line 1277 of file nasl_scanner_glue.c.

1278{
1279 tree_cell *retc;
1280 anon_nasl_var element;
1281
1282 retc = alloc_typed_cell (DYN_ARRAY);
1283 retc->x.ref_val = g_malloc0 (sizeof (nasl_array));
1284
1285 // Process the advisories, generate results and store them in the kb
1286 for (size_t i = 0; i < advisories->count; i++)
1287 {
1288 advisory_t *advisory = advisories->advisories[i];
1289 anon_nasl_var vulnerable_pkgs, oid;
1290
1291 memset (&element, 0, sizeof (element));
1292 element.var_type = VAR2_ARRAY;
1293
1294 memset (&vulnerable_pkgs, 0, sizeof (vulnerable_pkgs));
1295 vulnerable_pkgs.var_type = VAR2_ARRAY;
1296
1297 memset (&oid, 0, sizeof (oid));
1298 oid.var_type = VAR2_STRING;
1299 oid.v.v_str.s_val = (unsigned char *) advisory->oid;
1300 oid.v.v_str.s_siz = strlen (advisory->oid);
1301
1302 for (size_t j = 0; j < advisory->count; j++)
1303 {
1304 vuln_pkg_t *pkg = advisory->pkgs[j];
1305 anon_nasl_var name, installed, vul_pkg;
1306 memset (&name, 0, sizeof (name));
1307 memset (&installed, 0, sizeof (installed));
1308 memset (&vul_pkg, 0, sizeof (vul_pkg));
1309 name.var_type = VAR2_STRING;
1310 installed.var_type = VAR2_STRING;
1311 vul_pkg.var_type = VAR2_ARRAY;
1312 name.v.v_str.s_val = (unsigned char *) pkg->pkg_name;
1313 name.v.v_str.s_siz = strlen (pkg->pkg_name);
1314 installed.v.v_str.s_val = (unsigned char *) pkg->install_version;
1315 installed.v.v_str.s_siz = strlen (pkg->install_version);
1316
1317 if (pkg->type == RANGE)
1318 {
1319 anon_nasl_var range, start, end;
1320 memset (&range, 0, sizeof (range));
1321 range.var_type = VAR2_ARRAY;
1322
1323 memset (&start, 0, sizeof (start));
1324 start.var_type = VAR2_STRING;
1325 start.v.v_str.s_val = (unsigned char *) pkg->range->start;
1326 start.v.v_str.s_siz = strlen (pkg->range->start);
1327 add_var_to_array (&range.v.v_arr, "start", &start);
1328
1329 memset (&end, 0, sizeof (end));
1330 end.var_type = VAR2_STRING;
1331 end.v.v_str.s_val = (unsigned char *) pkg->range->stop;
1332 end.v.v_str.s_siz = strlen (pkg->range->stop);
1333 add_var_to_array (&range.v.v_arr, "end", &end);
1334 add_var_to_array (&vul_pkg.v.v_arr, "fixed", &range);
1335 }
1336 else if (pkg->type == SINGLE)
1337 {
1338 anon_nasl_var single, version, specifier;
1339
1340 memset (&single, 0, sizeof (single));
1341 single.var_type = VAR2_ARRAY;
1342
1343 memset (&version, 0, sizeof (version));
1344 version.var_type = VAR2_STRING;
1345 version.v.v_str.s_val = (unsigned char *) pkg->version->version;
1346 version.v.v_str.s_siz = strlen (pkg->version->version);
1347 add_var_to_array (&single.v.v_arr, "version", &version);
1348
1349 memset (&specifier, 0, sizeof (specifier));
1350 specifier.var_type = VAR2_STRING;
1351 specifier.v.v_str.s_val =
1352 (unsigned char *) pkg->version->specifier;
1353 specifier.v.v_str.s_siz = strlen (pkg->version->specifier);
1354 add_var_to_array (&single.v.v_arr, "specifier", &specifier);
1355
1356 add_var_to_array (&vul_pkg.v.v_arr, "fixed", &single);
1357 }
1358 else
1359 {
1360 g_warning ("%s: Unknown fixed version type for advisory %s",
1361 __func__, advisory->oid);
1363 notus_err = -3;
1364 deref_cell (retc);
1365
1366 return NULL;
1367 }
1368 add_var_to_array (&vul_pkg.v.v_arr, "name", &name);
1369 add_var_to_array (&vul_pkg.v.v_arr, "installed", &installed);
1370 add_var_to_list (&vulnerable_pkgs.v.v_arr, j, &vul_pkg);
1371 }
1372
1373 add_var_to_array (&element.v.v_arr, "oid", &oid);
1374 add_var_to_array (&element.v.v_arr, "vulnerable_packages",
1375 &vulnerable_pkgs);
1376 add_var_to_list (retc->x.ref_val, i, &element);
1377 }
1378
1380
1381 return retc;
1382}
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition nasl_var.c:1245
@ VAR2_STRING
Definition nasl_var.h:17
advisory_t ** advisories
vuln_pkg_t * pkgs[100]
fixed_version_t * version
enum fixed_type type
version_range_t * range
void advisories_free(advisories_t *advisories)
Free()'s an advisories.
@ SINGLE
@ RANGE
struct notus_advisory advisory_t
struct vulnerable_pkg vuln_pkg_t

References add_var_to_array(), add_var_to_list(), advisories::advisories, advisories_free(), alloc_typed_cell(), advisories::count, notus_advisory::count, deref_cell(), DYN_ARRAY, vulnerable_pkg::install_version, name, notus_err, notus_advisory::oid, oid, vulnerable_pkg::pkg_name, notus_advisory::pkgs, 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.

Referenced by nasl_notus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_skiron()

tree_cell * parse_skiron ( advisories_t * adv)
static

Definition at line 1385 of file nasl_scanner_glue.c.

1386{
1387 tree_cell *retc;
1388 anon_nasl_var element;
1389
1390 retc = alloc_typed_cell (DYN_ARRAY);
1391 retc->x.ref_val = g_malloc0 (sizeof (nasl_array));
1392
1393 for (size_t i = 0; i < adv->count; i++)
1394 {
1395 skiron_advisory_t *advisory = adv->skiron_advisories[i];
1396 anon_nasl_var msg, oid;
1397
1398 memset (&element, 0, sizeof (element));
1399 element.var_type = VAR2_ARRAY;
1400
1401 memset (&msg, 0, sizeof (msg));
1402 msg.var_type = VAR2_STRING;
1403 msg.v.v_str.s_val = (unsigned char *) advisory->message;
1404 msg.v.v_str.s_siz = strlen (advisory->message);
1405
1406 memset (&oid, 0, sizeof (oid));
1407 oid.var_type = VAR2_STRING;
1408 oid.v.v_str.s_val = (unsigned char *) advisory->oid;
1409 oid.v.v_str.s_siz = strlen (advisory->oid);
1410
1411 add_var_to_array (&element.v.v_arr, "oid", &oid);
1412 add_var_to_array (&element.v.v_arr, "message", &msg);
1413 add_var_to_list (retc->x.ref_val, i, &element);
1414 }
1415 advisories_free (adv);
1416
1417 return retc;
1418}
skiron_advisory_t ** skiron_advisories
struct skiron_advisory skiron_advisory_t

References add_var_to_array(), add_var_to_list(), advisories_free(), alloc_typed_cell(), advisories::count, DYN_ARRAY, skiron_advisory::message, oid, skiron_advisory::oid, TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, advisories::skiron_advisories, 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, and TC::x.

Referenced by nasl_notus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace_kb_item()

tree_cell * replace_kb_item ( lex_ctxt * lexic)

Definition at line 785 of file nasl_scanner_glue.c.

786{
787 struct script_infos *script_infos = lexic->script_infos;
788 char *name = get_str_var_by_name (lexic, "name");
789 int type = get_var_type_by_name (lexic, "value");
790
791 if (name == NULL)
792 {
793 nasl_perror (lexic, "Syntax error with replace_kb_item() [null name]\n",
794 name);
795 return FAKE_CELL;
796 }
797
798 if (type == VAR2_INT)
799 {
800 int value = get_int_var_by_name (lexic, "value", -1);
801 if (value != -1)
803 GSIZE_TO_POINTER (value));
804 else
806 lexic, "Syntax error with replace_kb_item(%s) [value=-1]\n", name);
807 }
808 else
809 {
810 char *value = get_str_var_by_name (lexic, "value");
811 size_t len = get_var_size_by_name (lexic, "value");
812
813 if (value == NULL)
814 {
815 nasl_perror (lexic,
816 "Syntax error with replace_kb_item(%s) [null value]\n",
817 name);
818 return FAKE_CELL;
819 }
821 }
822
823 return FAKE_CELL;
824}
int get_var_type_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1162
long int get_var_size_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1138
void plug_replace_key_len(struct script_infos *args, char *name, int type, void *value, size_t len)
Definition plugutils.c:1118
void plug_replace_key(struct script_infos *args, char *name, int type, void *value)
Definition plugutils.c:1145
#define ARG_INT
Definition plugutils.h:20

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.

Here is the call graph for this function:

◆ safe_checks()

tree_cell * safe_checks ( lex_ctxt * lexic)

Definition at line 617 of file nasl_scanner_glue.c.

618{
619 (void) lexic;
621
622 retc->x.i_val = prefs_get_bool ("safe_checks");
623
624 return retc;
625}

References alloc_typed_cell(), CONST_INT, TC::i_val, and TC::x.

Referenced by plugin_run_openvas_tcp_scanner().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ script_add_preference()

tree_cell * script_add_preference ( lex_ctxt * lexic)

Definition at line 440 of file nasl_scanner_glue.c.

441{
442 int id = get_int_var_by_name (lexic, "id", -1);
443 char *name = get_str_var_by_name (lexic, "name");
444 char *type = get_str_var_by_name (lexic, "type");
445 char *value = get_str_var_by_name (lexic, "value");
446 struct script_infos *script_infos = lexic->script_infos;
447 nvtpref_t *np;
448 unsigned int i;
449
450 if (!script_infos->nvti)
451 return FAKE_CELL;
452 if (id < 0)
453 id = nvti_pref_len (script_infos->nvti) + 1;
454 if (id == 0)
455 {
456 nasl_perror (lexic,
457 "Invalid id or not allowed id value in the call to %s()\n",
458 __func__);
459 return FAKE_CELL;
460 }
461 if (!name || !type || !value)
462 {
463 nasl_perror (lexic,
464 "Argument error in the call to script_add_preference()\n");
465 return FAKE_CELL;
466 }
467 for (i = 0; i < nvti_pref_len (script_infos->nvti); i++)
468 {
469 if (!strcmp (name, nvtpref_name (nvti_pref (script_infos->nvti, i))))
470 {
471 nasl_perror (lexic, "Preference '%s' already exists\n", name);
472 return FAKE_CELL;
473 }
474 if (id == nvtpref_id (nvti_pref (script_infos->nvti, i)))
475 {
476 nasl_perror (lexic, "Invalid or already existent preference id\n");
477 return FAKE_CELL;
478 }
479 }
480
481 np = nvtpref_new (id, name, type, value);
482 nvti_add_pref (script_infos->nvti, np);
483 return FAKE_CELL;
484}
nvti_t * nvti
Definition scanneraux.h:33

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.

Here is the call graph for this function:

◆ script_category()

tree_cell * script_category ( lex_ctxt * lexic)

Definition at line 260 of file nasl_scanner_glue.c.

261{
262 struct script_infos *script_infos = lexic->script_infos;
263
264 int category = get_int_var_by_num (lexic, 0, -1);
265
266 if (category < 0)
267 {
268 nasl_perror (lexic, "Argument error in function script_category()\n");
269 nasl_perror (lexic, "Function usage is : script_category(<category>)\n");
270 return FAKE_CELL;
271 }
272 nvti_set_category (script_infos->nvti, category);
273 return FAKE_CELL;
274}

References FAKE_CELL, get_int_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_copyright()

tree_cell * script_copyright ( lex_ctxt * lexic)

Definition at line 253 of file nasl_scanner_glue.c.

254{
255 (void) lexic;
256 return FAKE_CELL;
257}

References FAKE_CELL.

◆ script_cve_id()

tree_cell * script_cve_id ( lex_ctxt * lexic)

Definition at line 117 of file nasl_scanner_glue.c.

118{
119 struct script_infos *script_infos = lexic->script_infos;
120 char *cve = get_str_var_by_num (lexic, 0);
121 int i;
122
123 for (i = 0; cve != NULL; i++)
124 {
125 nvti_add_vtref (script_infos->nvti, vtref_new ("cve", cve, ""));
126 cve = get_str_var_by_num (lexic, i + 1);
127 }
128
129 return FAKE_CELL;
130}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_dependencies()

tree_cell * script_dependencies ( lex_ctxt * lexic)

Definition at line 284 of file nasl_scanner_glue.c.

285{
286 struct script_infos *script_infos = lexic->script_infos;
287 char *dep = get_str_var_by_num (lexic, 0);
288 int i;
289
290 if (dep == NULL)
291 {
292 nasl_perror (lexic, "Argument error in function script_dependencies()\n");
293 nasl_perror (lexic, "Function usage is : script_dependencies(<name>)\n");
294 nasl_perror (lexic, "Where <name> is the name of another script\n");
295
296 return FAKE_CELL;
297 }
298
299 for (i = 0; dep != NULL; i++)
300 {
301 dep = get_str_var_by_num (lexic, i);
302 if (dep != NULL)
304 }
305
306 return FAKE_CELL;
307}
void plug_set_dep(struct script_infos *args, const char *depname)
Definition plugutils.c:104

References FAKE_CELL, get_str_var_by_num(), nasl_perror(), plug_set_dep(), and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_exclude_keys()

tree_cell * script_exclude_keys ( lex_ctxt * lexic)

Definition at line 381 of file nasl_scanner_glue.c.

382{
383 char *keys = get_str_var_by_num (lexic, 0);
384 int i;
385
386 if (keys == NULL)
387 {
388 nasl_perror (lexic, "Argument error in function script_exclude_keys()\n");
389 nasl_perror (lexic, "Function usage is : script_exclude_keys(<name>)\n");
390 nasl_perror (lexic, "Where <name> is the name of a key\n");
391 return FAKE_CELL;
392 }
393
394 for (i = 0; keys != NULL; i++)
395 {
396 keys = get_str_var_by_num (lexic, i);
397 nvti_add_excluded_keys (lexic->script_infos->nvti, keys);
398 }
399
400 return FAKE_CELL;
401}

References FAKE_CELL, get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_family()

tree_cell * script_family ( lex_ctxt * lexic)

Definition at line 277 of file nasl_scanner_glue.c.

278{
279 nvti_set_family (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
280 return FAKE_CELL;
281}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_get_preference()

tree_cell * script_get_preference ( lex_ctxt * lexic)

Get a preferences of the current script.

Search the preference by preference name or by preferences id.

Parameters
[in]lexicNASL lexer.
Returns
lex cell containing the preferences value as a string. Fake cell otherwise

Definition at line 497 of file nasl_scanner_glue.c.

498{
499 tree_cell *retc;
500 int id = get_int_var_by_name (lexic, "id", -1);
501 char *pref = get_str_var_by_num (lexic, 0);
502 char *value;
503
504 if (pref == NULL && id == -1)
505 {
506 nasl_perror (lexic,
507 "Argument error in the function script_get_preference()\n");
508 nasl_perror (lexic,
509 "Function usage is : pref = script_get_preference(<name>, "
510 "id:<id>)\n");
511 return FAKE_CELL;
512 }
513
514 value = get_plugin_preference (lexic->oid, pref, id);
515 if (value != NULL)
516 {
518 if (isalldigit (value, strlen (value)))
519 retc->x.i_val = atoi (value);
520 else
521 {
522 retc->type = CONST_DATA;
523 retc->size = strlen (value);
524 retc->x.str_val = g_strdup (value);
525 }
526 g_free (value);
527 return retc;
528 }
529 else
530 return FAKE_CELL;
531}
static int isalldigit(char *str, int len)
char * get_plugin_preference(const char *oid, const char *name, int pref_id)
Get the a plugins preference.
Definition plugutils.c:837

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.

Here is the call graph for this function:

◆ script_get_preference_file_content()

tree_cell * script_get_preference_file_content ( lex_ctxt * lexic)

Definition at line 534 of file nasl_scanner_glue.c.

535{
536 struct script_infos *script_infos = lexic->script_infos;
537 tree_cell *retc;
538 char *pref = get_str_var_by_num (lexic, 0);
539 char *value;
540 char *content;
541 int contentsize = 0;
542
543 if (pref == NULL)
544 {
545 nasl_perror (lexic,
546 "Argument error in the function script_get_preference()\n");
547 nasl_perror (lexic, "Function usage is : pref = "
548 "script_get_preference_file_content(<name>)\n");
549 return NULL;
550 }
551
552 value = get_plugin_preference (lexic->oid, pref, -1);
553 if (value == NULL)
554 return NULL;
555
557 contentsize = get_plugin_preference_file_size (script_infos, value);
558 g_free (value);
559 if (content == NULL)
560 return FAKE_CELL;
561 if (contentsize <= 0)
562 {
563 nasl_perror (lexic,
564 "script_get_preference_file_content: could not get "
565 " size of file from preference %s\n",
566 pref);
567 return NULL;
568 }
569
571 retc->size = contentsize;
572 retc->x.str_val = content;
573
574 return retc;
575}
char * get_plugin_preference_file_content(struct script_infos *desc, const char *identifier)
Get the file contents of a plugins preference that is of type "file".
Definition plugutils.c:980
long get_plugin_preference_file_size(struct script_infos *desc, const char *identifier)
Get the file size of a plugins preference that is of type "file".
Definition plugutils.c:1011

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.

Here is the call graph for this function:

◆ script_get_preference_file_location()

tree_cell * script_get_preference_file_location ( lex_ctxt * lexic)

Definition at line 578 of file nasl_scanner_glue.c.

579{
580 struct script_infos *script_infos = lexic->script_infos;
581 tree_cell *retc;
582 char *pref = get_str_var_by_num (lexic, 0);
583 const char *value, *local;
584 int len;
585
586 if (pref == NULL)
587 {
589 lexic, "script_get_preference_file_location: no preference name!\n");
590 return NULL;
591 }
592
593 value = get_plugin_preference (lexic->oid, pref, -1);
594 if (value == NULL)
595 {
597 lexic,
598 "script_get_preference_file_location: could not get preference %s\n",
599 pref);
600 return NULL;
601 }
603 if (local == NULL)
604 return NULL;
605
606 len = strlen (local);
608 retc->size = len;
609 retc->x.str_val = g_malloc0 (len + 1);
610 memcpy (retc->x.str_val, local, len + 1);
611
612 return retc;
613}
const char * get_plugin_preference_fname(struct script_infos *desc, const char *filename)
Get the file name of a plugins preference that is of type "file".
Definition plugutils.c:925

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.

Here is the call graph for this function:

◆ script_mandatory_keys()

tree_cell * script_mandatory_keys ( lex_ctxt * lexic)

Definition at line 334 of file nasl_scanner_glue.c.

335{
336 char *keys = get_str_var_by_num (lexic, 0);
337 char **splits = NULL, *re = get_str_var_by_name (lexic, "re");
338 int i;
339
340 if (keys == NULL)
341 {
342 nasl_perror (lexic,
343 "Argument error in function script_mandatory_keys()\n");
344 nasl_perror (lexic, "Function usage is: script_mandatory_keys(<name>... "
345 "[, re: '<name>=<regex>'])\n");
346 nasl_perror (lexic, "Where <name> is the name of a key and <regex> is a "
347 "regular expression for a value of a key.\n");
348 return FAKE_CELL;
349 }
350
351 if (re)
352 {
353 splits = g_strsplit (re, "=", 0);
354
355 if (!splits[0] || !splits[1] || !*splits[1] || splits[2])
356 {
357 nasl_perror (lexic, "Erroneous re argument");
358 return FAKE_CELL;
359 }
360 }
361 for (i = 0; keys != NULL; i++)
362 {
363 keys = get_str_var_by_num (lexic, i);
364
365 if (splits && keys && !strcmp (keys, splits[0]))
366 {
367 nvti_add_mandatory_keys (lexic->script_infos->nvti, re);
368 re = NULL;
369 }
370 else
371 nvti_add_mandatory_keys (lexic->script_infos->nvti, keys);
372 }
373 if (re)
374 nvti_add_mandatory_keys (lexic->script_infos->nvti, re);
375
376 g_strfreev (splits);
377 return FAKE_CELL;
378}

References FAKE_CELL, get_str_var_by_name(), get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_name()

tree_cell * script_name ( lex_ctxt * lexic)

Definition at line 239 of file nasl_scanner_glue.c.

240{
241 nvti_set_name (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
242 return FAKE_CELL;
243}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Referenced by nasl_perror(), and nasl_trace().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ script_oid()

tree_cell * script_oid ( lex_ctxt * lexic)

Definition at line 110 of file nasl_scanner_glue.c.

111{
112 nvti_set_oid (lexic->script_infos->nvti, get_str_var_by_num (lexic, 0));
113 return FAKE_CELL;
114}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_require_keys()

tree_cell * script_require_keys ( lex_ctxt * lexic)

Definition at line 310 of file nasl_scanner_glue.c.

311{
312 char *keys = get_str_var_by_num (lexic, 0);
313 int i;
314
315 if (keys == NULL)
316 {
317 nasl_perror (lexic, "Argument error in function script_require_keys()\n");
318 nasl_perror (lexic,
319 "Function usage is : script_require_keys(<name>...)\n");
320 nasl_perror (lexic, "Where <name> is the name of a key\n");
321 return FAKE_CELL;
322 }
323
324 for (i = 0; keys != NULL; i++)
325 {
326 keys = get_str_var_by_num (lexic, i);
327 nvti_add_required_keys (lexic->script_infos->nvti, keys);
328 }
329
330 return FAKE_CELL;
331}

References FAKE_CELL, get_str_var_by_num(), nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_require_ports()

tree_cell * script_require_ports ( lex_ctxt * lexic)

Definition at line 404 of file nasl_scanner_glue.c.

405{
406 char *port;
407 int i;
408
409 for (i = 0;; i++)
410 {
411 port = get_str_var_by_num (lexic, i);
412 if (port != NULL)
413 nvti_add_required_ports (lexic->script_infos->nvti, port);
414 else
415 break;
416 }
417
418 return FAKE_CELL;
419}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_require_udp_ports()

tree_cell * script_require_udp_ports ( lex_ctxt * lexic)

Definition at line 422 of file nasl_scanner_glue.c.

423{
424 int i;
425 char *port;
426
427 for (i = 0;; i++)
428 {
429 port = get_str_var_by_num (lexic, i);
430 if (port != NULL)
431 nvti_add_required_udp_ports (lexic->script_infos->nvti, port);
432 else
433 break;
434 }
435
436 return FAKE_CELL;
437}

References FAKE_CELL, get_str_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_tag()

tree_cell * script_tag ( lex_ctxt * lexic)

Definition at line 199 of file nasl_scanner_glue.c.

200{
201 struct script_infos *script_infos = lexic->script_infos;
202 char *name = get_str_var_by_name (lexic, "name");
203 char *value = get_str_var_by_name (lexic, "value");
204
205 if (value == NULL || name == NULL)
206 {
207 nasl_perror (lexic, "script_tag() syntax error - should be"
208 " script_tag(name:<name>, value:<value>)\n");
209 if (name == NULL)
210 {
211 nasl_perror (lexic, " <name> is empty\n");
212 }
213 else
214 {
215 nasl_perror (lexic, " <name> is %s\n", name);
216 }
217 if (value == NULL)
218 {
219 nasl_perror (lexic, " <value> is empty)\n");
220 }
221 else
222 {
223 nasl_perror (lexic, " <value> is %s\n)", value);
224 }
225 return FAKE_CELL;
226 }
227
228 if (strchr (value, '|'))
229 {
230 nasl_perror (lexic, "%s tag contains | separator", name);
231 return FAKE_CELL;
232 }
233 nvti_add_tag (script_infos->nvti, name, value);
234
235 return FAKE_CELL;
236}

References FAKE_CELL, get_str_var_by_name(), name, nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_timeout()

tree_cell * script_timeout ( lex_ctxt * lexic)

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.

Parameters
[in]lexiclexic
[in]toscript timeout
Returns
FAKE_CELL

Definition at line 92 of file nasl_scanner_glue.c.

93{
94 nvti_t *nvti = lexic->script_infos->nvti;
95 int to = get_int_var_by_num (lexic, 0, -65535);
96 nvtpref_t *np;
97 gchar *timeout;
98
99 if (to == -65535)
100 return FAKE_CELL;
101
102 timeout = g_strdup_printf ("%d", to);
103
104 np = nvtpref_new (NVTPREF_TIMEOUT_ID, "timeout", "entry", timeout);
105 nvti_add_pref (nvti, np);
106 return FAKE_CELL;
107}

References FAKE_CELL, get_int_var_by_num(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ script_version()

tree_cell * script_version ( lex_ctxt * lexic)

Definition at line 246 of file nasl_scanner_glue.c.

247{
248 (void) lexic;
249 return FAKE_CELL;
250}

References FAKE_CELL.

◆ script_xref()

tree_cell * script_xref ( lex_ctxt * lexic)

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");

Parameters
lexicThe parser context.
Returns
Always FAKE_CELL.

Definition at line 155 of file nasl_scanner_glue.c.

156{
157 struct script_infos *script_infos = lexic->script_infos;
158 char *name = get_str_var_by_name (lexic, "name");
159 char *value = get_str_var_by_name (lexic, "value");
160 char *csv = get_str_var_by_name (lexic, "csv");
161
162 if (((value == NULL) && (csv == NULL)) || name == NULL)
163 {
164 nasl_perror (lexic,
165 "script_xref() syntax error - should be"
166 " script_xref(name:<name>, value:<value>) or"
167 " script_xref(name:<name>, value:<value>, csv:<CSVs>) or"
168 " script_xref(name:<name>, csv:<CSVs>)\n");
169 if (name == NULL)
170 {
171 nasl_perror (lexic, " <name> is empty\n");
172 }
173 else
174 {
175 nasl_perror (lexic, " <name> is %s\n", name);
176 }
177 if ((value == NULL) && (csv == NULL))
178 {
179 nasl_perror (lexic, " <value> and <csv> is empty)\n");
180 }
181 else
182 {
183 nasl_perror (lexic, " <value> is %s\n)", value);
184 nasl_perror (lexic, " <csv> is %s\n)", csv);
185 }
186 return FAKE_CELL;
187 }
188
189 if (csv)
190 nvti_add_refs (script_infos->nvti, name, csv, "");
191
192 if (value)
193 nvti_add_vtref (script_infos->nvti, vtref_new (name, value, ""));
194
195 return FAKE_CELL;
196}

References FAKE_CELL, get_str_var_by_name(), name, nasl_perror(), script_infos::nvti, and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ security_message()

tree_cell * security_message ( lex_ctxt * lexic)

Send a security message to the client.

Parameters
[in]lexicNASL lexer.
Returns
FAKE_CELL.

Definition at line 1165 of file nasl_scanner_glue.c.

1166{
1168}
void post_alarm(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
Definition plugutils.c:774
void proto_post_alarm(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
Definition plugutils.c:767

References post_alarm(), proto_post_alarm(), and security_something().

Here is the call graph for this function:

◆ security_notus()

tree_cell * security_notus ( lex_ctxt * lexic)

Definition at line 1092 of file nasl_scanner_glue.c.

1093{
1094 tree_cell *result;
1095 gchar *kb_result;
1096 named_nasl_var *oid_var, *var;
1097 unsigned char *oid, *result_string;
1098
1099 result = get_variable_by_name (lexic, "result");
1100 if (result == NULL)
1101 {
1102 nasl_perror (lexic, "security_lsc: oid or result is NULL\n");
1103 return FAKE_CELL;
1104 }
1105
1106 var = (named_nasl_var *) result->x.ref_val;
1107
1108 oid_var = get_var_by_name (&var->u.v.v_arr, "oid");
1109 if (oid_var == NULL)
1110 {
1111 nasl_perror (lexic, "security_lsc: oid not found\n");
1112 return NULL;
1113 }
1114
1115 oid = (unsigned char *) oid_var->u.v.v_str.s_val;
1116
1117 if (notus_type == NOTUS)
1118 {
1119 result_string = get_notus_result_message (lexic, var);
1120 }
1121 else
1122 {
1123 named_nasl_var *message;
1124 message = get_var_by_name (&var->u.v.v_arr, "message");
1125 if (message == NULL)
1126 {
1127 nasl_perror (lexic, "security_lsc: message not found\n");
1128 return NULL;
1129 }
1130 result_string = message->u.v.v_str.s_val;
1131 }
1132
1133 if (result_string == NULL)
1134 {
1135 nasl_perror (lexic, "security_lsc: No results to publish\n");
1136 return FAKE_CELL;
1137 }
1138
1139 gchar ip_str[INET6_ADDRSTRLEN];
1140 addr6_to_str (lexic->script_infos->ip, ip_str);
1141 // type|||IP|||HOSTNAME|||package|||OID|||the result message|||URI
1142 kb_result = g_strdup_printf ("%s|||%s|||%s|||%s|||%s|||%s|||%s", "ALARM",
1143 ip_str, " ", "package", oid, result_string, "");
1144
1145 // Only free result_string for notus type, as skiron uses a reference to a
1146 // nasl var
1147 if (notus_type == NOTUS)
1148 g_free (result_string);
1149
1150 kb_item_push_str_with_main_kb_check (get_main_kb (), "internal/results",
1151 kb_result);
1152 g_free (kb_result);
1153
1154 return FAKE_CELL;
1155}
kb_t get_main_kb(void)
gets the main_kb. @description returns the previously set main_kb; when asserts are enabled it will a...
Definition kb_cache.c:41
tree_cell * get_variable_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:176
static unsigned char * get_notus_result_message(lex_ctxt *lexic, named_nasl_var *var)
int kb_item_push_str_with_main_kb_check(kb_t kb, const char *name, const char *value)
Check if the current kb corresponds to the original scanid, if it matches it kb_item_push_str....
Definition plugutils.c:533
struct in6_addr * ip
Definition scanneraux.h:37

References FAKE_CELL, get_main_kb(), get_notus_result_message(), get_var_by_name(), get_variable_by_name(), script_infos::ip, kb_item_push_str_with_main_kb_check(), nasl_perror(), NOTUS, notus_type, 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, and TC::x.

Here is the call graph for this function:

◆ security_something()

tree_cell * security_something ( lex_ctxt * lexic,
proto_post_something_t proto_post_func,
post_something_t post_func )
static

Definition at line 960 of file nasl_scanner_glue.c.

962{
963 struct script_infos *script_infos = lexic->script_infos;
964
965 char *proto = get_str_var_by_name (lexic, "protocol");
966 char *data = get_str_var_by_name (lexic, "data");
967 char *uri = get_str_var_by_name (lexic, "uri");
968 int port = get_int_var_by_name (lexic, "port", -1);
969 char *dup = NULL;
970
971 if (data != NULL)
972 {
973 size_t len = get_var_size_by_name (lexic, "data");
974 size_t i;
975
976 dup = g_malloc0 ((len + 1) * sizeof (char *));
977 memcpy (dup, data, len + 1);
978
979 for (i = 0; i < len; i++)
980 if (dup[i] == '\0')
981 dup[i] = ' ';
982 }
983
985 {
986 if (data != NULL)
987 fprintf (stdout, "%s\n", dup);
988 else
989 fprintf (stdout, "Success\n");
990 }
991
992 if (proto == NULL)
993 proto = get_str_var_by_name (lexic, "proto");
994
995 if (port < 0)
996 port = get_int_var_by_num (lexic, 0, -1);
997
998 if (dup != NULL)
999 {
1000 if (proto == NULL)
1001 post_func (lexic->oid, script_infos, port, dup, uri);
1002 else
1003 proto_post_func (lexic->oid, script_infos, port, proto, dup, uri);
1004
1005 g_free (dup);
1006 return FAKE_CELL;
1007 }
1008
1009 if (proto == NULL)
1010 post_func (lexic->oid, script_infos, port, NULL, uri);
1011 else
1012 proto_post_func (lexic->oid, script_infos, port, proto, NULL, uri);
1013
1014 return FAKE_CELL;
1015}

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_kb_item()

tree_cell * set_kb_item ( lex_ctxt * lexic)

Set a kb item.

If expire is set the key will be removed after it expired.

Parameters
[in]lexicNASL lexer.
[in]nameName of Item.
[in]valueValue of Item.
[in]expireOptional expire for item in seconds.
Returns
FAKE_CELL

Definition at line 895 of file nasl_scanner_glue.c.

896{
897 struct script_infos *script_infos = lexic->script_infos;
898 char *name = get_str_var_by_name (lexic, "name");
899 int type = get_var_type_by_name (lexic, "value");
900 int expire = get_int_var_by_name (lexic, "expire", -1);
901
902 if (expire != -1)
903 return set_kb_item_volatile (lexic);
904
905 if (name == NULL)
906 {
907 nasl_perror (lexic, "Syntax error with set_kb_item() [null name]\n",
908 name);
909 return FAKE_CELL;
910 }
911
912 if (type == VAR2_INT)
913 {
914 int value = get_int_var_by_name (lexic, "value", -1);
915 if (value != -1)
916 plug_set_key (script_infos, name, ARG_INT, GSIZE_TO_POINTER (value));
917 else
919 lexic, "Syntax error with set_kb_item() [value=-1 for name '%s']\n",
920 name);
921 }
922 else
923 {
924 char *value = get_str_var_by_name (lexic, "value");
925 size_t len = get_var_size_by_name (lexic, "value");
926 if (value == NULL)
927 {
929 lexic,
930 "Syntax error with set_kb_item() [null value for name '%s']\n",
931 name);
932 return FAKE_CELL;
933 }
935 }
936
937 return FAKE_CELL;
938}
static tree_cell * set_kb_item_volatile(lex_ctxt *lexic)
Set a volatile kb item.
void plug_set_key_len(struct script_infos *args, char *name, int type, const void *value, size_t len)
Definition plugutils.c:1033

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.

Here is the call graph for this function:

◆ set_kb_item_volatile()

tree_cell * set_kb_item_volatile ( lex_ctxt * lexic)
static

Set a volatile kb item.

Parameters
[in]lexicNASL lexer.
[in]nameName of Item.
[in]valueValue of Item.
[in]expireOptional expire for item in seconds.
Returns
FAKE_CELL

Definition at line 837 of file nasl_scanner_glue.c.

838{
839 struct script_infos *script_infos = lexic->script_infos;
840 char *name = get_str_var_by_name (lexic, "name");
841 int type = get_var_type_by_name (lexic, "value");
842 int expire = get_int_var_by_name (lexic, "expire", -1);
843
844 if (name == NULL)
845 {
846 nasl_perror (lexic, "Syntax error with set_kb_item() [null name]\n",
847 name);
848 return FAKE_CELL;
849 }
850
851 if (type == VAR2_INT)
852 {
853 int value = get_int_var_by_name (lexic, "value", -1);
854 if (value != -1 && expire != -1)
856 GSIZE_TO_POINTER (value), expire);
857 else
858 nasl_perror (lexic,
859 "Syntax error with set_kb_item() [value=-1 or expire=-1 "
860 "for name '%s']\n",
861 name);
862 }
863 else
864 {
865 char *value = get_str_var_by_name (lexic, "value");
866 size_t len = get_var_size_by_name (lexic, "value");
867 if (value == NULL || expire == -1)
868 {
869 nasl_perror (lexic,
870 "Syntax error with set_kb_item() [null value or "
871 "expire=-1 for name '%s']\n",
872 name);
873 return FAKE_CELL;
874 }
876 len);
877 }
878
879 return FAKE_CELL;
880}
void plug_set_key_volatile(struct script_infos *args, char *name, int type, const void *value, int expire)
Set volatile key with expire.
Definition plugutils.c:1111
void plug_set_key_len_volatile(struct script_infos *args, char *name, int type, const void *value, int expire, size_t len)
Set volatile key with expire.
Definition plugutils.c:1077

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().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ notus_err

int notus_err = 0
static

Error code for Notus.

The last occurred error code is stored in this variable.

Definition at line 1274 of file nasl_scanner_glue.c.

Referenced by nasl_notus(), nasl_notus_error(), and parse_notus().

◆ notus_type

int notus_type = 0
static

Type of Notus scan. This is either Notus or Skiron.

Definition at line 957 of file nasl_scanner_glue.c.

Referenced by nasl_notus(), nasl_notus_type(), and security_notus().