OpenVAS Scanner  22.7.9
nasl_wmi.c File Reference

NASL WMI functions. More...

#include "nasl_wmi.h"
#include "../misc/plugutils.h"
#include "openvas_wmi_interface.h"
#include <arpa/inet.h>
#include <ctype.h>
#include <gvm/base/logging.h>
#include <gvm/base/networking.h>
#include <inttypes.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
Include dependency graph for nasl_wmi.c:

Go to the source code of this file.

Macros

#define IMPORT(var)   char *var = get_str_var_by_name (lexic, #var)
 
#define max   5
 
#define G_LOG_DOMAIN   "lib nasl"
 GLib logging domain. More...
 

Functions

static int check_alpha (char *val)
 
static uint32_t stoi_uint32_t (char *s)
 
static uint64_t stoi_uint64_t (char *s)
 
tree_cellnasl_wmi_versioninfo (lex_ctxt *lexic)
 Get a version string of the WMI implementation. More...
 
tree_cellnasl_wmi_connect (lex_ctxt *lexic)
 Connect to a WMI service and return a handle for it. More...
 
tree_cellnasl_wmi_close (lex_ctxt *lexic)
 Close WMI service handle. More...
 
tree_cellnasl_wmi_query (lex_ctxt *lexic)
 Perform WQL query. More...
 
tree_cellnasl_wmi_connect_rsop (lex_ctxt *lexic)
 Connect to a WMI RSOP service and return a handle for it. More...
 
tree_cellnasl_wmi_query_rsop (lex_ctxt *lexic)
 WMI RSOP query. More...
 
tree_cellnasl_wmi_connect_reg (lex_ctxt *lexic)
 Connect to a WMI Registry service and return a handle for it. More...
 
tree_cellnasl_wmi_reg_get_sz (lex_ctxt *lexic)
 Get string value from Registry. More...
 
tree_cellnasl_wmi_reg_enum_value (lex_ctxt *lexic)
 Enumerate registry values. More...
 
tree_cellnasl_wmi_reg_enum_key (lex_ctxt *lexic)
 Enumerate registry keys. More...
 
tree_cellnasl_wmi_reg_get_bin_val (lex_ctxt *lexic)
 Get registry binary value. More...
 
tree_cellnasl_wmi_reg_get_dword_val (lex_ctxt *lexic)
 Get registry DWORD value. More...
 
tree_cellnasl_wmi_reg_get_ex_string_val (lex_ctxt *lexic)
 Get registry expanded string value. More...
 
tree_cellnasl_wmi_reg_get_mul_string_val (lex_ctxt *lexic)
 Get registry multi valued strings. More...
 
tree_cellnasl_wmi_reg_get_qword_val (lex_ctxt *lexic)
 Get registry QWORD value. More...
 
tree_cellnasl_wmi_reg_set_dword_val (lex_ctxt *lexic)
 Set Registry DWORD value. More...
 
tree_cellnasl_wmi_reg_set_qword_val (lex_ctxt *lexic)
 Set Registry QWORD value. More...
 
tree_cellnasl_wmi_reg_set_ex_string_val (lex_ctxt *lexic)
 Set Registry Expanded string value. More...
 
tree_cellnasl_wmi_reg_set_string_val (lex_ctxt *lexic)
 Set Registry string value. More...
 
tree_cellnasl_wmi_reg_create_key (lex_ctxt *lexic)
 Create Registry key. More...
 
tree_cellnasl_wmi_reg_delete_key (lex_ctxt *lexic)
 Delete Registry key. More...
 

Detailed Description

NASL WMI functions.

Provides WMI (Windows Management Instrumentation) functionalities via calling functions of a appropriate library. The API offers three groups of functions:

  1. WMI_FUNCTIONS
  2. WMI_RSOP_FUNCTIONS (RSOP = Resultant Set of Policy)
  3. WMI_REGISTRY_FUNCTIONS

Definition in file nasl_wmi.c.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib nasl"

GLib logging domain.

Definition at line 40 of file nasl_wmi.c.

◆ IMPORT

#define IMPORT (   var)    char *var = get_str_var_by_name (lexic, #var)

Definition at line 33 of file nasl_wmi.c.

◆ max

#define max   5

Definition at line 34 of file nasl_wmi.c.

Function Documentation

◆ check_alpha()

static int check_alpha ( char *  val)
static

Returns 0 if any alphabets are present

Definition at line 46 of file nasl_wmi.c.

47 {
48  int i, val_len;
49  val_len = strlen (val);
50 
51  if ((strcmp (val, "-1")) != 0)
52  {
53  for (i = 0; i < val_len; i++)
54  if (!isdigit (val[i]))
55  return 0;
56  }
57  else
58  return 0;
59 
60  return 1;
61 }

References val.

Referenced by nasl_wmi_reg_set_dword_val(), and nasl_wmi_reg_set_qword_val().

Here is the caller graph for this function:

◆ nasl_wmi_close()

tree_cell* nasl_wmi_close ( lex_ctxt lexic)

Close WMI service handle.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case of a serious problem. Else returns a treecell with integer == 1.

Retrieves local variable "wmi_handle" from the lexical context and closes the respective handle.

Definition at line 191 of file nasl_wmi.c.

192 {
193  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
194  if (!handle)
195  return NULL;
196 
198 
199  if (wmi_close (handle) == 0)
200  {
201  retc->x.i_val = 1;
202  return retc;
203  }
204  return NULL;
205 }

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

Here is the call graph for this function:

◆ nasl_wmi_connect()

tree_cell* nasl_wmi_connect ( lex_ctxt lexic)

Connect to a WMI service and return a handle for it.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case the connection could not be established. Else a tree_cell with the handle.

Retrieves local variables "host", "username", "password" and "ns" from the lexical context, performs and connects to this given WMI service returning a handle for the service as integer.

Definition at line 128 of file nasl_wmi.c.

129 {
130  struct script_infos *script_infos = lexic->script_infos;
131  struct in6_addr *host = plug_get_host_ip (script_infos);
132  char *ip;
133  char *argv[max];
134  WMI_HANDLE handle;
135  int argc = 5;
136  IMPORT (username);
137  IMPORT (password);
138  IMPORT (ns);
139  IMPORT (options);
140 
141  if (ns == NULL)
142  ns = "root\\cimv2";
143 
144  if ((host == NULL) || (username == NULL) || (password == NULL))
145  {
146  g_message ("nasl_wmi_connect: Invalid input arguments");
147  return NULL;
148  }
149 
150  ip = addr6_as_str (host);
151  if ((strlen (password) == 0) || (strlen (username) == 0) || strlen (ip) == 0)
152  {
153  g_message ("nasl_wmi_connect: Invalid input arguments");
154  g_free (ip);
155  return NULL;
156  }
157 
158  // Construct the WMI query
159  argv[0] = g_strdup ("wmic");
160  argv[1] = g_strdup ("-U");
161  argv[2] = g_strdup_printf ("%s%%%s", username, password);
162  argv[3] = g_strdup_printf ("//%s%s", ip, options ? options : "[sign]");
163  argv[4] = g_strdup (ns);
164  g_free (ip);
165 
167  handle = wmi_connect (argc, argv);
168  if (!handle)
169  {
170  g_message ("nasl_wmi_connect: WMI Connect failed or missing WMI support "
171  "for the scanner");
172  return NULL;
173  }
174 
175  retc->x.ref_val = handle;
176  return retc;
177 }

References alloc_typed_cell(), CONST_INT, IMPORT, max, plug_get_host_ip(), TC::ref_val, struct_lex_ctxt::script_infos, wmi_connect(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_connect_reg()

tree_cell* nasl_wmi_connect_reg ( lex_ctxt lexic)

Connect to a WMI Registry service and return a handle for it.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case the connection could not be established. Else a tree_cell with the handle.

Retrieves local variables "host", "username", "password" from the lexical context, performs and connects to this given WMI service returning a handle for the service as integer.

Definition at line 388 of file nasl_wmi.c.

389 {
390  struct script_infos *script_infos = lexic->script_infos;
391  struct in6_addr *host = plug_get_host_ip (script_infos);
392  char *ip;
393  IMPORT (username);
394  IMPORT (password);
395  IMPORT (options);
396 
397  char *argv[4];
398  WMI_HANDLE handle;
399  int argc = 4;
400 
401  if ((host == NULL) || (username == NULL) || (password == NULL))
402  {
403  g_message ("nasl_wmi_connect_reg: Invalid input arguments");
404  return NULL;
405  }
406 
407  ip = addr6_as_str (host);
408  if ((strlen (password) == 0) || (strlen (username) == 0) || strlen (ip) == 0)
409  {
410  g_message ("nasl_wmi_connect_reg: Invalid input arguments");
411  g_free (ip);
412  return NULL;
413  }
414 
415  // Construct the WMI query
416  argv[0] = g_strdup ("wmic");
417  argv[1] = g_strdup ("-U");
418  argv[2] = g_strdup_printf ("%s%%%s", username, password);
419  argv[3] = g_strdup_printf ("//%s%s", ip, options ? options : "[sign]");
420  g_free (ip);
421 
423  handle = wmi_connect_reg (argc, argv);
424  if (!handle)
425  {
426  g_message ("nasl_wmi_connect_reg: WMI Connect failed or missing WMI "
427  "support for the scanner");
428  return NULL;
429  }
430 
431  retc->x.ref_val = handle;
432  return retc;
433 }

References alloc_typed_cell(), CONST_INT, IMPORT, plug_get_host_ip(), TC::ref_val, struct_lex_ctxt::script_infos, wmi_connect_reg(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_connect_rsop()

tree_cell* nasl_wmi_connect_rsop ( lex_ctxt lexic)

Connect to a WMI RSOP service and return a handle for it.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case the connection could not be established. Else a tree_cell with the handle.

Retrieves local variables "host", "username", "password" from the lexical context, performs and connects to this given WMI service returning a handle for the service as integer.

Definition at line 275 of file nasl_wmi.c.

276 {
277  struct script_infos *script_infos = lexic->script_infos;
278  struct in6_addr *host = plug_get_host_ip (script_infos);
279  char *ip;
280  IMPORT (username);
281  IMPORT (password);
282  IMPORT (options);
283 
284  char *argv[4];
285  WMI_HANDLE handle;
286  int argc = 4;
287 
288  if ((host == NULL) || (username == NULL) || (password == NULL))
289  {
290  g_message ("nasl_wmi_connect_rsop: Invalid input arguments");
291  return NULL;
292  }
293 
294  ip = addr6_as_str (host);
295  if ((strlen (password) == 0) || (strlen (username) == 0) || strlen (ip) == 0)
296  {
297  g_message ("nasl_wmi_connect_rsop: Invalid input arguments");
298  g_free (ip);
299  return NULL;
300  }
301 
302  // Construct the WMI query
303  argv[0] = g_strdup ("wmic");
304  argv[1] = g_strdup ("-U");
305  argv[2] = g_strdup_printf ("%s%%%s", username, password);
306  argv[3] = g_strdup_printf ("//%s%s", ip, options ? options : "[sign]");
307  g_free (ip);
308 
310  handle = wmi_connect_rsop (argc, argv);
311  if (!handle)
312  {
313  g_message ("nasl_wmi_connect_rsop: WMI Connect failed or missing WMI "
314  "support for the scanner");
315  return NULL;
316  }
317 
318  retc->x.ref_val = handle;
319  return retc;
320 }

References alloc_typed_cell(), CONST_INT, IMPORT, plug_get_host_ip(), TC::ref_val, struct_lex_ctxt::script_infos, wmi_connect_rsop(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_query()

tree_cell* nasl_wmi_query ( lex_ctxt lexic)

Perform WQL query.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case the query can not be executed properly. Else a tree_cell with the result of the query as string.

Retrieves local variables "wmi_handle" and "query" from the lexical context, performs a WMI query on the given handle and returns the result as a string.

Definition at line 220 of file nasl_wmi.c.

221 {
222  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
223  char *query = get_str_var_by_name (lexic, "query");
224  char *res = NULL;
225  int value;
226 
227  if (!handle)
228  return NULL;
229 
231  retc->x.str_val = NULL;
232  retc->size = 0;
233 
234  value = wmi_query (handle, query, &res);
235  if ((value == -1) && (res != NULL))
236  {
237  g_message ("wmi_query: WMI query failed '%s' with error: '%s'", query,
238  res);
239  g_free (res);
240  return NULL;
241  }
242  else if ((value == -1) && (res == NULL))
243  {
244  g_debug ("wmi_query: WMI query failed '%s'", query);
245  return NULL;
246  }
247  else if (res == NULL)
248  return NULL;
249 
250  retc->x.str_val = strdup (res);
251  retc->size = strlen (res);
252 
253  return retc;
254 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_query(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_query_rsop()

tree_cell* nasl_wmi_query_rsop ( lex_ctxt lexic)

WMI RSOP query.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, 1 on success

Retrieves local variables "wmi_handle", "query" from the lexical context, performs the RSOP query returning results in string format.

Definition at line 334 of file nasl_wmi.c.

335 {
336  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
337  if (!handle)
338  return NULL;
339 
340  char *query = get_str_var_by_name (lexic, "query"); // WQL query
341  char *res = NULL;
342  int value;
344  retc->x.str_val = NULL;
345  retc->size = 0;
346 
347  value = wmi_query_rsop (handle, query, &res);
348  if ((value == -1) && (res != NULL))
349  {
350  g_message ("wmi_query_rsop: WMI query failed '%s' with error: '%s'",
351  query, res);
352  g_free (res);
353  return NULL;
354  }
355  else if ((value == -1) && (res == NULL))
356  {
357  g_debug ("wmi_query_rsop: WMI query failed");
358  return NULL;
359  }
360  else if (res == NULL)
361  return NULL;
362 
363  retc->x.str_val = strdup (res);
364  retc->size = strlen (res);
365 
366  return retc;
367 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_query_rsop(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_create_key()

tree_cell* nasl_wmi_reg_create_key ( lex_ctxt lexic)

Create Registry key.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key" from the lexical context, performs the registry create operation for the key.

Definition at line 990 of file nasl_wmi.c.

991 {
992  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
993 
994  if (!handle)
995  return NULL;
996 
997  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
998 
999  int value;
1000 
1002  retc->x.i_val = 1;
1003 
1004  value = wmi_reg_create_key (handle, key);
1005 
1006  if (value == -1)
1007  {
1008  g_message ("nasl_wmi_reg_create_key: WMI registry key create"
1009  " operation failed");
1010  return NULL;
1011  }
1012  return retc;
1013 }

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

Here is the call graph for this function:

◆ nasl_wmi_reg_delete_key()

tree_cell* nasl_wmi_reg_delete_key ( lex_ctxt lexic)

Delete Registry key.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key" from the lexical context, performs the registry delete operation for the key.

It will work only if the key exist

Definition at line 1029 of file nasl_wmi.c.

1030 {
1031  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
1032 
1033  if (!handle)
1034  return NULL;
1035 
1036  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
1037 
1038  int value;
1039 
1041  retc->x.i_val = 1;
1042 
1043  value = wmi_reg_delete_key (handle, key);
1044 
1045  if (value == -1)
1046  {
1047  g_message ("nasl_wmi_reg_delete_key: WMI registry key"
1048  " delete operation failed");
1049  return NULL;
1050  }
1051  return retc;
1052 }

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

Here is the call graph for this function:

◆ nasl_wmi_reg_enum_key()

tree_cell* nasl_wmi_reg_enum_key ( lex_ctxt lexic)

Enumerate registry keys.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL if the query fails. Else a tree_cell with the Registry keys.

Retrieves local variables "wmi_handle", "hive", "key" from the lexical context, performs the registry query returning a string value.

Definition at line 536 of file nasl_wmi.c.

537 {
538  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
539 
540  if (!handle)
541  return NULL;
542 
543  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
544  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
545 
546  char *res = NULL;
547  int value;
549  retc->x.str_val = NULL;
550  retc->size = 0;
551 
552  value = wmi_reg_enum_key (handle, hive, key, &res);
553 
554  if ((value == -1) || (res == NULL))
555  {
556  g_message ("nasl_wmi_reg_enum_key: WMI query failed");
557  return NULL;
558  }
559 
560  retc->x.str_val = strdup (res);
561  retc->size = strlen (res);
562 
563  return retc;
564 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_enum_key(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_enum_value()

tree_cell* nasl_wmi_reg_enum_value ( lex_ctxt lexic)

Enumerate registry values.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL if the query fails. Else a tree_cell with the Registry values.

Retrieves local variables "wmi_handle", "hive", "key" from the lexical context, performs the registry query returning a string value.

Definition at line 493 of file nasl_wmi.c.

494 {
495  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
496 
497  if (!handle)
498  return NULL;
499 
500  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
501  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
502 
503  char *res = NULL;
504  int value;
506  retc->x.str_val = NULL;
507  retc->size = 0;
508 
509  value = wmi_reg_enum_value (handle, hive, key, &res);
510 
511  if ((value == -1) || (res == NULL))
512  {
513  g_message ("nasl_wmi_reg_enum_value: WMI query failed");
514  return NULL;
515  }
516 
517  retc->x.str_val = strdup (res);
518  retc->size = strlen (res);
519 
520  return retc;
521 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_enum_value(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_bin_val()

tree_cell* nasl_wmi_reg_get_bin_val ( lex_ctxt lexic)

Get registry binary value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, else tree_cell containing string representation of binary value

Retrieves local variables "wmi_handle", "hive", "key", "val_name" from the lexical context, performs the registry operation querying binary value.

Definition at line 579 of file nasl_wmi.c.

580 {
581  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
582 
583  if (!handle)
584  return NULL;
585 
586  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
587  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
588  char *val_name =
589  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
590 
591  char *res = NULL;
592  int value;
593 
595  retc->x.str_val = NULL;
596  retc->size = 0;
597 
598  value = wmi_reg_get_bin_val (handle, hive, key, val_name, &res);
599 
600  if ((value == -1) || (res == NULL))
601  {
602  g_message ("nasl_wmi_reg_get_bin_val: WMI query failed");
603  return NULL;
604  }
605 
606  retc->x.str_val = strdup (res);
607  retc->size = strlen (res);
608  return retc;
609 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_bin_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_dword_val()

tree_cell* nasl_wmi_reg_get_dword_val ( lex_ctxt lexic)

Get registry DWORD value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, else tree_cell containing string representation of DWORD value

Retrieves local variables "wmi_handle", "hive", "key", "val_name" from the lexical context, performs the registry operation querying DWORD value.

Definition at line 624 of file nasl_wmi.c.

625 {
626  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
627 
628  if (!handle)
629  return NULL;
630 
631  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
632  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
633  char *val_name =
634  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
635 
636  char *res = NULL;
637  int value;
638 
640  retc->x.str_val = NULL;
641  retc->size = 0;
642 
643  value = wmi_reg_get_dword_val (handle, hive, key, val_name, &res);
644 
645  if ((value == 0) && (res == 0))
646  res = "0";
647 
648  if ((value == -1) || (res == NULL))
649  {
650  g_message ("nasl_wmi_reg_get_dword_val: WMI query failed");
651  return NULL;
652  }
653 
654  retc->x.str_val = strdup (res);
655  retc->size = strlen (res);
656  return retc;
657 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_dword_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_ex_string_val()

tree_cell* nasl_wmi_reg_get_ex_string_val ( lex_ctxt lexic)

Get registry expanded string value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, else tree_cell containing string representation of Expanded String value

Retrieves local variables "wmi_handle", "hive", "key", "val_name" from the lexical context, performs the registry operation querying Expanded string value.

Definition at line 672 of file nasl_wmi.c.

673 {
674  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
675 
676  if (!handle)
677  return NULL;
678 
679  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
680  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
681  char *val_name =
682  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
683 
684  char *res = NULL;
685  int value;
686 
688  retc->x.str_val = NULL;
689  retc->size = 0;
690 
691  value = wmi_reg_get_ex_string_val (handle, hive, key, val_name, &res);
692 
693  if ((value == -1) || (res == NULL))
694  {
695  g_message ("nasl_wmi_reg_get_ex_string_val: WMI query failed");
696  return NULL;
697  }
698 
699  retc->x.str_val = strdup (res);
700  retc->size = strlen (res);
701  return retc;
702 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_ex_string_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_mul_string_val()

tree_cell* nasl_wmi_reg_get_mul_string_val ( lex_ctxt lexic)

Get registry multi valued strings.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, else tree_cell containing string representation of multi valued strings

Retrieves local variables "wmi_handle", "hive", "key", "val_name" from the lexical context, performs the registry operation querying Expanded string value.

Definition at line 717 of file nasl_wmi.c.

718 {
719  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
720 
721  if (!handle)
722  return NULL;
723 
724  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
725  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
726  char *val_name =
727  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
728 
729  char *res = NULL;
730  int value;
731 
733  retc->x.str_val = NULL;
734  retc->size = 0;
735 
736  value = wmi_reg_get_mul_string_val (handle, hive, key, val_name, &res);
737 
738  if ((value == -1) || (res == NULL))
739  {
740  g_message ("nasl_wmi_reg_get_mul_string_val: WMI query failed");
741  return NULL;
742  }
743 
744  retc->x.str_val = strdup (res);
745  retc->size = strlen (res);
746  return retc;
747 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_mul_string_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_qword_val()

tree_cell* nasl_wmi_reg_get_qword_val ( lex_ctxt lexic)

Get registry QWORD value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure, else tree_cell containing string representation of QWORD value

Retrieves local variables "wmi_handle", "hive", "key", "val_name" from the lexical context, performs the registry operation querying 64-bit unsigned integer.

Definition at line 762 of file nasl_wmi.c.

763 {
764  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
765 
766  if (!handle)
767  return NULL;
768 
769  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
770  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
771  char *val_name =
772  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
773 
774  char *res = NULL;
775  int value;
776 
778  retc->x.str_val = NULL;
779  retc->size = 0;
780 
781  value = wmi_reg_get_qword_val (handle, hive, key, val_name, &res);
782 
783  if ((value == -1) || (res == NULL))
784  {
785  g_message ("nasl_wmi_reg_get_qword_val: WMI query failed");
786  return NULL;
787  }
788 
789  retc->x.str_val = strdup (res);
790  retc->size = strlen (res);
791  return retc;
792 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_qword_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_get_sz()

tree_cell* nasl_wmi_reg_get_sz ( lex_ctxt lexic)

Get string value from Registry.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL if the query fails. Else a tree_cell with the Registry value.

Retrieves local variables "wmi_handle", "hive", "key", "key_name" from the lexical context, performs the registry query returning a string value.

Definition at line 448 of file nasl_wmi.c.

449 {
450  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
451 
452  if (!handle)
453  return NULL;
454 
455  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
456  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
457  char *key_name =
458  get_str_var_by_name (lexic, "key_name"); // REGISTRY value name
459 
460  char *res = NULL;
461  int value;
463  retc->x.str_val = NULL;
464  retc->size = 0;
465 
466  value = wmi_reg_get_sz (handle, hive, key, key_name, &res);
467 
468  if ((value == -1) || (res == NULL))
469  {
470  g_message ("nasl_wmi_reg_get_sz: WMI Registry get failed");
471  return NULL;
472  }
473 
474  retc->x.str_val = strdup (res);
475  retc->size = strlen (res);
476 
477  return retc;
478 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), TC::size, TC::str_val, wmi_reg_get_sz(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_set_dword_val()

tree_cell* nasl_wmi_reg_set_dword_val ( lex_ctxt lexic)

Set Registry DWORD value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key", "val_name", "val" from the lexical context, performs the registry set/create operation for double word data type.

It will work only if the key exist

Definition at line 808 of file nasl_wmi.c.

809 {
810  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
811 
812  if (!handle)
813  return NULL;
814 
815  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
816  char *val_name =
817  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
818  char *val = get_str_var_by_name (lexic, "val"); // REGISTRY VALUE TO SET
819 
820  uint32_t val1;
821  int value;
822 
823  // Return NULL if any alphabet is present
824  if (check_alpha (val) == 0)
825  return NULL;
826 
827  // Convert string to proper 64 bit integer
828  val1 = stoi_uint32_t (val);
829 
831  retc->x.i_val = 1;
832 
833  value = wmi_reg_set_dword_val (handle, key, val_name, val1);
834 
835  if (value == -1)
836  {
837  g_message ("nasl_wmi_reg_set_dword_val: WMI registry set"
838  " operation failed");
839  return NULL;
840  }
841  return retc;
842 }

References alloc_typed_cell(), check_alpha(), CONST_INT, get_int_var_by_name(), get_str_var_by_name(), TC::i_val, stoi_uint32_t(), val, wmi_reg_set_dword_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_set_ex_string_val()

tree_cell* nasl_wmi_reg_set_ex_string_val ( lex_ctxt lexic)

Set Registry Expanded string value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key", "val_name", "val" from the lexical context, performs the registry set/create operation for string value.

It will work only if the key exist

Definition at line 908 of file nasl_wmi.c.

909 {
910  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
911 
912  if (!handle)
913  return NULL;
914 
915  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
916  char *val_name =
917  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
918  char *val = get_str_var_by_name (lexic, "val"); // REGISTRY VALUE TO SET
919 
920  int value;
921 
923  retc->x.i_val = 1;
924 
925  value = wmi_reg_set_ex_string_val (handle, key, val_name, val);
926 
927  if (value == -1)
928  {
929  g_message (
930  "nasl_wmi_reg_set_ex_string_val: WMI registry set operation failed");
931  return NULL;
932  }
933  return retc;
934 }

References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), get_str_var_by_name(), TC::i_val, val, wmi_reg_set_ex_string_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_set_qword_val()

tree_cell* nasl_wmi_reg_set_qword_val ( lex_ctxt lexic)

Set Registry QWORD value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key", "val_name", "val" from the lexical context, performs the registry set/create operation for 64-bit unsigned integer.

It will work only if the key exist

Definition at line 858 of file nasl_wmi.c.

859 {
860  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
861 
862  if (!handle)
863  return NULL;
864 
865  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
866  char *val_name =
867  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
868  char *val = get_str_var_by_name (lexic, "val"); // REGISTRY VALUE TO SET
869 
870  uint64_t val1;
871  int value;
872 
873  // Return if alphabets present
874  if (check_alpha (val) == 0)
875  return NULL;
876 
877  // Convert string to proper integer
878  val1 = stoi_uint64_t (val);
879 
881  retc->x.i_val = 1;
882 
883  value = wmi_reg_set_qword_val (handle, key, val_name, val1);
884 
885  if (value == -1)
886  {
887  g_message ("nasl_wmi_reg_set_qword_val: WMI register"
888  " set operation failed");
889  return NULL;
890  }
891  return retc;
892 }

References alloc_typed_cell(), check_alpha(), CONST_INT, get_int_var_by_name(), get_str_var_by_name(), TC::i_val, stoi_uint64_t(), val, wmi_reg_set_qword_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_reg_set_string_val()

tree_cell* nasl_wmi_reg_set_string_val ( lex_ctxt lexic)

Set Registry string value.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL on failure

Retrieves local variables "wmi_handle", "key", "val_name", "val" from the lexical context, performs the registry set/create operation for string value.

It will work only if the key exist

Definition at line 950 of file nasl_wmi.c.

951 {
952  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
953 
954  if (!handle)
955  return NULL;
956 
957  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
958  char *val_name =
959  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
960  char *val = get_str_var_by_name (lexic, "val"); // REGISTRY VALUE TO SET
961 
962  int value;
963 
965  retc->x.i_val = 1;
966 
967  value = wmi_reg_set_string_val (handle, key, val_name, val);
968 
969  if (value == -1)
970  {
971  g_message ("nasl_wmi_reg_set_string_val: WMI registry"
972  " set operation failed");
973  return NULL;
974  }
975  return retc;
976 }

References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), get_str_var_by_name(), TC::i_val, val, wmi_reg_set_string_val(), and TC::x.

Here is the call graph for this function:

◆ nasl_wmi_versioninfo()

tree_cell* nasl_wmi_versioninfo ( lex_ctxt lexic)

Get a version string of the WMI implementation.

Parameters
[in]lexicLexical context of NASL interpreter.
Returns
NULL in case no implementation is present. Else a tree_cell with the version as string.

Definition at line 94 of file nasl_wmi.c.

95 {
96  char *version = wmi_versioninfo ();
97  tree_cell *retc;
98  (void) lexic;
99 
100  if (!version)
101  return NULL;
102 
103  retc = alloc_typed_cell (CONST_DATA);
104  retc->x.str_val = strdup (version);
105  retc->size = strlen (version);
106  return retc;
107 }

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

Here is the call graph for this function:

◆ stoi_uint32_t()

static uint32_t stoi_uint32_t ( char *  s)
static

Convert string to unsign int 32 bit

Definition at line 67 of file nasl_wmi.c.

68 {
69  uint32_t v;
70  sscanf (s, "%" PRIu32, &v);
71  return v;
72 }

Referenced by nasl_wmi_reg_set_dword_val().

Here is the caller graph for this function:

◆ stoi_uint64_t()

static uint64_t stoi_uint64_t ( char *  s)
static

Convert string to unsign int 64 bit

Definition at line 78 of file nasl_wmi.c.

79 {
80  uint64_t v;
81  sscanf (s, "%" PRIu64, &v);
82  return v;
83 }

Referenced by nasl_wmi_reg_set_qword_val().

Here is the caller graph for this function:
wmi_close
int wmi_close(WMI_HANDLE)
Close the connection handle for a WMI service.
Definition: wmi_interface_stub.c:57
script_infos
Definition: scanneraux.h:29
CONST_DATA
@ CONST_DATA
Definition: nasl_tree.h:82
wmi_reg_create_key
int wmi_reg_create_key(WMI_HANDLE, const char *)
Create Registry Key.
Definition: wmi_interface_stub.c:448
plug_get_host_ip
struct in6_addr * plug_get_host_ip(struct script_infos *args)
Definition: plugutils.c:316
TC::str_val
char * str_val
Definition: nasl_tree.h:103
TC::x
union TC::@5 x
wmi_reg_set_qword_val
int wmi_reg_set_qword_val(WMI_HANDLE, const char *, const char *, uint64_t)
Set Registry QWORD value.
Definition: wmi_interface_stub.c:384
wmi_reg_enum_key
int wmi_reg_enum_key(WMI_HANDLE, unsigned int, const char *, char **)
Enumerate Registry keys.
Definition: wmi_interface_stub.c:204
stoi_uint64_t
static uint64_t stoi_uint64_t(char *s)
Definition: nasl_wmi.c:78
get_str_var_by_name
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1118
wmi_connect_reg
WMI_HANDLE wmi_connect_reg(int argc, char **argv)
Establish connection to a WMI Registry service.
Definition: wmi_interface_stub.c:130
wmi_reg_set_string_val
int wmi_reg_set_string_val(WMI_HANDLE, const char *, const char *, const char *)
Set Registry string value.
Definition: wmi_interface_stub.c:428
max
#define max
Definition: nasl_wmi.c:34
wmi_reg_get_bin_val
int wmi_reg_get_bin_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry binary value.
Definition: wmi_interface_stub.c:230
wmi_reg_get_ex_string_val
int wmi_reg_get_ex_string_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry Expanded string value.
Definition: wmi_interface_stub.c:284
IMPORT
#define IMPORT(var)
Definition: nasl_wmi.c:33
TC::size
int size
Definition: nasl_tree.h:99
get_int_var_by_name
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1104
wmi_reg_get_dword_val
int wmi_reg_get_dword_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry DWORD value.
Definition: wmi_interface_stub.c:257
wmi_reg_get_qword_val
int wmi_reg_get_qword_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry QWORD value.
Definition: wmi_interface_stub.c:338
wmi_connect
WMI_HANDLE wmi_connect(int argc, char **argv)
Establish connection to a WMI service.
Definition: wmi_interface_stub.c:42
TC::ref_val
void * ref_val
Definition: nasl_tree.h:105
wmi_reg_enum_value
int wmi_reg_enum_value(WMI_HANDLE, unsigned int, const char *, char **)
Enumerate Registry values.
Definition: wmi_interface_stub.c:179
wmi_reg_set_ex_string_val
int wmi_reg_set_ex_string_val(WMI_HANDLE, const char *, const char *, const char *)
Set Registry Expanded string value.
Definition: wmi_interface_stub.c:406
struct_lex_ctxt::script_infos
struct script_infos * script_infos
Definition: nasl_lex_ctxt.h:30
check_alpha
static int check_alpha(char *val)
Definition: nasl_wmi.c:46
TC
Definition: nasl_tree.h:94
wmi_query_rsop
int wmi_query_rsop(WMI_HANDLE, const char *, char **)
WMI RSOP query.
Definition: wmi_interface_stub.c:112
stoi_uint32_t
static uint32_t stoi_uint32_t(char *s)
Definition: nasl_wmi.c:67
wmi_reg_set_dword_val
int wmi_reg_set_dword_val(WMI_HANDLE, const char *, const char *, uint32_t)
Set Registry DWORD value.
Definition: wmi_interface_stub.c:362
host
Host information, implemented as doubly linked list.
Definition: hosts.c:37
wmi_versioninfo
char * wmi_versioninfo(void)
Return version info for WMI implementation.
Definition: wmi_interface_stub.c:27
WMI_HANDLE
void * WMI_HANDLE
Definition: openvas_wmi_interface.h:19
CONST_INT
@ CONST_INT
Definition: nasl_tree.h:79
val
const char * val
Definition: nasl_init.c:412
wmi_connect_rsop
WMI_HANDLE wmi_connect_rsop(int argc, char **argv)
Establish connection to a WMI RSOP service.
Definition: wmi_interface_stub.c:93
wmi_query
int wmi_query(WMI_HANDLE, const char *, char **)
Query WMI service using a WQL query.
Definition: wmi_interface_stub.c:75
alloc_typed_cell
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:28
wmi_reg_delete_key
int wmi_reg_delete_key(WMI_HANDLE, const char *)
Delete Registry Key.
Definition: wmi_interface_stub.c:465
wmi_reg_get_mul_string_val
int wmi_reg_get_mul_string_val(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry multi-valued strings.
Definition: wmi_interface_stub.c:311
TC::i_val
long int i_val
Definition: nasl_tree.h:104
wmi_reg_get_sz
int wmi_reg_get_sz(WMI_HANDLE, unsigned int, const char *, const char *, char **)
Get Registry string value.
Definition: wmi_interface_stub.c:153