36#include <gvm/base/logging.h>
37#include <gvm/base/networking.h>
38#include <gvm/base/prefs.h>
39#include <gvm/util/kb.h>
50#define G_LOG_DOMAIN "lib nasl"
59 for (i = 0; i <
len; i++)
61 if (!isdigit (str[i]))
65 snprintf (buf,
sizeof (buf),
"%d", atoi (str));
66 if (strcmp (buf, str) != 0)
102 timeout = g_strdup_printf (
"%d", to);
104 np = nvtpref_new (NVTPREF_TIMEOUT_ID,
"timeout",
"entry", timeout);
105 nvti_add_pref (nvti, np);
123 for (i = 0; cve != NULL; i++)
162 if (((value == NULL) && (csv == NULL)) ||
name == NULL)
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");
177 if ((value == NULL) && (csv == NULL))
179 nasl_perror (lexic,
" <value> and <csv> is empty)\n");
205 if (value == NULL ||
name == NULL)
207 nasl_perror (lexic,
"script_tag() syntax error - should be"
208 " script_tag(name:<name>, value:<value>)\n");
228 if (strchr (value,
'|'))
268 nasl_perror (lexic,
"Argument error in function script_category()\n");
269 nasl_perror (lexic,
"Function usage is : script_category(<category>)\n");
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");
299 for (i = 0; dep != NULL; i++)
317 nasl_perror (lexic,
"Argument error in function script_require_keys()\n");
319 "Function usage is : script_require_keys(<name>...)\n");
320 nasl_perror (lexic,
"Where <name> is the name of a key\n");
324 for (i = 0; keys != NULL; i++)
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");
353 splits = g_strsplit (re,
"=", 0);
355 if (!splits[0] || !splits[1] || !*splits[1] || splits[2])
361 for (i = 0; keys != NULL; i++)
365 if (splits && keys && !strcmp (keys, splits[0]))
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");
394 for (i = 0; keys != NULL; i++)
457 "Invalid id or not allowed id value in the call to %s()\n",
461 if (!
name || !type || !value)
464 "Argument error in the call to script_add_preference()\n");
476 nasl_perror (lexic,
"Invalid or already existent preference id\n");
481 np = nvtpref_new (
id,
name, type, value);
504 if (pref == NULL &&
id == -1)
507 "Argument error in the function script_get_preference()\n");
509 "Function usage is : pref = script_get_preference(<name>, "
519 retc->
x.
i_val = atoi (value);
523 retc->
size = strlen (value);
546 "Argument error in the function script_get_preference()\n");
548 "script_get_preference_file_content(<name>)\n");
561 if (contentsize <= 0)
564 "script_get_preference_file_content: could not get "
565 " size of file from preference %s\n",
571 retc->
size = contentsize;
583 const char *value, *local;
589 lexic,
"script_get_preference_file_location: no preference name!\n");
598 "script_get_preference_file_location: could not get preference %s\n",
606 len = strlen (local);
622 retc->
x.
i_val = prefs_get_bool (
"safe_checks");
637 const char *
oid = lexic->
oid;
661 struct kb_item *res, *top;
665 nasl_perror (lexic,
"get_kb_list() usage : get_kb_list(<NameOfItem>)\n");
675 if (strchr (kb_mask,
'*'))
676 top = res = kb_item_get_pattern (kb, kb_mask);
678 top = res = kb_item_get_all (kb, kb_mask);
683 bzero (&v,
sizeof (v));
685 if (res->type == KB_TYPE_INT)
692 else if (res->type == KB_TYPE_STR)
724 if (kb_entry == NULL)
729 if (
val == NULL && type == -1)
733 if (type == KB_TYPE_INT)
793 nasl_perror (lexic,
"Syntax error with replace_kb_item() [null name]\n",
803 GSIZE_TO_POINTER (value));
806 lexic,
"Syntax error with replace_kb_item(%s) [value=-1]\n",
name);
816 "Syntax error with replace_kb_item(%s) [null value]\n",
846 nasl_perror (lexic,
"Syntax error with set_kb_item() [null name]\n",
854 if (value != -1 && expire != -1)
856 GSIZE_TO_POINTER (value), expire);
859 "Syntax error with set_kb_item() [value=-1 or expire=-1 "
867 if (value == NULL || expire == -1)
870 "Syntax error with set_kb_item() [null value or "
871 "expire=-1 for name '%s']\n",
907 nasl_perror (lexic,
"Syntax error with set_kb_item() [null name]\n",
919 lexic,
"Syntax error with set_kb_item() [value=-1 for name '%s']\n",
930 "Syntax error with set_kb_item() [null value for name '%s']\n",
946 int,
const char *,
const char *,
952 const char *,
const char *);
976 dup = g_malloc0 ((
len + 1) *
sizeof (
char *));
977 memcpy (dup, data,
len + 1);
979 for (i = 0; i <
len; i++)
987 fprintf (stdout,
"%s\n", dup);
989 fprintf (stdout,
"Success\n");
1017static unsigned char *
1021 *specifier, *start, *end;
1024 GString *result_buf, *buf;
1029 nasl_perror (lexic,
"security_lsc: vul_packages is not an array\n");
1032 result_buf = g_string_new (NULL);
1049 if (
name == NULL || version == NULL)
1056 buf = g_string_new (NULL);
1057 g_string_printf (buf,
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,
1064 name->u.v.v_str.s_val,
1067 else if (start != NULL && end != NULL)
1069 buf = g_string_new (NULL);
1070 g_string_printf (buf,
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,
1085 g_string_append (result_buf, buf->str);
1086 g_string_free (buf, TRUE);
1088 return (
unsigned char *) result_buf->str;
1097 unsigned char *
oid, *result_string;
1102 nasl_perror (lexic,
"security_lsc: oid or result is NULL\n");
1109 if (oid_var == NULL)
1111 nasl_perror (lexic,
"security_lsc: oid not found\n");
1125 if (message == NULL)
1127 nasl_perror (lexic,
"security_lsc: message not found\n");
1133 if (result_string == NULL)
1135 nasl_perror (lexic,
"security_lsc: No results to publish\n");
1139 gchar ip_str[INET6_ADDRSTRLEN];
1142 kb_result = g_strdup_printf (
"%s|||%s|||%s|||%s|||%s|||%s|||%s",
"ALARM",
1143 ip_str,
" ",
"package",
oid, result_string,
"");
1148 g_free (result_string);
1197 value = prefs_get (
name);
1203 retc->
size = strlen (value);
1214 retc->
x.
str_val = strdup (version);
1215 retc->
size = strlen (version);
1240 const char *json = NULL;
1244 if (os_version == NULL || pkg_list == NULL)
1246 g_warning (
"%s: Missing data for running LSC", __func__);
1263 g_warning (
"Unable to send the package list for LSC to the host process");
1265 g_free ((
void *) json);
1291 memset (&element, 0,
sizeof (element));
1294 memset (&vulnerable_pkgs, 0,
sizeof (vulnerable_pkgs));
1297 memset (&
oid, 0,
sizeof (
oid));
1299 oid.v.v_str.s_val = (
unsigned char *) advisory->
oid;
1300 oid.v.v_str.s_siz = strlen (advisory->
oid);
1302 for (
size_t j = 0; j < advisory->
count; j++)
1307 memset (&installed, 0,
sizeof (installed));
1308 memset (&vul_pkg, 0,
sizeof (vul_pkg));
1320 memset (&range, 0,
sizeof (range));
1323 memset (&start, 0,
sizeof (start));
1329 memset (&end, 0,
sizeof (end));
1340 memset (&single, 0,
sizeof (single));
1343 memset (&version, 0,
sizeof (version));
1349 memset (&specifier, 0,
sizeof (specifier));
1360 g_warning (
"%s: Unknown fixed version type for advisory %s",
1361 __func__, advisory->
oid);
1393 for (
size_t i = 0; i < adv->
count; i++)
1398 memset (&element, 0,
sizeof (element));
1401 memset (&msg, 0,
sizeof (msg));
1406 memset (&
oid, 0,
sizeof (
oid));
1408 oid.v.v_str.s_val = (
unsigned char *) advisory->
oid;
1409 oid.v.v_str.s_siz = strlen (advisory->
oid);
1453 if (product == NULL || pkg_list == NULL)
1455 g_warning (
"%s: Missing data for running LSC", __func__);
1464 g_warning (
"%s: Unable to get the response", __func__);
1475 g_warning (
"%s: Unable to process the response", __func__);
1526 char *notus_err_str;
1532 notus_err_str = strdup (
"Missing data for running LSC");
1535 notus_err_str = strdup (
"Unable to get the response");
1538 notus_err_str = strdup (
"Unknown fixed version type for advisory");
1541 notus_err_str = strdup (
"Unable to process the response");
1549 retc->
size = strlen (notus_err_str);
1565 const char *prange = prefs_get (
"port_range");
1567 static u_short *ports = NULL;
1574 nasl_perror (lexic,
"Argument error in scanner_get_port()\n");
1575 nasl_perror (lexic,
"Correct usage is : num = scanner_get_port(<num>)\n");
1577 "Where <num> should be 0 the first time you call it\n");
1583 ports = (u_short *)
getpts ((
char *) prange, &num);
1596 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
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 *)
long int get_var_size_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.
static tree_cell * parse_skiron(advisories_t *adv)
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)
static tree_cell * parse_notus(advisories_t *advisories)
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 * nasl_notus_type(lex_ctxt *lexic)
Get the Notus scan type.
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.
static unsigned char * get_notus_result_message(lex_ctxt *lexic, named_nasl_var *var)
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)
static int notus_type
Type of Notus scan. This is either Notus or Skiron.
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
skiron_advisory_t ** skiron_advisories
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 * lsc_get_response(const char *pkg_list, const char *os)
Sent the installed package list and OS to notus.
void advisories_free(advisories_t *advisories)
Free()'s an advisories.
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
struct notus_advisory advisory_t
struct skiron_advisory skiron_advisory_t
struct vulnerable_pkg vuln_pkg_t
const gchar * vendor_version_get()
Get vendor version.
Header file: vendor version functions prototypes.