OpenVAS Scanner  7.0.0~git
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

int check_alpha (char *val)
 
uint32_t stoi_uint32_t (char *s)
 
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 54 of file nasl_wmi.c.

◆ IMPORT

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

Definition at line 47 of file nasl_wmi.c.

◆ max

#define max   5

Definition at line 48 of file nasl_wmi.c.

Function Documentation

◆ check_alpha()

int check_alpha ( char *  val)

Returns 0 if any alphabets are present

Definition at line 60 of file nasl_wmi.c.

61 {
62  int i, val_len;
63  val_len = strlen (val);
64 
65  if ((strcmp (val, "-1")) != 0)
66  {
67  for (i = 0; i < val_len; i++)
68  if (!isdigit (val[i]))
69  return 0;
70  }
71  else
72  return 0;
73 
74  return 1;
75 }

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 203 of file nasl_wmi.c.

204 {
205  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
206  if (!handle)
207  return NULL;
208 
210 
211  if (wmi_close (handle) == 0)
212  {
213  retc->x.i_val = 1;
214  return retc;
215  }
216  return NULL;
217 }

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 142 of file nasl_wmi.c.

143 {
144  struct script_infos *script_infos = lexic->script_infos;
145  struct in6_addr *host = plug_get_host_ip (script_infos);
146  char *ip;
147  char *argv[max];
148  WMI_HANDLE handle;
149  int argc = 5;
150  IMPORT (username);
151  IMPORT (password);
152  IMPORT (ns);
153 
154  if (ns == NULL)
155  ns = "root\\cimv2";
156 
157  if ((host == NULL) || (username == NULL) || (password == NULL))
158  {
159  g_message ("nasl_wmi_connect: Invalid input arguments");
160  return NULL;
161  }
162 
163  ip = addr6_as_str (host);
164  if ((strlen (password) == 0) || (strlen (username) == 0) || strlen (ip) == 0)
165  {
166  g_message ("nasl_wmi_connect: Invalid input arguments");
167  g_free (ip);
168  return NULL;
169  }
170 
171  // Construct the WMI query
172  argv[0] = g_strdup ("wmic");
173  argv[1] = g_strdup ("-U");
174  argv[2] = g_strdup_printf ("%s%%%s", username, password);
175  argv[3] = g_strdup_printf ("//%s", ip);
176  argv[4] = g_strdup (ns);
177  g_free (ip);
178 
180  handle = wmi_connect (argc, argv);
181  if (!handle)
182  {
183  g_message ("nasl_wmi_connect: WMI Connect failed");
184  return NULL;
185  }
186 
187  retc->x.ref_val = handle;
188  return retc;
189 }

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 379 of file nasl_wmi.c.

380 {
381  struct script_infos *script_infos = lexic->script_infos;
382  struct in6_addr *host = plug_get_host_ip (script_infos);
383  char *ip;
384  IMPORT (username);
385  IMPORT (password);
386  char *argv[4];
387  WMI_HANDLE handle;
388  int argc = 4;
389 
390  if ((host == NULL) || (username == NULL) || (password == NULL))
391  {
392  g_message ("nasl_wmi_connect_reg: Invalid input arguments");
393  return NULL;
394  }
395 
396  ip = addr6_as_str (host);
397  if ((strlen (password) == 0) || (strlen (username) == 0) || strlen (ip) == 0)
398  {
399  g_message ("nasl_wmi_connect_reg: Invalid input arguments");
400  g_free (ip);
401  return NULL;
402  }
403 
404  // Construct the WMI query
405  argv[0] = g_strdup ("wmic");
406  argv[1] = g_strdup ("-U");
407  argv[2] = g_strdup_printf ("%s%%%s", username, password);
408  argv[3] = g_strdup_printf ("//%s", ip);
409  g_free (ip);
410 
412  handle = wmi_connect_reg (argc, argv);
413  if (!handle)
414  {
415  g_message ("nasl_wmi_connect_reg: WMI Connect failed");
416  return NULL;
417  }
418 
419  retc->x.ref_val = handle;
420  return retc;
421 }

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 279 of file nasl_wmi.c.

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

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 232 of file nasl_wmi.c.

233 {
234  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
235  char *query = get_str_var_by_name (lexic, "query");
236  char *res = NULL;
237  int value;
238 
239  if (!handle)
240  return NULL;
241 
243  retc->x.str_val = NULL;
244  retc->size = 0;
245 
246  value = wmi_query (handle, query, &res);
247 
248  if ((value == -1) || (res == NULL))
249  {
250  g_message ("wmi_query: WMI query failed '%s'", query);
251  return NULL;
252  }
253 
254  retc->x.str_val = strdup (res);
255  retc->size = strlen (res);
256 
257  return retc;
258 }

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 335 of file nasl_wmi.c.

336 {
337  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
338  if (!handle)
339  return NULL;
340 
341  char *query = get_str_var_by_name (lexic, "query"); // WQL query
342  char *res = NULL;
343  int value;
345  retc->x.str_val = NULL;
346  retc->size = 0;
347 
348  value = wmi_query_rsop (handle, query, &res);
349  if ((value == -1) || (res == NULL))
350  {
351  g_message ("wmi_query_rsop: WMI query failed");
352  return NULL;
353  }
354  retc->x.str_val = strdup (res);
355  retc->size = strlen (res);
356 
357  return retc;
358 }

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 978 of file nasl_wmi.c.

979 {
980  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
981 
982  if (!handle)
983  return NULL;
984 
985  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
986 
987  int value;
988 
990  retc->x.i_val = 1;
991 
992  value = wmi_reg_create_key (handle, key);
993 
994  if (value == -1)
995  {
996  g_message ("nasl_wmi_reg_create_key: WMI registery key create"
997  " operation failed");
998  return NULL;
999  }
1000  return retc;
1001 }

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 1017 of file nasl_wmi.c.

1018 {
1019  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
1020 
1021  if (!handle)
1022  return NULL;
1023 
1024  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
1025 
1026  int value;
1027 
1029  retc->x.i_val = 1;
1030 
1031  value = wmi_reg_delete_key (handle, key);
1032 
1033  if (value == -1)
1034  {
1035  g_message ("nasl_wmi_reg_delete_key: WMI registery key"
1036  " delete operation failed");
1037  return NULL;
1038  }
1039  return retc;
1040 }

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 524 of file nasl_wmi.c.

525 {
526  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
527 
528  if (!handle)
529  return NULL;
530 
531  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
532  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
533 
534  char *res = NULL;
535  int value;
537  retc->x.str_val = NULL;
538  retc->size = 0;
539 
540  value = wmi_reg_enum_key (handle, hive, key, &res);
541 
542  if ((value == -1) || (res == NULL))
543  {
544  g_message ("nasl_wmi_reg_enum_key: WMI query failed");
545  return NULL;
546  }
547 
548  retc->x.str_val = strdup (res);
549  retc->size = strlen (res);
550 
551  return retc;
552 }

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 481 of file nasl_wmi.c.

482 {
483  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
484 
485  if (!handle)
486  return NULL;
487 
488  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
489  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
490 
491  char *res = NULL;
492  int value;
494  retc->x.str_val = NULL;
495  retc->size = 0;
496 
497  value = wmi_reg_enum_value (handle, hive, key, &res);
498 
499  if ((value == -1) || (res == NULL))
500  {
501  g_message ("nasl_wmi_reg_enum_value: WMI query failed");
502  return NULL;
503  }
504 
505  retc->x.str_val = strdup (res);
506  retc->size = strlen (res);
507 
508  return retc;
509 }

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 567 of file nasl_wmi.c.

568 {
569  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
570 
571  if (!handle)
572  return NULL;
573 
574  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
575  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
576  char *val_name =
577  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
578 
579  char *res = NULL;
580  int value;
581 
583  retc->x.str_val = NULL;
584  retc->size = 0;
585 
586  value = wmi_reg_get_bin_val (handle, hive, key, val_name, &res);
587 
588  if ((value == -1) || (res == NULL))
589  {
590  g_message ("nasl_wmi_reg_get_bin_val: WMI query failed");
591  return NULL;
592  }
593 
594  retc->x.str_val = strdup (res);
595  retc->size = strlen (res);
596  return retc;
597 }

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 612 of file nasl_wmi.c.

613 {
614  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
615 
616  if (!handle)
617  return NULL;
618 
619  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
620  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
621  char *val_name =
622  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
623 
624  char *res = NULL;
625  int value;
626 
628  retc->x.str_val = NULL;
629  retc->size = 0;
630 
631  value = wmi_reg_get_dword_val (handle, hive, key, val_name, &res);
632 
633  if ((value == 0) && (res == 0))
634  res = "0";
635 
636  if ((value == -1) || (res == NULL))
637  {
638  g_message ("nasl_wmi_reg_get_dword_val: WMI query failed");
639  return NULL;
640  }
641 
642  retc->x.str_val = strdup (res);
643  retc->size = strlen (res);
644  return retc;
645 }

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 660 of file nasl_wmi.c.

661 {
662  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
663 
664  if (!handle)
665  return NULL;
666 
667  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
668  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
669  char *val_name =
670  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
671 
672  char *res = NULL;
673  int value;
674 
676  retc->x.str_val = NULL;
677  retc->size = 0;
678 
679  value = wmi_reg_get_ex_string_val (handle, hive, key, val_name, &res);
680 
681  if ((value == -1) || (res == NULL))
682  {
683  g_message ("nasl_wmi_reg_get_ex_string_val: WMI query failed");
684  return NULL;
685  }
686 
687  retc->x.str_val = strdup (res);
688  retc->size = strlen (res);
689  return retc;
690 }

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 705 of file nasl_wmi.c.

706 {
707  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
708 
709  if (!handle)
710  return NULL;
711 
712  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
713  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
714  char *val_name =
715  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
716 
717  char *res = NULL;
718  int value;
719 
721  retc->x.str_val = NULL;
722  retc->size = 0;
723 
724  value = wmi_reg_get_mul_string_val (handle, hive, key, val_name, &res);
725 
726  if ((value == -1) || (res == NULL))
727  {
728  g_message ("nasl_wmi_reg_get_mul_string_val: WMI query failed");
729  return NULL;
730  }
731 
732  retc->x.str_val = strdup (res);
733  retc->size = strlen (res);
734  return retc;
735 }

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 750 of file nasl_wmi.c.

751 {
752  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
753 
754  if (!handle)
755  return NULL;
756 
757  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
758  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
759  char *val_name =
760  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
761 
762  char *res = NULL;
763  int value;
764 
766  retc->x.str_val = NULL;
767  retc->size = 0;
768 
769  value = wmi_reg_get_qword_val (handle, hive, key, val_name, &res);
770 
771  if ((value == -1) || (res == NULL))
772  {
773  g_message ("nasl_wmi_reg_get_qword_val: WMI query failed");
774  return NULL;
775  }
776 
777  retc->x.str_val = strdup (res);
778  retc->size = strlen (res);
779  return retc;
780 }

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 436 of file nasl_wmi.c.

437 {
438  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
439 
440  if (!handle)
441  return NULL;
442 
443  unsigned int hive = get_int_var_by_name (lexic, "hive", 0); // REGISTRY Hive
444  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
445  char *key_name =
446  get_str_var_by_name (lexic, "key_name"); // REGISTRY value name
447 
448  char *res = NULL;
449  int value;
451  retc->x.str_val = NULL;
452  retc->size = 0;
453 
454  value = wmi_reg_get_sz (handle, hive, key, key_name, &res);
455 
456  if ((value == -1) || (res == NULL))
457  {
458  g_message ("nasl_wmi_reg_get_sz: WMI Registry get failed");
459  return NULL;
460  }
461 
462  retc->x.str_val = strdup (res);
463  retc->size = strlen (res);
464 
465  return retc;
466 }

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 796 of file nasl_wmi.c.

797 {
798  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
799 
800  if (!handle)
801  return NULL;
802 
803  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
804  char *val_name =
805  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
806  char *val = get_str_var_by_name (lexic, "val"); // REGISTERY VALUE TO SET
807 
808  uint32_t val1;
809  int value;
810 
811  // Return NULL if any alphabet is present
812  if (check_alpha (val) == 0)
813  return NULL;
814 
815  // Convert string to proper 64 bit integer
816  val1 = stoi_uint32_t (val);
817 
819  retc->x.i_val = 1;
820 
821  value = wmi_reg_set_dword_val (handle, key, val_name, val1);
822 
823  if (value == -1)
824  {
825  g_message ("nasl_wmi_reg_set_dword_val: WMI registry set"
826  " operation failed");
827  return NULL;
828  }
829  return retc;
830 }

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 896 of file nasl_wmi.c.

897 {
898  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
899 
900  if (!handle)
901  return NULL;
902 
903  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
904  char *val_name =
905  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
906  char *val = get_str_var_by_name (lexic, "val"); // REGISTERY VALUE TO SET
907 
908  int value;
909 
911  retc->x.i_val = 1;
912 
913  value = wmi_reg_set_ex_string_val (handle, key, val_name, val);
914 
915  if (value == -1)
916  {
917  g_message (
918  "nasl_wmi_reg_set_ex_string_val: WMI registery set operation failed");
919  return NULL;
920  }
921  return retc;
922 }

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 846 of file nasl_wmi.c.

847 {
848  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
849 
850  if (!handle)
851  return NULL;
852 
853  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
854  char *val_name =
855  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
856  char *val = get_str_var_by_name (lexic, "val"); // REGISTERY VALUE TO SET
857 
858  uint64_t val1;
859  int value;
860 
861  // Return if alphabets present
862  if (check_alpha (val) == 0)
863  return NULL;
864 
865  // Convert string to proper integer
866  val1 = stoi_uint64_t (val);
867 
869  retc->x.i_val = 1;
870 
871  value = wmi_reg_set_qword_val (handle, key, val_name, val1);
872 
873  if (value == -1)
874  {
875  g_message ("nasl_wmi_reg_set_qword_val: WMI register"
876  " set operation failed");
877  return NULL;
878  }
879  return retc;
880 }

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 938 of file nasl_wmi.c.

939 {
940  WMI_HANDLE handle = (WMI_HANDLE) get_int_var_by_name (lexic, "wmi_handle", 0);
941 
942  if (!handle)
943  return NULL;
944 
945  char *key = get_str_var_by_name (lexic, "key"); // REGISTRY KEY
946  char *val_name =
947  get_str_var_by_name (lexic, "val_name"); // REGISTRY VALUE NAME
948  char *val = get_str_var_by_name (lexic, "val"); // REGISTERY VALUE TO SET
949 
950  int value;
951 
953  retc->x.i_val = 1;
954 
955  value = wmi_reg_set_string_val (handle, key, val_name, val);
956 
957  if (value == -1)
958  {
959  g_message ("nasl_wmi_reg_set_string_val: WMI registery"
960  " set operation failed");
961  return NULL;
962  }
963  return retc;
964 }

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 108 of file nasl_wmi.c.

109 {
110  char *version = wmi_versioninfo ();
111  tree_cell *retc;
112  (void) lexic;
113 
114  if (!version)
115  return NULL;
116 
117  retc = alloc_typed_cell (CONST_DATA);
118  retc->x.str_val = strdup (version);
119  retc->size = strlen (version);
120  return retc;
121 }

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

uint32_t stoi_uint32_t ( char *  s)

Convert string to unsign int 32 bit

Definition at line 81 of file nasl_wmi.c.

82 {
83  uint32_t v;
84  sscanf (s, "%" PRIu32, &v);
85  return v;
86 }

Referenced by nasl_wmi_reg_set_dword_val().

Here is the caller graph for this function:

◆ stoi_uint64_t()

uint64_t stoi_uint64_t ( char *  s)

Convert string to unsign int 64 bit

Definition at line 92 of file nasl_wmi.c.

93 {
94  uint64_t v;
95  sscanf (s, "%" PRIu64, &v);
96  return v;
97 }

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:71
stoi_uint64_t
uint64_t stoi_uint64_t(char *s)
Definition: nasl_wmi.c:92
script_infos
Definition: scanneraux.h:43
CONST_DATA
@ CONST_DATA
Definition: nasl_tree.h:93
check_alpha
int check_alpha(char *val)
Definition: nasl_wmi.c:60
wmi_reg_create_key
int wmi_reg_create_key(WMI_HANDLE, const char *)
Create Registry Key.
Definition: wmi_interface_stub.c:462
plug_get_host_ip
struct in6_addr * plug_get_host_ip(struct script_infos *args)
Definition: plugutils.c:285
TC::str_val
char * str_val
Definition: nasl_tree.h:112
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:398
wmi_reg_enum_key
int wmi_reg_enum_key(WMI_HANDLE, unsigned int, const char *, char **)
Enumerate Registry keys.
Definition: wmi_interface_stub.c:218
TC::x
union TC::@2 x
get_str_var_by_name
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
wmi_connect_reg
WMI_HANDLE wmi_connect_reg(int argc, char **argv)
Establish connection to a WMI Registry service.
Definition: wmi_interface_stub.c:144
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:442
max
#define max
Definition: nasl_wmi.c:48
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:244
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:298
IMPORT
#define IMPORT(var)
Definition: nasl_wmi.c:47
TC::size
int size
Definition: nasl_tree.h:109
get_int_var_by_name
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1113
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:271
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:352
wmi_connect
WMI_HANDLE wmi_connect(int argc, char **argv)
Establish connection to a WMI service.
Definition: wmi_interface_stub.c:56
TC::ref_val
void * ref_val
Definition: nasl_tree.h:114
wmi_reg_enum_value
int wmi_reg_enum_value(WMI_HANDLE, unsigned int, const char *, char **)
Enumerate Registry values.
Definition: wmi_interface_stub.c:193
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:420
struct_lex_ctxt::script_infos
struct script_infos * script_infos
Definition: nasl_lex_ctxt.h:41
TC
Definition: nasl_tree.h:104
wmi_query_rsop
int wmi_query_rsop(WMI_HANDLE, const char *, char **)
WMI RSOP query.
Definition: wmi_interface_stub.c:126
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:376
host
Host information, implemented as doubly linked list.
Definition: hosts.c:46
wmi_versioninfo
char * wmi_versioninfo(void)
Return version info for WMI implementation.
Definition: wmi_interface_stub.c:41
WMI_HANDLE
void * WMI_HANDLE
Definition: openvas_wmi_interface.h:33
CONST_INT
@ CONST_INT
Definition: nasl_tree.h:90
val
const char * val
Definition: nasl_init.c:378
wmi_connect_rsop
WMI_HANDLE wmi_connect_rsop(int argc, char **argv)
Establish connection to a WMI RSOP service.
Definition: wmi_interface_stub.c:107
wmi_query
int wmi_query(WMI_HANDLE, const char *, char **)
Query WMI service using a WQL query.
Definition: wmi_interface_stub.c:89
alloc_typed_cell
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
wmi_reg_delete_key
int wmi_reg_delete_key(WMI_HANDLE, const char *)
Delete Registry Key.
Definition: wmi_interface_stub.c:479
stoi_uint32_t
uint32_t stoi_uint32_t(char *s)
Definition: nasl_wmi.c:81
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:325
TC::i_val
long int i_val
Definition: nasl_tree.h:113
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:167