|
OpenVAS Scanner 23.40.3
|
#include "table_driven_lsc.h"#include "base/networking.h"#include "kb_cache.h"#include "plugutils.h"#include <ctype.h>#include <curl/curl.h>#include <gnutls/gnutls.h>#include <gvm/base/prefs.h>#include <gvm/util/mqtt.h>#include <gvm/util/uuidutils.h>#include <json-glib/json-glib.h>#include <stddef.h>

Go to the source code of this file.
Data Structures | |
| struct | notus_info |
| Struct to hold necessary information to call and run notus. More... | |
| struct | string |
| Define a string struct for storing the response. More... | |
Macros | |
| #define | G_LOG_DOMAIN "lib misc" |
| GLib logging domain. | |
| #define | RSNOTUS |
Typedefs | |
| typedef struct notus_info * | notus_info_t |
Functions | |
| void | set_lsc_flag (void) |
| Set lsc_flag to 1. | |
| int | lsc_has_run (void) |
| Get lsc_flag value. | |
| static JsonBuilder * | add_packages_str_to_list (JsonBuilder *builder, const gchar *packages) |
| Split the package list string and creates a json array. | |
| static gchar * | make_table_driven_lsc_info_json_str (const char *scan_id, const char *ip_str, const char *hostname, const char *os_release, const char *package_list) |
| Build a json object with data necessary to start a table drive LSC. | |
| static gchar * | get_status_of_table_driven_lsc_from_json (const char *scan_id, const char *host_ip, const char *json, int len) |
| Get the status of table driven lsc from json object. | |
| static notus_info_t | init_notus_info (const char *server) |
| Initialize a notus info struct and stores the server URL. | |
| static void | free_notus_info (notus_info_t notusdata) |
| Free notus info structure. | |
| static char * | help_tolower (char *s) |
| helper function to lower case | |
| static gchar * | make_package_list_as_json_str (const char *packages) |
| Build a json array from the package list to start a table drive LSC. | |
| static int | parse_server (notus_info_t *notusdata) |
| Parse the server URL. | |
| static advisories_t * | advisories_new_notus () |
| Initialize a new advisories struct with 100 slots. | |
| static advisories_t * | advisories_new_skiron () |
| Initialize a new advisories struct with 100 slots. | |
| static void | advisories_add (advisories_t *advisories_list, advisory_t *notus_advisory) |
| Initialize a new advisories struct with 100 slots. | |
| static advisory_t * | advisory_new (char *oid) |
| Initialize a new notus_advisory. | |
| static skiron_advisory_t * | skiron_advisory_new (char *oid, char *message) |
| static void | advisory_add_vuln_pkg (advisory_t *adv, vuln_pkg_t *vuln) |
| Add a new vulnerability to the notus_advisory. | |
| static void | advisory_free (advisory_t *notus_advisory) |
| Free()'s an notus_advisory. | |
| static void | skiron_advisory_free (skiron_advisory_t *skiron_advisory) |
| void | advisories_free (advisories_t *advisories) |
| Free()'s an advisories. | |
| static vuln_pkg_t * | vulnerable_pkg_new (const char *pkg_name, const char *install_version, enum fixed_type type, char *item1, char *item2) |
| Creates a new Vulnerable packages which belongs to an notus_advisory. | |
| static advisories_t * | lsc_process_response_notus (JsonReader *reader) |
| static advisories_t * | lsc_process_response_skiron (JsonReader *reader) |
| advisories_t * | lsc_process_response (const gchar *resp, const size_t len) |
| Process a json object which contains advisories and vulnerable packages. | |
| static void | init_string (struct string *s) |
| Initialize the string struct to hold the response. | |
| static size_t | response_callback_fn (void *ptr, size_t size, size_t nmemb, void *struct_string) |
| Call back function to stored the response. | |
| static long | send_request (notus_info_t notusdata, const char *os, const char *pkg_list, char **response) |
| Send a request to the server. | |
| char * | lsc_get_response (const char *pkg_list, const char *os) |
| Sent the installed package list and OS to notus. | |
| static int | call_rs_notus (const char *ip_str, const char *hostname, const char *pkg_list, const char *os) |
| Call notus and stores the results. | |
| int | run_table_driven_lsc (const char *scan_id, const char *ip_str, const char *hostname, const char *package_list, const char *os_release) |
| Publish the necessary data to start a Table driven LSC scan. | |
Variables | |
| static int | lsc_flag = 0 |
| LSC ran or didn't 0 didn't run. 1 ran. | |
| #define G_LOG_DOMAIN "lib misc" |
GLib logging domain.
Definition at line 30 of file table_driven_lsc.c.
| #define RSNOTUS |
Definition at line 236 of file table_driven_lsc.c.
| typedef struct notus_info* notus_info_t |
Definition at line 252 of file table_driven_lsc.c.
|
static |
Split the package list string and creates a json array.
JSON result consists of scan_id, message type, host ip, hostname, port together with proto, OID, result message and uri.
| [in/out] | builder The Json builder to add the array to. | |
| [in] | packages | The installed package list as string |
Definition at line 65 of file table_driven_lsc.c.
Referenced by make_table_driven_lsc_info_json_str().

|
static |
Initialize a new advisories struct with 100 slots.
| advisories_list[in/out] | An advisories holder to add new advisories into. |
| notus_advisory[in] | the new notus_advisory to add in the list |
Definition at line 472 of file table_driven_lsc.c.
References advisories::advisories, advisories::count, and advisories::max_size.
Referenced by lsc_process_response_notus(), and lsc_process_response_skiron().


| void advisories_free | ( | advisories_t * | advisories | ) |
Free()'s an advisories.
| notus_advisory | The advisories holder to be free()'ed. It free()'s all advisories members. |
Definition at line 589 of file table_driven_lsc.c.
References advisories::advisories, advisory_free(), advisories::count, NOTUS, advisories::skiron_advisories, skiron_advisory_free(), and advisories::type.
Referenced by call_rs_notus(), Ensure(), lsc_process_response_notus(), parse_notus(), and parse_skiron().


|
static |
Initialize a new advisories struct with 100 slots.
Definition at line 436 of file table_driven_lsc.c.
References advisories::advisories, advisories::max_size, NOTUS, and advisories::type.
Referenced by lsc_process_response_notus().


|
static |
Initialize a new advisories struct with 100 slots.
Definition at line 453 of file table_driven_lsc.c.
References advisories::max_size, SKIRON, advisories::skiron_advisories, and advisories::type.
Referenced by lsc_process_response_skiron().

|
static |
Add a new vulnerability to the notus_advisory.
@description Each notus_advisory can have multiple vulnerable packages This structure can hold up to 100 packages.
| adv[in/out] | The notus_advisory to add the vulnerable package into |
| vuln[in] | The vulnerable package to add. |
Definition at line 524 of file table_driven_lsc.c.
References notus_advisory::count, notus_advisory::oid, and notus_advisory::pkgs.
Referenced by lsc_process_response_notus().

|
static |
Free()'s an notus_advisory.
| notus_advisory | The notus_advisory to be free()'ed. It free()'s all vulnerable packages that belong to this notus_advisory. |
Definition at line 545 of file table_driven_lsc.c.
References notus_advisory::count, vulnerable_pkg::install_version, notus_advisory::oid, vulnerable_pkg::pkg_name, notus_advisory::pkgs, RANGE, vulnerable_pkg::range, SINGLE, fixed_version::specifier, version_range::start, version_range::stop, vulnerable_pkg::type, fixed_version::version, and vulnerable_pkg::version.
Referenced by advisories_free(), and lsc_process_response_notus().

|
static |
Initialize a new notus_advisory.
| oid | The notus_advisory's OID |
Definition at line 496 of file table_driven_lsc.c.
References notus_advisory::count, notus_advisory::oid, and oid.
Referenced by lsc_process_response_notus().

|
static |
Call notus and stores the results.
| ip_str | Target's IP address. |
| hostname | Target's hostname. |
| pkg_list | List of packages installed in the target. The packages are "\n" separated. |
| os | Name of the target's operating system. |
Definition at line 1060 of file table_driven_lsc.c.
References advisories::advisories, advisories_free(), advisories::count, notus_advisory::count, get_main_kb(), hostname, vulnerable_pkg::install_version, kb_item_push_str_with_main_kb_check(), lsc_get_response(), lsc_process_response(), notus_advisory::oid, vulnerable_pkg::pkg_name, notus_advisory::pkgs, RANGE, vulnerable_pkg::range, SINGLE, fixed_version::specifier, version_range::start, version_range::stop, vulnerable_pkg::type, fixed_version::version, and vulnerable_pkg::version.
Referenced by run_table_driven_lsc().


|
static |
Free notus info structure.
| notusdata | The data to free() |
Definition at line 276 of file table_driven_lsc.c.
References notus_info::alpn, notus_info::host, notus_info::http_version, notus_info::schema, and notus_info::server.
Referenced by lsc_get_response().

|
static |
Get the status of table driven lsc from json object.
Checks for the corresponding status inside the JSON. If the status does not belong the the scan or host, NULL is returned instead. NULL is also returned if message JSON cannot be parsed correctly. Return value has to be freed by caller.
Definition at line 175 of file table_driven_lsc.c.
Referenced by run_table_driven_lsc().

|
static |
helper function to lower case
| s | the string to lower case |
Definition at line 295 of file table_driven_lsc.c.
Referenced by parse_server(), and send_request().

|
static |
Initialize a notus info struct and stores the server URL.
| server | Original server to store and to get the info from |
Definition at line 261 of file table_driven_lsc.c.
References notus_info::server.
Referenced by lsc_get_response().

|
static |
Initialize the string struct to hold the response.
| s[in/out] | The string struct to be initialized |
Definition at line 870 of file table_driven_lsc.c.
References string::len, and string::ptr.
Referenced by send_request().

| char * lsc_get_response | ( | const char * | pkg_list, |
| const char * | os ) |
Sent the installed package list and OS to notus.
| pkg_list | Installed package list |
| os | The target's OS |
Definition at line 1012 of file table_driven_lsc.c.
References free_notus_info(), init_notus_info(), make_package_list_as_json_str(), parse_server(), and send_request().
Referenced by call_rs_notus(), and nasl_notus().


| int lsc_has_run | ( | void | ) |
Get lsc_flag value.
Definition at line 48 of file table_driven_lsc.c.
References lsc_flag.
Referenced by attack_host().

| advisories_t * lsc_process_response | ( | const gchar * | resp, |
| const size_t | len ) |
Process a json object which contains advisories and vulnerable packages.
@description This is the body string in response get from an openvasd server
| resp | String containing the json object to be processed. |
| len | String length. |
Definition at line 821 of file table_driven_lsc.c.
References len, lsc_process_response_notus(), and lsc_process_response_skiron().
Referenced by call_rs_notus(), Ensure(), and nasl_notus().


|
static |
Definition at line 648 of file table_driven_lsc.c.
References advisories_add(), advisories_free(), advisories_new_notus(), advisory_add_vuln_pkg(), advisory_free(), advisory_new(), name, NOTUS, RANGE, SINGLE, advisories::type, UNKNOWN, and vulnerable_pkg_new().
Referenced by lsc_process_response().


|
static |
Definition at line 779 of file table_driven_lsc.c.
References advisories_add(), advisories_new_skiron(), oid, and skiron_advisory_new().
Referenced by lsc_process_response().


|
static |
Build a json array from the package list to start a table drive LSC.
| packages | The installed package list in the target system to be evaluated |
Definition at line 312 of file table_driven_lsc.c.
Referenced by Ensure(), and lsc_get_response().

|
static |
Build a json object with data necessary to start a table drive LSC.
JSON result consists of scan_id, message type, host ip, hostname, port together with proto, OID, result message and uri.
| scan_id | Scan Id. |
| ip_str | IP string of host. |
| hostname | Name of host. |
| os_release | OS release |
| package_list | The installed package list in the target system to be evaluated |
Definition at line 102 of file table_driven_lsc.c.
References add_packages_str_to_list(), hostname, and scan_id.
Referenced by run_table_driven_lsc().


|
static |
Parse the server URL.
| [in] | server | String containing the server URL Valid is http://example.com:1234 or https://example.com.1234. @notusdata[out] Structure to store information from the URL |
Definition at line 359 of file table_driven_lsc.c.
References help_tolower(), notus_info::port, and notus_info::schema.
Referenced by lsc_get_response().


|
static |
Call back function to stored the response.
@description The function signature is the necessary to work with libcurl. It stores the response in s. It reallocate memory if necessary.
Definition at line 888 of file table_driven_lsc.c.
References string::len, and string::ptr.
Referenced by _http2_req(), and send_request().

| int run_table_driven_lsc | ( | const char * | scan_id, |
| const char * | ip_str, | ||
| const char * | hostname, | ||
| const char * | package_list, | ||
| const char * | os_release ) |
Publish the necessary data to start a Table driven LSC scan.
If the gather-package-list.nasl plugin was launched, and it generated a valid package list for a supported OS, the table driven LSC scan which is subscribed to the topic will perform a scan an publish the the results to be handle by the sensor/client.
Definition at line 1167 of file table_driven_lsc.c.
References call_rs_notus(), get_status_of_table_driven_lsc_from_json(), hostname, make_table_driven_lsc_info_json_str(), payload, and scan_id.
Referenced by call_lsc().


|
static |
Send a request to the server.
| [in] | notusdata | Structure containing information necessary for the request |
| [in] | os | Target's operative system. Necessary for the URL path part. |
| [in] | pkg_list | The package list installed in the target, to be checked |
| [out] | response | The string containing the results in json format. |
Definition at line 917 of file table_driven_lsc.c.
References help_tolower(), init_string(), string::ptr, response_callback_fn(), and notus_info::server.
Referenced by lsc_get_response().


| void set_lsc_flag | ( | void | ) |
Set lsc_flag to 1.
Definition at line 40 of file table_driven_lsc.c.
References lsc_flag.
Referenced by process_ipc_data().

|
static |
Definition at line 573 of file table_driven_lsc.c.
References skiron_advisory::message, and skiron_advisory::oid.
Referenced by advisories_free().

|
static |
Definition at line 506 of file table_driven_lsc.c.
References skiron_advisory::message, oid, and skiron_advisory::oid.
Referenced by lsc_process_response_skiron().

|
static |
Creates a new Vulnerable packages which belongs to an notus_advisory.
| pkg_name | |
| install_version | |
| type | Data type specifying how the fixed version is stored. Can be RANGE or SINGLE |
| item1 | Depending on the type is the "version" for SINGLE type, or the "less than" for RANGE type |
| item2 | Depending on the type is the "specifier" for SINGLE type, or the "greater than" for RANGE type |
Definition at line 618 of file table_driven_lsc.c.
References vulnerable_pkg::install_version, vulnerable_pkg::pkg_name, RANGE, vulnerable_pkg::range, fixed_version::specifier, version_range::start, version_range::stop, vulnerable_pkg::type, fixed_version::version, and vulnerable_pkg::version.
Referenced by lsc_process_response_notus().

|
static |
LSC ran or didn't 0 didn't run. 1 ran.
Definition at line 35 of file table_driven_lsc.c.
Referenced by lsc_has_run(), and set_lsc_flag().