36#include <gvm/base/logging.h>
37#include <gvm/base/networking.h>
38#include <gvm/base/prefs.h>
39#include <gvm/util/kb.h>
49#define G_LOG_DOMAIN "lib nasl"
58 for (i = 0; i <
len; i++)
60 if (!isdigit (str[i]))
64 snprintf (buf,
sizeof (buf),
"%d", atoi (str));
65 if (strcmp (buf, str) != 0)
101 timeout = g_strdup_printf (
"%d", to);
103 np = nvtpref_new (NVTPREF_TIMEOUT_ID,
"timeout",
"entry", timeout);
104 nvti_add_pref (nvti, np);
122 for (i = 0; cve != NULL; i++)
161 if (((value == NULL) && (csv == NULL)) ||
name == NULL)
164 "script_xref() syntax error - should be"
165 " script_xref(name:<name>, value:<value>) or"
166 " script_xref(name:<name>, value:<value>, csv:<CSVs>) or"
167 " script_xref(name:<name>, csv:<CSVs>)\n");
176 if ((value == NULL) && (csv == NULL))
178 nasl_perror (lexic,
" <value> and <csv> is empty)\n");
204 if (value == NULL ||
name == NULL)
206 nasl_perror (lexic,
"script_tag() syntax error - should be"
207 " script_tag(name:<name>, value:<value>)\n");
227 if (strchr (value,
'|'))
267 nasl_perror (lexic,
"Argument error in function script_category()\n");
268 nasl_perror (lexic,
"Function usage is : script_category(<category>)\n");
291 nasl_perror (lexic,
"Argument error in function script_dependencies()\n");
292 nasl_perror (lexic,
"Function usage is : script_dependencies(<name>)\n");
293 nasl_perror (lexic,
"Where <name> is the name of another script\n");
298 for (i = 0; dep != NULL; i++)
316 nasl_perror (lexic,
"Argument error in function script_require_keys()\n");
318 "Function usage is : script_require_keys(<name>...)\n");
319 nasl_perror (lexic,
"Where <name> is the name of a key\n");
323 for (i = 0; keys != NULL; i++)
342 "Argument error in function script_mandatory_keys()\n");
343 nasl_perror (lexic,
"Function usage is: script_mandatory_keys(<name>... "
344 "[, re: '<name>=<regex>'])\n");
345 nasl_perror (lexic,
"Where <name> is the name of a key and <regex> is a "
346 "regular expression for a value of a key.\n");
352 splits = g_strsplit (re,
"=", 0);
354 if (!splits[0] || !splits[1] || !*splits[1] || splits[2])
360 for (i = 0; keys != NULL; i++)
364 if (splits && keys && !strcmp (keys, splits[0]))
387 nasl_perror (lexic,
"Argument error in function script_exclude_keys()\n");
388 nasl_perror (lexic,
"Function usage is : script_exclude_keys(<name>)\n");
389 nasl_perror (lexic,
"Where <name> is the name of a key\n");
393 for (i = 0; keys != NULL; i++)
456 "Invalid id or not allowed id value in the call to %s()\n",
460 if (!
name || !type || !value)
463 "Argument error in the call to script_add_preference()\n");
475 nasl_perror (lexic,
"Invalid or already existent preference id\n");
480 np = nvtpref_new (
id,
name, type, value);
503 if (pref == NULL &&
id == -1)
506 "Argument error in the function script_get_preference()\n");
508 "Function usage is : pref = script_get_preference(<name>, "
518 retc->
x.
i_val = atoi (value);
522 retc->
size = strlen (value);
545 "Argument error in the function script_get_preference()\n");
547 "script_get_preference_file_content(<name>)\n");
560 if (contentsize <= 0)
563 "script_get_preference_file_content: could not get "
564 " size of file from preference %s\n",
570 retc->
size = contentsize;
582 const char *value, *local;
588 lexic,
"script_get_preference_file_location: no preference name!\n");
597 "script_get_preference_file_location: could not get preference %s\n",
605 len = strlen (local);
621 retc->
x.
i_val = prefs_get_bool (
"safe_checks");
636 const char *
oid = lexic->
oid;
660 struct kb_item *res, *top;
664 nasl_perror (lexic,
"get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
674 if (strchr (kb_mask,
'*'))
675 top = res = kb_item_get_pattern (kb, kb_mask);
677 top = res = kb_item_get_all (kb, kb_mask);
682 bzero (&v,
sizeof (v));
684 if (res->type == KB_TYPE_INT)
691 else if (res->type == KB_TYPE_STR)
723 if (kb_entry == NULL)
728 if (
val == NULL && type == -1)
732 if (type == KB_TYPE_INT)
792 nasl_perror (lexic,
"Syntax error with replace_kb_item() [null name]\n",
802 GSIZE_TO_POINTER (value));
805 lexic,
"Syntax error with replace_kb_item(%s) [value=-1]\n",
name);
815 "Syntax error with replace_kb_item(%s) [null value]\n",
845 nasl_perror (lexic,
"Syntax error with set_kb_item() [null name]\n",
853 if (value != -1 && expire != -1)
855 GSIZE_TO_POINTER (value), expire);
858 "Syntax error with set_kb_item() [value=-1 or expire=-1 "
866 if (value == NULL || expire == -1)
869 "Syntax error with set_kb_item() [null value or "
870 "expire=-1 for name '%s']\n",
906 nasl_perror (lexic,
"Syntax error with set_kb_item() [null name]\n",
918 lexic,
"Syntax error with set_kb_item() [value=-1 for name '%s']\n",
929 "Syntax error with set_kb_item() [null value for name '%s']\n",
945 int,
const char *,
const char *,
951 const char *,
const char *);
970 dup = g_malloc0 ((
len + 1) *
sizeof (
char *));
971 memcpy (dup, data,
len + 1);
973 for (i = 0; i <
len; i++)
981 fprintf (stdout,
"%s\n", dup);
983 fprintf (stdout,
"Success\n");
1020 GString *result_buf, *buf;
1026 nasl_perror (lexic,
"security_lsc: oid or result is NULL\n");
1033 if (oid_var == NULL)
1035 nasl_perror (lexic,
"security_lsc: oid not found\n");
1044 nasl_perror (lexic,
"security_lsc: vul_packages is not an array\n");
1047 result_buf = g_string_new (NULL);
1064 if (
name == NULL || version == NULL)
1071 buf = g_string_new (NULL);
1072 g_string_printf (buf,
1074 "Vulnerable package: %s\n"
1075 "Installed version: %s-%s\n"
1076 "Fixed version: %2s%s-%s\n",
1077 name->u.v.v_str.s_val,
name->u.v.v_str.s_val,
1079 name->u.v.v_str.s_val,
1082 else if (start != NULL && end != NULL)
1084 buf = g_string_new (NULL);
1085 g_string_printf (buf,
1087 "Vulnerable package: %s\n"
1088 "Installed version: %s-%s\n"
1089 "Fixed version: < %s-%s\n"
1090 "Fixed version: >=%s-%s\n",
1091 name->u.v.v_str.s_val,
name->u.v.v_str.s_val,
1100 g_string_append (result_buf, buf->str);
1101 g_string_free (buf, TRUE);
1104 if (result_buf == NULL)
1106 nasl_perror (lexic,
"security_lsc: No results to publish\n");
1110 gchar ip_str[INET6_ADDRSTRLEN];
1114 g_strdup_printf (
"%s|||%s|||%s|||%s|||%s|||%s|||%s",
"ALARM", ip_str,
" ",
1115 "package",
oid, result_buf->str,
"");
1116 g_string_free (result_buf, TRUE);
1164 value = prefs_get (
name);
1170 retc->
size = strlen (value);
1181 retc->
x.
str_val = strdup (version);
1182 retc->
size = strlen (version);
1207 const char *json = NULL;
1211 if (os_version == NULL || pkg_list == NULL)
1213 g_warning (
"%s: Missing data for running LSC", __func__);
1230 g_warning (
"Unable to send the package list for LSC to the host process");
1232 g_free ((
void *) json);
1272 if (product == NULL || pkg_list == NULL)
1274 g_warning (
"%s: Missing data for running LSC", __func__);
1283 g_warning (
"%s: Unable to get the response", __func__);
1301 memset (&element, 0,
sizeof (element));
1304 memset (&vulnerable_pkgs, 0,
sizeof (vulnerable_pkgs));
1307 memset (&
oid, 0,
sizeof (
oid));
1317 memset (&installed, 0,
sizeof (installed));
1318 memset (&vul_pkg, 0,
sizeof (vul_pkg));
1330 memset (&range, 0,
sizeof (range));
1333 memset (&start, 0,
sizeof (start));
1339 memset (&end, 0,
sizeof (end));
1350 memset (&single, 0,
sizeof (single));
1353 memset (&version, 0,
sizeof (version));
1359 memset (&specifier, 0,
sizeof (specifier));
1370 g_warning (
"%s: Unknown fixed version type for advisory %s",
1407 char *notus_err_str;
1413 notus_err_str = strdup (
"Missing data for running LSC");
1416 notus_err_str = strdup (
"Unable to get the response");
1419 notus_err_str = strdup (
"Unknown fixed version type for advisory");
1427 retc->
size = strlen (notus_err_str);
1443 const char *prange = prefs_get (
"port_range");
1445 static u_short *ports = NULL;
1452 nasl_perror (lexic,
"Argument error in scanner_get_port()\n");
1453 nasl_perror (lexic,
"Correct usage is : num = scanner_get_port(<num>)\n");
1455 "Where <num> should be 0 the first time you call it\n");
1461 ports = (u_short *)
getpts ((
char *) prange, &num);
1474 retc->
x.
i_val = ports[idx];
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
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
kb_t get_main_kb(void)
gets the main_kb. @description returns the previously set main_kb; when asserts are enabled it will a...
Header file to cache main_kb.
void nasl_perror(lex_ctxt *lexic, char *msg,...)
struct struct_lex_ctxt lex_ctxt
int get_var_size_by_name(lex_ctxt *, const char *)
char * get_str_var_by_name(lex_ctxt *, const char *)
char * get_str_var_by_num(lex_ctxt *, int)
long int get_int_var_by_num(lex_ctxt *, int, int)
long int get_int_var_by_name(lex_ctxt *, const char *, int)
int get_var_type_by_name(lex_ctxt *, const char *)
tree_cell * get_variable_by_name(lex_ctxt *, const char *)
tree_cell * script_tag(lex_ctxt *lexic)
tree_cell * security_notus(lex_ctxt *lexic)
static int notus_err
Error code for Notus.
tree_cell * log_message(lex_ctxt *lexic)
tree_cell * nasl_scanner_status(lex_ctxt *lexic)
static tree_cell * set_kb_item_volatile(lex_ctxt *lexic)
Set a volatile kb item.
tree_cell * nasl_notus(lex_ctxt *lexic)
Directly runs a LSC with the given package list and OS release.
void(* post_something_t)(const char *, struct script_infos *, int, const char *, const char *)
tree_cell * script_family(lex_ctxt *lexic)
tree_cell * script_get_preference(lex_ctxt *lexic)
Get a preferences of the current script.
tree_cell * script_get_preference_file_content(lex_ctxt *lexic)
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.
void(* proto_post_something_t)(const char *, struct script_infos *, int, const char *, const char *, const char *)
static tree_cell * security_something(lex_ctxt *lexic, proto_post_something_t proto_post_func, post_something_t post_func)
tree_cell * script_get_preference_file_location(lex_ctxt *lexic)
tree_cell * error_message2(lex_ctxt *lexic)
tree_cell * script_xref(lex_ctxt *lexic)
Add a cross reference to the meta data.
tree_cell * security_message(lex_ctxt *lexic)
Send a security message to the client.
tree_cell * nasl_scanner_add_port(lex_ctxt *lexic)
tree_cell * get_host_kb_index(lex_ctxt *lexic)
Get the kb index of the host running the current script.
tree_cell * safe_checks(lex_ctxt *lexic)
tree_cell * script_name(lex_ctxt *lexic)
tree_cell * script_copyright(lex_ctxt *lexic)
tree_cell * script_add_preference(lex_ctxt *lexic)
tree_cell * nasl_scanner_get_port(lex_ctxt *lexic)
tree_cell * get_script_oid(lex_ctxt *lexic)
Return the OID of the current script.
tree_cell * script_oid(lex_ctxt *lexic)
tree_cell * nasl_vendor_version(lex_ctxt *lexic)
tree_cell * script_category(lex_ctxt *lexic)
tree_cell * get_kb_list(lex_ctxt *lexic)
tree_cell * script_timeout(lex_ctxt *lexic)
Add timeout preference to VT preferences.
tree_cell * script_require_udp_ports(lex_ctxt *lexic)
tree_cell * get_kb_item(lex_ctxt *lexic)
static int isalldigit(char *str, int len)
tree_cell * script_mandatory_keys(lex_ctxt *lexic)
tree_cell * script_dependencies(lex_ctxt *lexic)
tree_cell * script_exclude_keys(lex_ctxt *lexic)
tree_cell * set_kb_item(lex_ctxt *lexic)
Set a kb item.
tree_cell * nasl_notus_error(lex_ctxt *lexic)
Get the last Notus error as string.
tree_cell * replace_kb_item(lex_ctxt *lexic)
tree_cell * script_require_ports(lex_ctxt *lexic)
tree_cell * script_require_keys(lex_ctxt *lexic)
tree_cell * script_cve_id(lex_ctxt *lexic)
tree_cell * script_version(lex_ctxt *lexic)
tree_cell * nasl_get_preference(lex_ctxt *lexic)
tree_cell * alloc_typed_cell(int typ)
void deref_cell(tree_cell *c)
int add_var_to_array(nasl_array *a, char *name, const anon_nasl_var *v)
named_nasl_var * get_var_by_name(nasl_array *a, const char *s)
anon_nasl_var * nasl_get_var_by_num(void *ctxt, nasl_array *a, int num, int create)
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
struct st_a_nasl_var anon_nasl_var
struct st_nasl_array nasl_array
struct st_n_nasl_var named_nasl_var
unsigned short * getpts(char *origexpr, int *len)
Converts a string like "-100,200-1024,3000-4000,60000-" into an array.
Header file for module network.
void plug_replace_key_len(struct script_infos *args, char *name, int type, void *value, size_t len)
void post_alarm(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
void plug_set_key_volatile(struct script_infos *args, char *name, int type, const void *value, int expire)
Set volatile key with expire.
void scanner_add_port(struct script_infos *args, int port, char *proto)
void proto_post_alarm(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
void plug_set_key_len(struct script_infos *args, char *name, int type, const void *value, size_t len)
void plug_set_dep(struct script_infos *args, const char *depname)
void proto_post_error(const char *oid, struct script_infos *desc, int port, const char *proto, const char *action, const char *uri)
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.
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.
void plug_replace_key(struct script_infos *args, char *name, int type, void *value)
char * get_plugin_preference(const char *oid, const char *name, int pref_id)
Get the a plugins preference.
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....
void post_error(const char *oid, struct script_infos *desc, int port, const char *action, const char *uri)
void plug_set_key(struct script_infos *args, char *name, int type, const void *value)
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.
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".
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.
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".
kb_t plug_get_kb(struct script_infos *args)
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".
Header file for module plugutils.
union TC::@332262321161220155002104006201360276211317150140 x
struct ipc_context * ipc_context
union st_a_nasl_var::@154137074032032170165360023270032033276061363156 v
struct script_infos * script_infos
fixed_version_t * version
Support macros for special platforms.
char * notus_get_response(const char *pkg_list, const char *os)
Sent the installed package list and OS to notus.
advisories_t * process_notus_response(const gchar *resp, const size_t len)
Process a json object which contains advisories and vulnerable packages.
void advisories_free(advisories_t *advisories)
Free()'s an advisories.
struct advisories advisories_t
struct advisory advisory_t
struct vulnerable_pkg vuln_pkg_t
const gchar * vendor_version_get()
Get vendor version.
Header file: vendor version functions prototypes.