Skip to content

Add: NASL support for calling Notus directly without any side effects. #1905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 18 additions & 83 deletions misc/table_driven_lsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ struct notus_info
char *alpn; // Application layer protocol negotiation: http/1.0, http/1.1, h2
char *http_version; // same version as in application layer
int port; // server port
int tls; // 0: TLS encapsulation diable. Otherwise enable
int tls; // 0: TLS encapsulation disable. Otherwise enable
};

typedef struct notus_info *notus_info_t;
Expand Down Expand Up @@ -427,72 +427,7 @@ parse_server (notus_info_t *notusdata)
return 0;
}

/** @brief Fixed version format
*/
enum fixed_type
{
UNKNOWN, // Unknown
RANGE, // Range of version which fixed the package
SINGLE, // A single version with a specifier (gt or lt)
};

/** @brief Fixed version
*/
struct fixed_version
{
char *version; // a version
char *specifier; // a lt or gt specifier
};
typedef struct fixed_version fixed_version_t;

/** @brief Specify a version range
*/
struct version_range
{
char *start; // <= the version
char *stop; // >= the version
};
typedef struct version_range version_range_t;

/** @brief Define a vulnerable package
*/
struct vulnerable_pkg
{
char *pkg_name; // package name
char *install_version; // installed version of the vulnerable package
enum fixed_type type; // fixed version type: range or single
union
{
version_range_t *range; // range of vulnerable versions
fixed_version_t *version; // version and specifier for the fixed versions
};
};

typedef struct vulnerable_pkg vuln_pkg_t;

/** brief define an advisory with a list of vulnerable packages
*/
struct advisory
{
char *oid; // Advisory OID
vuln_pkg_t *pkgs[100]; // list of vulnerable packages, installed version and
// fixed versions
size_t count; // Count of vulnerable packages this adivsory has
};

typedef struct advisory advisory_t;

/** brief define a advisories list
*/
struct advisories
{
advisory_t **advisories;
size_t count;
size_t max_size;
};
typedef struct advisories advisories_t;

/** @brief Initialize a new adivisories struct with 100 slots
/** @brief Initialize a new advisories struct with 100 slots
*
* @return initialized advisories_t struct. It must be free by the caller
* with advisories_free()
Expand All @@ -508,7 +443,7 @@ advisories_new ()
return advisories_list;
}

/** @brief Initialize a new adivisories struct with 100 slots
/** @brief Initialize a new advisories struct with 100 slots
*
* @param advisories_list[in/out] An advisories holder to add new advisories
into.
Expand All @@ -533,7 +468,7 @@ advisories_add (advisories_t *advisories_list, advisory_t *advisory)
advisories_list->count++;
}

/** @brief Initialize a new adivisory
/** @brief Initialize a new advisory
*
* @param oid The advisory's OID
*
Expand Down Expand Up @@ -574,7 +509,7 @@ advisory_add_vuln_pkg (advisory_t *adv, vuln_pkg_t *vuln)

/** @brief Free()'s an advisory
*
* @param advisory The adviosory to be free()'ed.
* @param advisory The advisory to be free()'ed.
* It free()'s all vulnerable packages that belong to this advisory.
*/
static void
Expand Down Expand Up @@ -607,10 +542,10 @@ advisory_free (advisory_t *advisory)

/** @brief Free()'s an advisories
*
* @param advisory The adviosories holder to be free()'ed.
* @param advisory The advisories holder to be free()'ed.
* It free()'s all advisories members.
*/
static void
void
advisories_free (advisories_t *advisories)
{
if (advisories == NULL)
Expand All @@ -629,11 +564,11 @@ advisories_free (advisories_t *advisories)
* Can be RANGE or SINGLE
* @param item1 Depending on the type is the "version" for SINGLE type,
* or the "less than" for RANGE type
* @param item2 Depending on the type is the "specifer" for SINGLE type,
* or the "greather than" for RANGE type
* @param item2 Depending on the type is the "specifier" for SINGLE type,
* or the "greater than" for RANGE type
*
* @return a vulnerable packages struct. Members are a copy of the passed
* parametes. They must be free separately.
* parameters. They must be free separately.
*/
static vuln_pkg_t *
vulnerable_pkg_new (const char *pkg_name, const char *install_version,
Expand Down Expand Up @@ -671,13 +606,13 @@ vulnerable_pkg_new (const char *pkg_name, const char *install_version,
* @description This is the body string in response get from an openvasd server
*
* @param resp String containing the json object to be processed.
* @param len String lenght.
* @param len String length.
*
* @return a advisories_t struct containing all advisories and vulnerable
* packages.
* After usage must be free()'ed with advisories_free().
*/
static advisories_t *
advisories_t *
process_notus_response (const gchar *resp, const size_t len)
{
JsonParser *parser = NULL;
Expand Down Expand Up @@ -979,7 +914,7 @@ send_request (notus_info_t notusdata, const char *os, const char *pkg_list,
* @return String containing the server response or NULL
* Must be free()'ed by the caller.
*/
static char *
char *
notus_get_response (const char *pkg_list, const char *os)
{
const char *server = NULL;
Expand All @@ -999,7 +934,7 @@ notus_get_response (const char *pkg_list, const char *os)
return NULL;
}

// Convert the packge list string into a string containing json
// Convert the package list string into a string containing json
// array of packages
if ((json_pkglist = make_package_list_as_json_str (pkg_list)) == NULL)
{
Expand All @@ -1020,10 +955,10 @@ notus_get_response (const char *pkg_list, const char *os)
/** @brief Call notus and stores the results
*
* @param ip_str Target's IP address.
* @param hostname Targer's hostname.
* @param hostname Target's hostname.
* @param pkg_list List of packages installed in the target. The packages are
* "\n" separated.
* @param os Name of the target's operative sistem.
* @param os Name of the target's operating system.
*
* @result Count of stored results. -1 on error.
*/
Expand Down Expand Up @@ -1055,7 +990,7 @@ call_rs_notus (const char *ip_str, const char *hostname, const char *pkg_list,
g_string_printf (res,
"\nVulnerable package: %s\n"
"Installed version: %s-%s\n"
"Fixed version: <=%s-%s\n"
"Fixed version: < %s-%s\n"
"Fixed version: >=%s-%s\n",
pkg->pkg_name, pkg->pkg_name,
pkg->install_version, pkg->pkg_name,
Expand Down Expand Up @@ -1212,7 +1147,7 @@ run_table_driven_lsc (const char *scan_id, const char *ip_str,
if (err == 1)
{
g_warning (
"%s: Unablet to retrieve message. Timeout after 60s.",
"%s: Unable to retrieve message. Timeout after 60s.",
__func__);
return -1;
}
Expand Down
74 changes: 74 additions & 0 deletions misc/table_driven_lsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,74 @@
#include <glib.h>
#include <gvm/util/kb.h> // for kb_t

/** @brief Fixed version format
*/
enum fixed_type
{
UNKNOWN, // Unknown
RANGE, // Range of version which fixed the package
SINGLE, // A single version with a specifier (gt or lt)
};

/** @brief Fixed version
*/
struct fixed_version
{
char *version; // a version
char *specifier; // a lt or gt specifier
};
typedef struct fixed_version fixed_version_t;

/** @brief Specify a version range
*/
struct version_range
{
char *start; // <= the version
char *stop; // >= the version
};
typedef struct version_range version_range_t;

/** @brief Define a vulnerable package
*/
struct vulnerable_pkg
{
char *pkg_name; // package name
char *install_version; // installed version of the vulnerable package
enum fixed_type type; // fixed version type: range or single
union
{
version_range_t *range; // range of vulnerable versions
fixed_version_t *version; // version and specifier for the fixed versions
};
};

typedef struct vulnerable_pkg vuln_pkg_t;

/** brief define an advisory with a list of vulnerable packages
*/
struct advisory
{
char *oid; // Advisory OID
vuln_pkg_t *pkgs[100]; // list of vulnerable packages, installed version and
// fixed versions
size_t count; // Count of vulnerable packages this advisory has
};

typedef struct advisory advisory_t;

/** brief define a advisories list
*/
struct advisories
{
advisory_t **advisories;
size_t count;
size_t max_size;
};
typedef struct advisories advisories_t;

void
advisories_free (advisories_t *advisories);

void
set_lsc_flag (void);

Expand All @@ -24,4 +92,10 @@ int
run_table_driven_lsc (const char *, const char *, const char *, const char *,
const char *);

char *
notus_get_response (const char *pkg_list, const char *os);

advisories_t *
process_notus_response (const gchar *resp, const size_t len);

#endif // MISC_TABLE_DRIVEN_LSC_H
1 change: 1 addition & 0 deletions nasl/nasl_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static init_func libfuncs[] = {
{"script_tag", script_tag},
{"vendor_version", nasl_vendor_version},
{"update_table_driven_lsc_data", nasl_update_table_driven_lsc_data},
{"table_driven_lsc", table_driven_lsc},
{"get_preference", nasl_get_preference},
{"safe_checks", safe_checks},
{"get_script_oid", get_script_oid},
Expand Down
Loading
Loading