47#define G_LOG_DOMAIN "libgvm base"
78vtref_new (
const gchar *type,
const gchar *ref_id,
const gchar *ref_text)
83 ref->
type = g_strdup (type);
85 ref->
ref_id = g_strdup (ref_id);
120 return r ? r->
type : NULL;
134 return r ? r->
ref_id : NULL;
188 s->
type = g_strdup (type);
190 s->
origin = g_strdup (origin);
194 s->
value = g_strdup (value);
227 return s ? s->
type : NULL;
241 return s ? s->
origin : NULL;
255 return s ? s->
value : NULL;
303 if ((strcmp ((
char *) str_time,
"") == 0)
304 || (strcmp ((
char *) str_time,
"$Date: $") == 0)
305 || (strcmp ((
char *) str_time,
"$Date$") == 0)
306 || (strcmp ((
char *) str_time,
"$Date:$") == 0)
307 || (strcmp ((
char *) str_time,
"$Date") == 0)
308 || (strcmp ((
char *) str_time,
"$$") == 0))
318 memset (&tm, 0,
sizeof (
struct tm));
319 if (strptime ((
char *) str_time,
"%Y-%m-%d %T +%H%M", &tm) == NULL && strptime ((
char *) str_time,
"%Y-%m-%d %T -%H%M", &tm) == NULL)
321 memset (&tm, 0,
sizeof (
struct tm));
322 if (strptime ((
char *) str_time,
"$Date: %Y-%m-%d %T +%H%M", &tm) == NULL && strptime ((
char *) str_time,
"$Date: %Y-%m-%d %T -%H%M", &tm) == NULL)
324 memset (&tm, 0,
sizeof (
struct tm));
325 if (strptime ((
char *) str_time,
"%a %b %d %T %Y +%H%M", &tm) == NULL && strptime ((
char *) str_time,
"%a %b %d %T %Y -%H%M", &tm) == NULL)
327 memset (&tm, 0,
sizeof (
struct tm));
328 if (strptime ((
char *) str_time,
"$Date: %a, %d %b %Y %T +%H%M", &tm) == NULL && strptime ((
char *) str_time,
"$Date: %a, %d %b %Y %T -%H%M", &tm) == NULL)
330 memset (&tm, 0,
sizeof (
struct tm));
331 if (strptime ((
char *) str_time,
"$Date: %a %b %d %T %Y +%H%M", &tm) == NULL && strptime ((
char *) str_time,
"$Date: %a %b %d %T %Y -%H%M", &tm) == NULL)
333 g_warning (
"%s: Failed to parse time: %s", __func__,
341 epoch_time = mktime (&tm);
342 if (epoch_time == -1)
344 g_warning (
"%s: Failed to make time: %s", __func__, str_time);
350 if ((sscanf ((
char *) str_time,
"%*u-%*u-%*u %*u:%*u:%*u %d%*[^]]", &offset)
352 && (sscanf ((
char *) str_time,
"$Date: %*u-%*u-%*u %*u:%*u:%*u %d%*[^]]",
355 && (sscanf ((
char *) str_time,
"%*s %*s %*s %*u:%*u:%*u %*u %d%*[^]]",
358 && (sscanf ((
char *) str_time,
359 "$Date: %*s %*s %*s %*u %*u:%*u:%*u %d%*[^]]", &offset)
361 && (sscanf ((
char *) str_time,
362 "$Date: %*s %*s %*s %*u:%*u:%*u %*u %d%*[^]]", &offset)
365 g_warning (
"%s: Failed to parse timezone offset: %s", __func__, str_time);
373 epoch_time += ((-offset) / 100) * 60 * 60;
374 epoch_time += ((-offset) % 100) * 60;
378 epoch_time -= (offset / 100) * 60 * 60;
379 epoch_time -= (offset % 100) * 60;
446 vt->
refs = g_slist_append (vt->
refs, ref);
497nvtpref_new (
int id,
const gchar *name,
const gchar *type,
const gchar *dflt)
503 np->
name = g_strdup (name);
505 np->
type = g_strdup (type);
507 np->
dflt = g_strdup (dflt);
540 return np ? np->
id : -1;
554 return np ? np->
name : NULL;
568 return np ? np->
type : NULL;
582 return np ? np->
dflt : NULL;
648 return n ? n->
oid : NULL;
662 return n ? n->
name : NULL;
718 return n ? n->
impact : NULL;
759 return n ? g_slist_length (n->
refs) : 0;
774 return n ? g_slist_nth_data (n->
refs, p) : NULL;
804 gchar *refs, *refs2, **exclude_item;
807 gchar **exclude_split;
816 if (exclude_types && exclude_types[0])
817 exclude_split = g_strsplit (exclude_types,
",", 0);
819 exclude_split = NULL;
821 for (i = 0; i < g_slist_length (n->
refs); i++)
823 ref = g_slist_nth_data (n->
refs, i);
824 if (type && strcasecmp (ref->
type, type) != 0)
830 for (exclude_item = exclude_split; *exclude_item; exclude_item++)
832 if (strcasecmp (g_strstrip (*exclude_item), ref->
type) == 0)
846 g_strdup_printf (
"%s, %s:%s", refs, ref->
type, ref->
ref_id);
848 refs2 = g_strdup_printf (
"%s:%s", ref->
type, ref->
ref_id);
853 refs2 = g_strdup_printf (
"%s, %s", refs, ref->
ref_id);
855 refs2 = g_strdup_printf (
"%s", ref->
ref_id);
862 g_strfreev (exclude_split);
877 return n ? g_slist_length (n->
severities) : 0;
892 return n ? g_slist_nth_data (n->
severities, p) : NULL;
1003 return n ? n->
tag : NULL;
1019 gchar **split, **point;
1021 if (!n || n->
tag == NULL || !name)
1024 split = g_strsplit (n->
tag,
"|", 0);
1029 if ((strlen (*point) > strlen (name))
1030 && (strncmp (*point, name, strlen (name)) == 0)
1031 && ((*point)[strlen (name)] ==
'='))
1034 ret = g_strdup (*point + strlen (name) + 1);
1181 return n ? n->
qod : NULL;
1195 return n ? n->
family : NULL;
1208 return n ? g_slist_length (n->
prefs) : 0;
1223 return n ? g_slist_nth_data (n->
prefs, p) : NULL;
1255 n->
oid = g_strdup (oid);
1275 n->
name = g_strdup (name);
1315 n->
summary = g_strdup (summary);
1355 n->
insight = g_strdup (insight);
1435 n->
impact = g_strdup (impact);
1598 gchar *newvalue = NULL;
1603 if (!name || !name[0])
1606 if (!value || !value[0])
1609 if (!strcmp (name,
"last_modification"))
1614 else if (!strcmp (name,
"creation_date"))
1619 else if (!strcmp (name,
"severity_date"))
1621 else if (!strcmp (name,
"cvss_base"))
1638 g_strconcat (n->
tag,
"|", name,
"=", newvalue ? newvalue : value, NULL);
1643 n->
tag = g_strconcat (name,
"=", newvalue ? newvalue : value, NULL);
1667 n->
tag = g_strdup (tag);
1689 if (cvss_base && cvss_base[0])
1713 if (dependencies && dependencies[0])
1737 if (required_keys && required_keys[0])
1761 if (mandatory_keys && mandatory_keys[0])
1785 if (excluded_keys && excluded_keys[0])
1809 if (required_ports && required_ports[0])
1833 if (required_udp_ports && required_udp_ports[0])
1897 if (qod_type && qod_type[0])
1922 n->
qod = g_strdup (qod);
1944 n->
family = g_strdup (family);
2004 const gchar *ref_text)
2006 gchar **split, **item;
2014 split = g_strsplit (ref_ids,
",", 0);
2016 for (item = split; *item; item++)
2023 if (strcmp (
id,
"") == 0)
2034 split2 = g_strsplit (
id,
":", 2);
2035 if (split2[0] && split2[1])
2037 g_strfreev (split2);
2245 return g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
2258 g_hash_table_destroy (nvtis);
2271 g_hash_table_insert (
2287 return g_hash_table_lookup (nvtis, oid);
vtref_t * nvti_vtref(const nvti_t *n, guint p)
Get the n'th reference of the NVT.
Definition nvti.c:772
struct vtseverity vtseverity_t
The structure for a severity of a VT.
nvti_t * nvti_new(void)
Create a new (empty) nvti structure.
Definition nvti.c:594
int nvti_put_impact(nvti_t *n, gchar *impact)
Set the impact text of a NVT, using the given memory.
Definition nvti.c:1449
void vtseverity_free(vtseverity_t *s)
Free memory of a vtseverity structure.
Definition nvti.c:205
gchar * nvti_dependencies(const nvti_t *n)
Get the dependencies list.
Definition nvti.c:1067
int nvti_add_required_keys(nvti_t *n, const gchar *key)
Add a required key of a NVT.
Definition nvti.c:2055
guint nvti_pref_len(const nvti_t *n)
Get the number of preferences of the NVT.
Definition nvti.c:1206
int nvti_set_qod(nvti_t *n, const gchar *qod)
Set the QoD of a NVT.
Definition nvti.c:1915
gchar * nvti_detection(const nvti_t *n)
Get the text about detection.
Definition nvti.c:1151
gchar * nvti_required_udp_ports(const nvti_t *n)
Get the required udp ports list.
Definition nvti.c:1137
int nvti_set_solution(nvti_t *n, const gchar *solution)
Set the solution of a NVT.
Definition nvti.c:1507
gchar * nvti_get_tag(const nvti_t *n, const gchar *name)
Get a tag value by a tag name.
Definition nvti.c:1017
gchar * nvti_summary(const nvti_t *n)
Get the summary.
Definition nvti.c:674
int nvti_set_solution_type(nvti_t *n, const gchar *solution_type)
Set the solution type of a NVT.
Definition nvti.c:1548
gchar * nvti_required_ports(const nvti_t *n)
Get the required ports list.
Definition nvti.c:1123
int nvti_put_insight(nvti_t *n, gchar *insight)
Set the insight text of a NVT, using the given memory.
Definition nvti.c:1369
gchar * nvti_refs(const nvti_t *n, const gchar *type, const gchar *exclude_types, guint use_types)
Get references as string.
Definition nvti.c:801
double nvti_severity_score(const nvti_t *n)
Get the maximum severity score.
Definition nvti.c:903
gchar * nvtpref_type(const nvtpref_t *np)
Get the Type of a NVT Preference.
Definition nvti.c:566
int nvti_set_excluded_keys(nvti_t *n, const gchar *excluded_keys)
Set the excluded keys of a NVT.
Definition nvti.c:1779
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:1891
int nvti_add_excluded_keys(nvti_t *n, const gchar *key)
Add a excluded key of a NVT.
Definition nvti.c:2119
int nvti_put_detection(nvti_t *n, gchar *detection)
Set the detection text of a NVT, using the given memory.
Definition nvti.c:1870
nvtis_t * nvtis_new(void)
Make a collection of NVT Infos.
Definition nvti.c:2243
int nvti_set_dependencies(nvti_t *n, const gchar *dependencies)
Set the dependencies of a NVT.
Definition nvti.c:1707
int nvti_set_required_ports(nvti_t *n, const gchar *required_ports)
Set the required ports of a NVT.
Definition nvti.c:1803
int nvti_set_oid(nvti_t *n, const gchar *oid)
Set the OID of a NVT Info.
Definition nvti.c:1249
int nvti_add_required_udp_ports(nvti_t *n, const gchar *port)
Add a required udp port of a NVT.
Definition nvti.c:2183
int nvti_set_tag(nvti_t *n, const gchar *tag)
Set the tags of a NVT.
Definition nvti.c:1660
int nvti_set_cvss_base(nvti_t *n, const gchar *cvss_base)
Set the CVSS base of an NVT.
Definition nvti.c:1683
int nvti_set_mandatory_keys(nvti_t *n, const gchar *mandatory_keys)
Set the mandatory keys of a NVT.
Definition nvti.c:1755
int nvti_put_name(nvti_t *n, gchar *name)
Set the name of a NVT, using the given memory.
Definition nvti.c:1289
int nvti_put_family(nvti_t *n, gchar *family)
Set the family of a NVT, using the given memory.
Definition nvti.c:1958
gint nvti_category(const nvti_t *n)
Get the category for this NVT.
Definition nvti.c:1234
int nvti_set_impact(nvti_t *n, const gchar *impact)
Set the impact text of a NVT.
Definition nvti.c:1429
const gchar * vtseverity_type(const vtseverity_t *s)
Get the type of a severity.
Definition nvti.c:225
int nvti_add_required_ports(nvti_t *n, const gchar *port)
Add a required port of a NVT.
Definition nvti.c:2151
struct nvtpref nvtpref_t
The structure for a preference of a NVT.
gchar * nvti_family(const nvti_t *n)
Get the family name.
Definition nvti.c:1193
gchar * nvti_severity_vector_from_tag(const nvti_t *n)
Get the severity score.
Definition nvti.c:935
struct vtref vtref_t
The structure for a cross reference of a VT.
static void free_nvti_for_hash_table(gpointer nvti)
Free an NVT Info, for g_hash_table_destroy.
Definition nvti.c:2232
gchar * nvti_solution_method(const nvti_t *n)
Get the solution method.
Definition nvti.c:987
guint nvti_vtseverities_len(const nvti_t *n)
Get the number of severities of the NVT.
Definition nvti.c:875
const nvtpref_t * nvti_pref(const nvti_t *n, guint p)
Get the n'th preferences of the NVT.
Definition nvti.c:1221
gchar * nvti_qod(const nvti_t *n)
Get the QoD.
Definition nvti.c:1179
gchar * nvti_excluded_keys(const nvti_t *n)
Get the excluded keys list.
Definition nvti.c:1109
int nvti_set_summary(nvti_t *n, const gchar *summary)
Set the summary of a NVT.
Definition nvti.c:1309
gchar * nvti_name(const nvti_t *n)
Get the name.
Definition nvti.c:660
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
Definition nvti.c:646
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:497
int nvti_put_affected(nvti_t *n, gchar *affected)
Set the affected text of a NVT, using the given memory.
Definition nvti.c:1409
int nvti_put_solution(nvti_t *n, gchar *solution)
Set the solution of a NVT, using the given memory.
Definition nvti.c:1527
double vtseverity_score(const vtseverity_t *s)
Get the score of a severity.
Definition nvti.c:281
const gchar * vtref_type(const vtref_t *r)
Get the type of a reference.
Definition nvti.c:118
int nvti_add_pref(nvti_t *n, nvtpref_t *np)
Add a preference to the NVT Info.
Definition nvti.c:2215
int nvti_put_summary(nvti_t *n, gchar *summary)
Set the summary of a NVT, using the given memory.
Definition nvti.c:1329
const gchar * vtseverity_value(const vtseverity_t *s)
Get the value of a severity.
Definition nvti.c:253
int nvti_set_insight(nvti_t *n, const gchar *insight)
Set the insight text of a NVT.
Definition nvti.c:1349
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:78
gchar * nvti_cvss_base(const nvti_t *n)
Get the CVSS base.
Definition nvti.c:1053
int nvti_set_required_keys(nvti_t *n, const gchar *required_keys)
Set the required keys of a NVT.
Definition nvti.c:1731
int nvti_add_vtseverity(nvti_t *vt, vtseverity_t *s)
Add a severity to the VT Info.
Definition nvti.c:459
void nvtpref_free(nvtpref_t *np)
Free memory of a nvtpref structure.
Definition nvti.c:518
int nvti_set_solution_method(nvti_t *n, const gchar *solution_method)
Set the solution method of a NVT.
Definition nvti.c:1569
int nvtpref_id(const nvtpref_t *np)
Get the ID of a NVT Preference.
Definition nvti.c:538
int nvti_set_name(nvti_t *n, const gchar *name)
Set the name of a NVT.
Definition nvti.c:1269
nvti_t * nvtis_lookup(nvtis_t *nvtis, const char *oid)
Add an NVT Info to a collection of NVT Infos.
Definition nvti.c:2285
gchar * nvti_qod_type(const nvti_t *n)
Get the QoD type.
Definition nvti.c:1165
int nvti_add_mandatory_keys(nvti_t *n, const gchar *key)
Add a mandatory key of a NVT.
Definition nvti.c:2087
time_t nvti_creation_time(const nvti_t *n)
Get the creation time.
Definition nvti.c:730
gchar * nvti_affected(const nvti_t *n)
Get the text about affected systems.
Definition nvti.c:702
vtseverity_t * nvti_vtseverity(const nvti_t *n, guint p)
Get the n'th reference of the NVT.
Definition nvti.c:890
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:182
gchar * nvti_solution(const nvti_t *n)
Get the solution.
Definition nvti.c:959
int nvti_set_modification_time(nvti_t *n, const time_t modification_time)
Set the modification time of a NVT.
Definition nvti.c:1488
int nvti_set_creation_time(nvti_t *n, const time_t creation_time)
Set the creation time of a NVT.
Definition nvti.c:1469
gchar * nvti_required_keys(const nvti_t *n)
Get the required keys list.
Definition nvti.c:1081
gchar * nvti_insight(const nvti_t *n)
Get the text about insight.
Definition nvti.c:688
int nvti_add_refs(nvti_t *n, const gchar *type, const gchar *ref_ids, const gchar *ref_text)
Add many new vtref from a comma-separated list.
Definition nvti.c:2003
time_t nvti_modification_time(const nvti_t *n)
Get the modification time.
Definition nvti.c:744
void vtref_free(vtref_t *ref)
Free memory of a vtref structure.
Definition nvti.c:98
const gchar * vtseverity_origin(const vtseverity_t *s)
Get the origin of a severity.
Definition nvti.c:239
guint nvti_vtref_len(const nvti_t *n)
Get the number of references of the NVT.
Definition nvti.c:757
int nvti_set_required_udp_ports(nvti_t *n, const gchar *required_udp_ports)
Set the required udp ports of a NVT.
Definition nvti.c:1827
gchar * nvti_mandatory_keys(const nvti_t *n)
Get the mandatory keys list.
Definition nvti.c:1095
gchar * nvtpref_default(const nvtpref_t *np)
Get the Default of a NVT Preference.
Definition nvti.c:580
int nvti_set_family(nvti_t *n, const gchar *family)
Set the family of a NVT.
Definition nvti.c:1938
gchar * nvtpref_name(const nvtpref_t *np)
Get the Name of a NVT Preference.
Definition nvti.c:552
static time_t parse_nvt_timestamp(const gchar *str_time)
Try convert an NVT tag time string into epoch time or return 0 upon parse errors.
Definition nvti.c:297
int nvti_set_affected(nvti_t *n, const gchar *affected)
Set the affected text of a NVT.
Definition nvti.c:1389
int vtseverity_date(const vtseverity_t *s)
Get the date of a severity.
Definition nvti.c:267
gchar * nvti_solution_type(const nvti_t *n)
Get the solution type.
Definition nvti.c:973
const gchar * vtref_id(const vtref_t *r)
Get the id of a reference.
Definition nvti.c:132
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:1596
void nvtis_add(nvtis_t *nvtis, nvti_t *nvti)
Add an NVT Info to a collection of NVT Infos.
Definition nvti.c:2268
gchar * nvti_impact(const nvti_t *n)
Get the text about impact.
Definition nvti.c:716
const gchar * vtref_text(const vtref_t *r)
Get the text of a reference.
Definition nvti.c:146
void nvtis_free(nvtis_t *nvtis)
Free a collection of NVT Infos.
Definition nvti.c:2255
int nvti_set_detection(nvti_t *n, const gchar *detection)
Set the detection text of a NVT.
Definition nvti.c:1850
gchar * nvti_tag(const nvti_t *n)
Get the tags.
Definition nvti.c:1001
int nvti_set_category(nvti_t *n, const gint category)
Set the category type of a NVT Info.
Definition nvti.c:1978
void nvti_free(nvti_t *n)
Free memory of a nvti structure.
Definition nvti.c:605
int nvti_add_vtref(nvti_t *vt, vtref_t *ref)
Add a reference to the VT Info.
Definition nvti.c:441
Protos and data structures for NVT Information data sets.
GHashTable nvtis_t
A collection of information records corresponding to NVTs.
Definition nvti.h:252
The structure of a information record that corresponds to a NVT.
Definition nvti.c:391
gchar * solution_method
The solution method.
Definition nvti.c:405
gchar * insight
The insight.
Definition nvti.c:396
gchar * affected
Affected systems.
Definition nvti.c:397
gchar * cvss_base
CVSS base score for this NVT.
Definition nvti.c:408
gchar * required_keys
List of required KB keys of this NVT.
Definition nvti.c:411
time_t creation_time
Time of creation, seconds since epoch.
Definition nvti.c:400
gchar * solution
The solution.
Definition nvti.c:403
gchar * impact
Impact of vulnerability.
Definition nvti.c:398
gchar * family
Family the NVT belongs to.
Definition nvti.c:428
gchar * excluded_keys
List of excluded KB keys of this NVT.
Definition nvti.c:413
gchar * required_udp_ports
List of required UDP ports of this NVT.
Definition nvti.c:416
GSList * refs
Collection of VT references.
Definition nvti.c:422
gchar * tag
List of tags attached to this NVT.
Definition nvti.c:407
gchar * oid
Object ID.
Definition nvti.c:392
gchar * name
The name.
Definition nvti.c:393
gint category
The category, this NVT belongs to.
Definition nvti.c:427
gchar * qod_type
Quality of detection type.
Definition nvti.c:419
GSList * severities
Collection of VT severities.
Definition nvti.c:423
gchar * mandatory_keys
List of mandatory KB keys of this NVT.
Definition nvti.c:412
gchar * detection
Detection description.
Definition nvti.c:418
gchar * solution_type
The solution type.
Definition nvti.c:404
gchar * dependencies
List of dependencies of this NVT.
Definition nvti.c:410
gchar * qod
Quality of detection.
Definition nvti.c:420
time_t modification_time
Time of last change, sec. since epoch.
Definition nvti.c:401
gchar * required_ports
List of required ports of this NVT.
Definition nvti.c:414
gchar * summary
The summary.
Definition nvti.c:395
GSList * prefs
Collection of NVT preferences.
Definition nvti.c:424
The structure for a preference of a NVT.
Definition nvti.c:474
gchar * type
Preference type.
Definition nvti.c:476
gchar * dflt
Default value of the preference.
Definition nvti.c:478
int id
Preference ID.
Definition nvti.c:475
gchar * name
Name of the preference.
Definition nvti.c:477
The structure for a cross reference of a VT.
Definition nvti.c:58
gchar * type
Reference type ("cve", "bid", ...)
Definition nvti.c:59
gchar * ref_id
Actual reference ID ("CVE-2018-1234", etc)
Definition nvti.c:60
gchar * ref_text
Optional additional text.
Definition nvti.c:61
The structure for a severity of a VT.
Definition nvti.c:159
gchar * origin
Definition nvti.c:161
int date
Timestamp in seconds since epoch, defaults to VT creation date.
Definition nvti.c:163
double score
The score derived from the value in range [0.0-10.0].
Definition nvti.c:164
gchar * value
The value which corresponds to the type.
Definition nvti.c:165
gchar * type
Severity type ("cvss_base_v2", ...)
Definition nvti.c:160