OpenVAS Libraries  9.0.1
Macros | Functions
nasl_wmi.c File Reference

NASL WMI functions. More...

#include <string.h>
#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <inttypes.h>
#include "../misc/plugutils.h"
#include "nasl_wmi.h"
#include "openvas_wmi_interface.h"
#include "../misc/openvas_logging.h"

Macros

#define IMPORT(var)   char *var = get_str_local_var_by_name(lexic, #var)
 
#define max   5
 

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

Macro Definition Documentation

◆ IMPORT

#define IMPORT (   var)    char *var = get_str_local_var_by_name(lexic, #var)
Todo:
Check for memleak and document reference counting in tree cells. In some cases, after a tree_cell (typically retc) has been allocated with alloc_tree_cell, it is not later freed or deref_tree_cell'ed. It has to evaluated if that is okay or leads to memory leaks.

◆ max

#define max   5

Function Documentation

◆ check_alpha()

int check_alpha ( char *  val)

Returns 0 if any alphabets are present

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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.

◆ stoi_uint32_t()

uint32_t stoi_uint32_t ( char *  s)

Convert string to unsign int 32 bit

◆ stoi_uint64_t()

uint64_t stoi_uint64_t ( char *  s)

Convert string to unsign int 64 bit