17#define G_LOG_DOMAIN "libgvm util"
29 if (!g_strcmp0 (cat,
"init"))
31 else if (!g_strcmp0 (cat,
"scanner"))
33 else if (!g_strcmp0 (cat,
"settings"))
35 else if (!g_strcmp0 (cat,
"gather_info"))
37 else if (!g_strcmp0 (cat,
"attack"))
39 else if (!g_strcmp0 (cat,
"mixed_attack"))
41 else if (!g_strcmp0 (cat,
"destructive_attack"))
43 else if (!g_strcmp0 (cat,
"denial"))
45 else if (!g_strcmp0 (cat,
"kill_host"))
47 else if (!g_strcmp0 (cat,
"flood"))
49 else if (!g_strcmp0 (cat,
"end"))
58 if (cJSON_IsObject (tag_obj))
60 gchar *severity_vector, *str;
88 g_debug (
"%s: SOLUTION: missing type for OID: %s", __func__,
106 if (!severity_vector)
111 gchar *severity_type, *cvss_base;
112 double cvss_base_dbl;
114 if (g_strrstr (severity_vector,
"CVSS:3"))
115 severity_type = g_strdup (
"cvss_base_v3");
117 severity_type = g_strdup (
"cvss_base_v2");
125 cvss_base_dbl, severity_vector));
127 nvti_add_tag (nvt,
"cvss_base_vector", severity_vector);
129 cvss_base = g_strdup_printf (
134 g_free (severity_type);
139 g_warning (
"%s: SEVERITY missing value element", __func__);
151 item = cJSON_GetObjectItem (vt_obj,
"references");
152 if (item != NULL && cJSON_IsArray (item))
155 cJSON_ArrayForEach (ref_obj, item)
159 if (!cJSON_IsObject (ref_obj))
160 g_debug (
"%s: Error reading VT/REFS reference object", __func__);
163 g_warning (
"%s: REF missing class attribute", __func__);
166 g_warning (
"%s: REF missing ID attribute", __func__);
179 item = cJSON_GetObjectItem (vt_obj,
"preferences");
182 if (!cJSON_IsArray (item))
183 g_debug (
"%s: Error reading VT/REFS array", __func__);
186 cJSON *prefs_obj = NULL;
188 cJSON_ArrayForEach (prefs_obj, item)
190 gchar *
class, *name, *default_val;
193 if (!cJSON_IsObject (prefs_obj))
194 g_debug (
"%s: Error reading VT/PREFS preference object",
198 g_warning (
"%s: PREF missing class attribute", __func__);
201 g_warning (
"%s: PREF missing id attribute", __func__);
204 g_warning (
"%s: PREF missing name attribute", __func__);
208 g_warning (
"%s: PREF missing default attribute", __func__);
232 cJSON *vt_obj = NULL;
233 gchar *str, *error_message = NULL;
243 g_debug (
"%s: Start parsing feed", __func__);
245 else if (!g_strcmp0 (path,
"$")
249 g_debug (
"%s: Finish parsing feed", __func__);
258 g_warning (
"%s: Error reading VT object", __func__);
263 if (!cJSON_IsObject (vt_obj))
265 g_free (error_message);
266 cJSON_Delete (vt_obj);
269 g_free (error_message);
275 g_warning (
"%s: VT missing OID", __func__);
276 cJSON_Delete (vt_obj);
284 g_warning (
"%s: VT missing NAME", __func__);
285 cJSON_Delete (vt_obj);
293 g_warning (
"%s: VT missing FAMILY", __func__);
294 cJSON_Delete (vt_obj);
302 g_warning (
"%s: VT missing CATEGORY", __func__);
303 cJSON_Delete (vt_obj);
309 cJSON *tag_obj = cJSON_GetObjectItem (vt_obj,
"tag");
315 cJSON_Delete (vt_obj);
double get_cvss_score_from_base_metrics(const char *cvss_str)
Calculate CVSS Score.
Definition cvss.c:585
double gvm_json_obj_double(cJSON *obj, const gchar *key)
Get a double field from a JSON object.
Definition json.c:75
int gvm_json_obj_check_int(cJSON *obj, const gchar *key, int *val)
Get an int field from a JSON object.
Definition json.c:97
gchar * gvm_json_obj_str(cJSON *obj, const gchar *key)
Get a string field from a JSON object.
Definition json.c:165
int gvm_json_obj_check_str(cJSON *obj, const gchar *key, gchar **val)
Get a string field from a JSON object.
Definition json.c:142
void gvm_json_pull_parser_next(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event)
Get the next event from a JSON pull parser.
Definition jsonpull.c:669
gchar * gvm_json_path_to_string(GQueue *path)
Converts a path as used by a JSON pull parser to a JSONPath string.
Definition jsonpull.c:902
cJSON * gvm_json_pull_expand_container(gvm_json_pull_parser_t *parser, gchar **error_message)
Expands the current array or object of a JSON pull parser.
Definition jsonpull.c:744
@ GVM_JSON_PULL_EVENT_OBJECT_START
Definition jsonpull.h:45
@ GVM_JSON_PULL_EVENT_EOF
Definition jsonpull.h:51
@ GVM_JSON_PULL_EVENT_ARRAY_END
Definition jsonpull.h:44
@ GVM_JSON_PULL_EVENT_ARRAY_START
Definition jsonpull.h:43
nvti_t * nvti_new(void)
Create a new (empty) nvti structure.
Definition nvti.c:559
int nvti_set_qod(nvti_t *n, const gchar *qod)
Set the QoD of a NVT.
Definition nvti.c:1880
int nvti_set_solution(nvti_t *n, const gchar *solution)
Set the solution of a NVT.
Definition nvti.c:1472
int nvti_set_solution_type(nvti_t *n, const gchar *solution_type)
Set the solution type of a NVT.
Definition nvti.c:1513
struct nvti nvti_t
The structure of a information record that corresponds to a NVT.
int nvti_set_qod_type(nvti_t *n, const gchar *qod_type)
Set the QoD type of a NVT.
Definition nvti.c:1856
int nvti_set_oid(nvti_t *n, const gchar *oid)
Set the OID of a NVT Info.
Definition nvti.c:1214
int nvti_set_cvss_base(nvti_t *n, const gchar *cvss_base)
Set the CVSS base of an NVT.
Definition nvti.c:1648
int nvti_set_impact(nvti_t *n, const gchar *impact)
Set the impact text of a NVT.
Definition nvti.c:1394
int nvti_set_summary(nvti_t *n, const gchar *summary)
Set the summary of a NVT.
Definition nvti.c:1274
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
Definition nvti.c:611
nvtpref_t * nvtpref_new(int id, const gchar *name, const gchar *type, const gchar *dflt)
Create a new nvtpref structure filled with the given values.
Definition nvti.c:463
int nvti_add_pref(nvti_t *n, nvtpref_t *np)
Add a preference to the NVT Info.
Definition nvti.c:2180
int nvti_set_insight(nvti_t *n, const gchar *insight)
Set the insight text of a NVT.
Definition nvti.c:1314
vtref_t * vtref_new(const gchar *type, const gchar *ref_id, const gchar *ref_text)
Create a new vtref structure filled with the given values.
Definition nvti.c:77
int nvti_add_vtseverity(nvti_t *vt, vtseverity_t *s)
Add a severity to the VT Info.
Definition nvti.c:426
int nvti_set_solution_method(nvti_t *n, const gchar *solution_method)
Set the solution method of a NVT.
Definition nvti.c:1534
int nvti_set_name(nvti_t *n, const gchar *name)
Set the name of a NVT.
Definition nvti.c:1234
vtseverity_t * vtseverity_new(const gchar *type, const gchar *origin, int date, double score, const gchar *value)
Create a new vtseverity structure filled with the given values.
Definition nvti.c:180
int nvti_set_modification_time(nvti_t *n, const time_t modification_time)
Set the modification time of a NVT.
Definition nvti.c:1453
int nvti_set_creation_time(nvti_t *n, const time_t creation_time)
Set the creation time of a NVT.
Definition nvti.c:1434
int nvti_set_family(nvti_t *n, const gchar *family)
Set the family of a NVT.
Definition nvti.c:1903
int nvti_set_affected(nvti_t *n, const gchar *affected)
Set the affected text of a NVT.
Definition nvti.c:1354
int nvti_add_tag(nvti_t *n, const gchar *name, const gchar *value)
Add a tag to the NVT tags. The tag names "severity_date", "last_modification" and "creation_date" are...
Definition nvti.c:1561
int nvti_set_detection(nvti_t *n, const gchar *detection)
Set the detection text of a NVT.
Definition nvti.c:1815
int nvti_set_category(nvti_t *n, const gint category)
Set the category type of a NVT Info.
Definition nvti.c:1943
void nvti_free(nvti_t *n)
Free memory of a nvti structure.
Definition nvti.c:570
int nvti_add_vtref(nvti_t *vt, vtref_t *ref)
Add a reference to the VT Info.
Definition nvti.c:408
Event generated by the JSON pull parser.
Definition jsonpull.h:59
GQueue * path
Path to the event value.
Definition jsonpull.h:61
gvm_json_pull_event_type_t type
Type of event.
Definition jsonpull.h:60
A json pull parser.
Definition jsonpull.h:86
int parse_vt_json(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, nvti_t **nvt)
Parse a VT element given in json format.
Definition vtparser.c:229
static void add_preferences_to_nvt(nvti_t *nvt, cJSON *vt_obj)
Definition vtparser.c:175
static int get_category_from_name(const gchar *cat)
Get the VT category type given the category as string.
Definition vtparser.c:27
static void parse_references(nvti_t *nvt, cJSON *vt_obj)
Definition vtparser.c:147
static void add_tags_to_nvt(nvti_t *nvt, cJSON *tag_obj)
Definition vtparser.c:56
@ ACT_KILL_HOST
Definition vtparser.h:39
@ ACT_DESTRUCTIVE_ATTACK
Definition vtparser.h:37
@ ACT_SCANNER
Definition vtparser.h:32
@ ACT_END
Definition vtparser.h:41
@ ACT_FLOOD
Definition vtparser.h:40
@ ACT_GATHER_INFO
Definition vtparser.h:34
@ ACT_DENIAL
Definition vtparser.h:38
@ ACT_ATTACK
Definition vtparser.h:35
@ ACT_SETTINGS
Definition vtparser.h:33
@ ACT_MIXED_ATTACK
Definition vtparser.h:36
@ ACT_INIT
Definition vtparser.h:31