Skip to content

Commit

Permalink
Get the qod value or qod type from the nvti structure and add the val…
Browse files Browse the repository at this point in the history
…ue to the result.
  • Loading branch information
jjnicola committed Jul 26, 2021
1 parent 7746639 commit ebe7080
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 4 deletions.
2 changes: 1 addition & 1 deletion misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ include_directories (${GLIB_INCLUDE_DIRS} ${GLIB_JSON_INCLUDE_DIRS}
# Library

set (FILES bpf_share.c ftp_funcs.c vendorversion.c network.c plugutils.c pcap.c
strutils.c)
nvt_qod.c strutils.c)


# On windows we are always PIC and stack-protector is replaces by DEP
Expand Down
81 changes: 81 additions & 0 deletions misc/nvt_qod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* Portions Copyright (C) 2009-2021 Greenbone Networks GmbH
* Based on work Copyright (C) 1998 - 2007 Tenable Network Security, Inc.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/**
* @file
* @brief Converts a qod_type string into a QoD value.
*
*/

#include "nvt_qod.h"
#include <glib.h>

#undef G_LOG_DOMAIN
/**
* @brief GLib logging domain.
*/
#define G_LOG_DOMAIN "lib misc"

static const struct {
qod_val val;
const char *type;
} qod_types[] = {
{EXPLOIT, "exploit"},
{REMOTE_VUL, "remote_vul"},
{REMOTE_APP, "remote_app"},
{PACKAGE, "package"},
{REGISTRY, "registry"},
{REMOTE_ACTIVE, "remote_active"},
{REMOTE_BANNER, "remote_banner"},
{EXECUTABLE_VERSION, "executable_version"},
{REMOTE_ANALYSIS, "remote_analysis"},
{REMOTE_PROBE, "remote_probe"},
{REMOTE_BANNER_UNRELIABLE, "remote_banner_unreliable"},
{EXECUTABLE_VERSION_UNRELIABLE, "executable_version_unreliable"},
{GENERAL_NOTE, "general_note"},
{DEFAULT, "default"}
};

/**
* @brief Converts a qod_type string into it value
*
* @param[in] qod_type String containing the qod type
*
* @return The value corresponding to the given qod type. Defaults to 70 if
* the given type does not exist. -1 if a null pointer was given.
*/
int
qod_type2val (const char *qod_type)
{
unsigned int i;

g_message ("GGGGG %s",qod_type);

if (!qod_type)
return -1;

for (i = 0; i < sizeof (qod_types) / sizeof (qod_types[i]); i++)
{
g_message ("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA %d %s",qod_types[i].val ,qod_types[i].type);
if (!g_strcmp0(qod_types[i].type, qod_type))
return qod_types[i].val;
}
return DEFAULT;
}
52 changes: 52 additions & 0 deletions misc/nvt_qod.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Portions Copyright (C) 2009-2021 Greenbone Networks GmbH
* Based on work Copyright (C) 1998 - 2007 Tenable Network Security, Inc.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/**
* @file nvt_qod_types.h
* @brief QOD_TYPES definitions.
*
* This file contains defines for the QoD types of NVTs.
*/

#ifndef _NVT_QOD_H
#define _NVT_QOD_H

typedef enum
{
EXPLOIT = 100,
REMOTE_VUL = 99,
REMOTE_APP = 98,
PACKAGE = 97,
REGISTRY = 97,
REMOTE_ACTIVE = 95,
REMOTE_BANNER = 80,
EXECUTABLE_VERSION = 80,
REMOTE_ANALYSIS = 70,
REMOTE_PROBE = 50,
REMOTE_BANNER_UNRELIABLE = 30,
EXECUTABLE_VERSION_UNRELIABLE = 30,
GENERAL_NOTE = 1,
DEFAULT = 70,
} qod_val;

int
qod_type2val (const char *);

#endif /* _NVT_QOD_H */
39 changes: 36 additions & 3 deletions misc/plugutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
#include "plugutils.h"

#include "network.h" // for OPENVAS_ENCAPS_IP
#include "nvt_qod.h" // for qod_str2val

#include <errno.h> // for errno
#include <gvm/base/cvss.h> // for get_cvss_score_from_base_metrics
#include <gvm/base/hosts.h> // for g_vhost_t
#include <gvm/base/networking.h> // for port_protocol_t
#include <gvm/base/prefs.h> // for prefs_get_bool
#include <gvm/util/mqtt.h> // for mqtt_reset
#include <gvm/util/nvticache.h> // for nvticache_initialized
#include <gvm/util/mqtt.h> // for mqtt_reset
#include <gvm/util/nvticache.h> // for nvticache_initialized
#include <json-glib/json-glib.h>
#include <stdio.h> // for snprintf
#include <stdlib.h> // for exit
Expand Down Expand Up @@ -433,6 +434,35 @@ get_severity_score_from_vt (nvti_t *nvti)
return score_str;
}

/**
* @brief Get the nvti's QoD and return the value as
* string.
*
* @param[in] nvti The nvti where to get the QoD from.
*
* @return string representing an integer value, NULL on error.
* Must be free()'d by the caller.
*/
static gchar *
get_qod_from_vt (nvti_t *nvti)
{
int qod;
gchar *qod_str, *qod_type;

qod_str = NULL;
qod_type = nvti_get_tag (nvti, "qod_type");
if (qod_type)
{
qod = qod_type2val (qod_type);
qod_str = g_strdup_printf ("%i", qod);
g_free (qod_type);
return qod_str;
}

qod_str = nvti_get_tag (nvti, "qod");
return qod_str;
}

/**
* @brief Build a json representation of the part related to nvti information
* of a result.
Expand All @@ -449,6 +479,7 @@ add_nvti_info_into_json_builder (const char *oid, JsonBuilder *builder)
{
nvti_t *nvti;
gchar *score_str;
gchar *qod;

nvti = nvticache_get_nvt (oid);

Expand All @@ -461,8 +492,10 @@ add_nvti_info_into_json_builder (const char *oid, JsonBuilder *builder)
json_builder_set_member_name (builder, "name");
builder = json_builder_add_string_value (builder, nvti_name (nvti));

qod = get_qod_from_vt (nvti);
json_builder_set_member_name (builder, "qod");
builder = json_builder_add_string_value (builder, nvti_qod (nvti));
builder = json_builder_add_string_value (builder, qod);
g_free (qod);

score_str = get_severity_score_from_vt (nvti);
json_builder_set_member_name (builder, "severity");
Expand Down

0 comments on commit ebe7080

Please sign in to comment.