Greenbone Vulnerability Management Libraries 22.29.3
openvasd.c File Reference

API for Openvas Daemon communication. More...

#include "openvasd.h"
#include "../base/array.h"
#include "../base/networking.h"
#include "../http/httputils.h"
#include "../http_scanner/http_scanner.h"
#include "../util/json.h"
#include <cjson/cJSON.h>
#include <netinet/in.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

Go to the source code of this file.

Data Structures

struct  openvasd_credential
 Struct credential information for openvasd. More...
struct  openvasd_target
 Struct holding target information. More...
struct  openvasd_vt_single
 Struct holding vt information. More...

Macros

#define G_LOG_DOMAIN   "libgvm ovd"
 GLib log domain.
#define RESP_CODE_ERR   -1
#define RESP_CODE_OK   0

Functions

http_scanner_resp_t openvasd_get_vt_stream_init (http_scanner_connector_t conn)
 Fetch feed metadata chunk by chunk.
int openvasd_get_vt_stream (http_scanner_connector_t conn)
 Get a new feed metadata chunk.
http_scanner_resp_t openvasd_get_vts (http_scanner_connector_t conn)
 Get VT's metadata.
http_scanner_resp_t openvasd_get_performance (http_scanner_connector_t conn, openvasd_get_performance_opts_t opts)
 Get performance data.
int openvasd_parsed_performance (http_scanner_connector_t conn, openvasd_get_performance_opts_t opts, gchar **graph, gchar **err)
 Parse performance data.
static void add_port_to_scan_json (gpointer range, gpointer p_array)
 Add a port range to the scan json object.
static void add_credential_to_scan_json (gpointer credentials, gpointer cred_array)
 Add a credential to the scan json object.
static void add_scan_preferences_to_scan_json (gpointer key, gpointer val, gpointer scan_prefs_array)
 Add a scan preference to the scan json object.
static void add_vts_to_scan_json (gpointer single_vt, gpointer vts_array)
 Add a VT to the scan json object.
char * openvasd_build_scan_config_json (openvasd_target_t *target, GHashTable *scan_preferences, GSList *vts)
 Build a json object with data necessary to start a scan.
openvasd_credential_topenvasd_credential_new (const gchar *type, const gchar *service, const gchar *port)
 Allocate and initialize a new openvasd credential.
void openvasd_credential_free (openvasd_credential_t *credential)
 Free an openvasd credential.
void openvasd_credential_set_auth_data (openvasd_credential_t *credential, const gchar *name, const gchar *value)
 Get authentication data from an openvasd credential.
openvasd_target_topenvasd_target_new (const gchar *scanid, const gchar *hosts, const gchar *ports, const gchar *exclude_hosts, int reverse_lookup_unify, int reverse_lookup_only)
 Create a new openvasd target.
void openvasd_target_set_finished_hosts (openvasd_target_t *target, const gchar *finished_hosts)
 Set the finished hosts of an openvasd target.
void openvasd_target_free (openvasd_target_t *target)
 Free an openvasd target, including all added credentials.
void openvasd_target_add_alive_test_methods (openvasd_target_t *target, gboolean icmp, gboolean tcp_syn, gboolean tcp_ack, gboolean arp, gboolean consider_alive)
 Add alive test methods to openvasd target.
void openvasd_target_add_credential (openvasd_target_t *target, openvasd_credential_t *credential)
 Add a credential to an openvasd target.
openvasd_vt_single_topenvasd_vt_single_new (const gchar *vt_id)
 Create a new single openvasd VT.
void openvasd_vt_single_free (openvasd_vt_single_t *vt_single)
 Free a single openvasd VT, including all preference values.
void openvasd_vt_single_add_value (openvasd_vt_single_t *vt_single, const gchar *name, const gchar *value)
 Add a preference value to an openvasd VT.

Detailed Description

API for Openvas Daemon communication.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "libgvm ovd"

GLib log domain.

◆ RESP_CODE_ERR

#define RESP_CODE_ERR   -1

◆ RESP_CODE_OK

#define RESP_CODE_OK   0

Function Documentation

◆ add_credential_to_scan_json()

void add_credential_to_scan_json ( gpointer credentials,
gpointer cred_array )
static

Add a credential to the scan json object.

Parameters
credentialsCredential to add.
cred_arrayJSON array to add the credential to.

◆ add_port_to_scan_json()

void add_port_to_scan_json ( gpointer range,
gpointer p_array )
static

Add a port range to the scan json object.

Parameters
rangePort range to add.
p_arrayJSON array to add the port range to.

◆ add_scan_preferences_to_scan_json()

void add_scan_preferences_to_scan_json ( gpointer key,
gpointer val,
gpointer scan_prefs_array )
static

Add a scan preference to the scan json object.

Parameters
keyPreference ID.
valPreference value.
scan_prefs_arrayJSON array to add the preference to.

◆ add_vts_to_scan_json()

void add_vts_to_scan_json ( gpointer single_vt,
gpointer vts_array )
static

Add a VT to the scan json object.

Parameters
single_vtVT to add.
vts_arrayJSON array to add the VT to.

◆ openvasd_build_scan_config_json()

char * openvasd_build_scan_config_json ( openvasd_target_t * target,
GHashTable * scan_preferences,
GSList * vts )

Build a json object with data necessary to start a scan.

JSON result consists of scan_id, message type, host ip, hostname, port, together with proto, OID, result message and uri.

Parameters
targettarget
scan_preferencesScan preferences to be added to the scan config
vtsVTS collection to be added to the scan config.
Returns
JSON string on success. Must be freed by caller. NULL on error.

◆ openvasd_credential_free()

void openvasd_credential_free ( openvasd_credential_t * credential)

Free an openvasd credential.

Parameters
credentialThe credential to free.

◆ openvasd_credential_new()

openvasd_credential_t * openvasd_credential_new ( const gchar * type,
const gchar * service,
const gchar * port )

Allocate and initialize a new openvasd credential.

Parameters
typeThe credential type.
serviceThe service the credential is for.
portThe port.
Returns
New openvasd credential.

◆ openvasd_credential_set_auth_data()

void openvasd_credential_set_auth_data ( openvasd_credential_t * credential,
const gchar * name,
const gchar * value )

Get authentication data from an openvasd credential.

Parameters
credentialThe credential to get the data from.
nameThe name of the data item to get.
valueThe authentication data or NULL to unset.

◆ openvasd_get_performance()

http_scanner_resp_t openvasd_get_performance ( http_scanner_connector_t conn,
openvasd_get_performance_opts_t opts )

Get performance data.

Parameters
connConnector struct with the data necessary for the connection.
optsOptions for the performance request.
Returns
Response Struct containing the performance data.

◆ openvasd_get_vt_stream()

int openvasd_get_vt_stream ( http_scanner_connector_t conn)

Get a new feed metadata chunk.

This function must be call until the return value is 0, meaning there is no more data to fetch.

Parameters
connConnector struct with the data necessary for the connection
Returns
greather than 0 if the handler is still getting data. 0 if the transmision finished. -1 on error

◆ openvasd_get_vt_stream_init()

http_scanner_resp_t openvasd_get_vt_stream_init ( http_scanner_connector_t conn)

Fetch feed metadata chunk by chunk.

Parameters
connConnector struct with the data necessary for the connection
Returns
The response.

◆ openvasd_get_vts()

http_scanner_resp_t openvasd_get_vts ( http_scanner_connector_t conn)

Get VT's metadata.

Parameters
connConnector struct with the data necessary for the connection
Returns
Response Struct containing the feed metadata in json format in the body.

◆ openvasd_parsed_performance()

int openvasd_parsed_performance ( http_scanner_connector_t conn,
openvasd_get_performance_opts_t opts,
gchar ** graph,
gchar ** err )

Parse performance data.

Parameters
connConnector struct with the data necessary for the connection.
optsOptions for the performance request.
graphPointer to store the graph data.
errPointer to store error message if any.
Returns
0 on success, -1 on error.

◆ openvasd_target_add_alive_test_methods()

void openvasd_target_add_alive_test_methods ( openvasd_target_t * target,
gboolean icmp,
gboolean tcp_syn,
gboolean tcp_ack,
gboolean arp,
gboolean consider_alive )

Add alive test methods to openvasd target.

Parameters
targetThe openvasd target to add the methods to.
icmpUse ICMP ping.
tcp_synUse TCP-SYN ping.
tcp_ackUse TCP-ACK ping.
arpUse ARP ping.
consider_aliveConsider host to be alive.

◆ openvasd_target_add_credential()

void openvasd_target_add_credential ( openvasd_target_t * target,
openvasd_credential_t * credential )

Add a credential to an openvasd target.

Parameters
targetThe openvasd target to add the credential to.
credentialThe credential to add. Will be freed with target.

◆ openvasd_target_free()

void openvasd_target_free ( openvasd_target_t * target)

Free an openvasd target, including all added credentials.

Parameters
targetThe openvasd target to free.

◆ openvasd_target_new()

openvasd_target_t * openvasd_target_new ( const gchar * scanid,
const gchar * hosts,
const gchar * ports,
const gchar * exclude_hosts,
int reverse_lookup_unify,
int reverse_lookup_only )

Create a new openvasd target.

Parameters
scanidScan ID.
hostsThe hostnames of the target.
portsThe ports of the target.
exclude_hostsThe excluded hosts of the target.
reverse_lookup_unifyLookup flag.
reverse_lookup_onlyLookup flag.
Returns
The newly allocated openvasd_target_t.

◆ openvasd_target_set_finished_hosts()

void openvasd_target_set_finished_hosts ( openvasd_target_t * target,
const gchar * finished_hosts )

Set the finished hosts of an openvasd target.

Parameters
targetThe openvasd target to modify.
finished_hostsThe hostnames to consider finished.

◆ openvasd_vt_single_add_value()

void openvasd_vt_single_add_value ( openvasd_vt_single_t * vt_single,
const gchar * name,
const gchar * value )

Add a preference value to an openvasd VT.

This creates a copy of the name and value.

Parameters
vt_singleThe VT to add the preference to.
nameThe name / identifier of the preference.
valueThe value of the preference.

◆ openvasd_vt_single_free()

void openvasd_vt_single_free ( openvasd_vt_single_t * vt_single)

Free a single openvasd VT, including all preference values.

Parameters
vt_singleThe openvasd VT to free.

◆ openvasd_vt_single_new()

openvasd_vt_single_t * openvasd_vt_single_new ( const gchar * vt_id)

Create a new single openvasd VT.

Parameters
vt_idThe id of the VT.
Returns
The newly allocated single VT.