cvss_v2 (cvss v0.1.1)

View Source

CVSS 2.0 parsing, composition, validation, and scoring.

Use this module when working with CVSS 2.0 vectors directly. If the version is not known ahead of time, use cvss instead.

Vector format: AV:N/AC:L/Au:N/C:P/I:P/A:C

See: https://www.first.org/cvss/v2/guide

Summary

Functions

Calculate the CVSS 2.0 Base Score.

Compose a CVSS 2.0 record into a vector string.

Calculate the CVSS 2.0 Environmental Score. Returns the Temporal Score if no environmental metrics are present.

Parse a CVSS 2.0 vector string. Format: AV:N/AC:L/Au:N/C:P/I:P/A:C (parentheses optional)

Calculate the CVSS 2.0 score. Returns the most relevant score: Environmental > Temporal > Base.

Calculate the CVSS 2.0 Temporal Score. Returns the Base Score if no temporal metrics are present.

Check whether a CVSS 2.0 value is valid.

Types

ac()

-type ac() :: high | medium | low.

au()

-type au() :: multiple | single | none.

av()

-type av() :: local | adjacent_network | network.

cdp()

-type cdp() :: none | low | low_medium | medium_high | high | not_defined.

cvss()

-type cvss() ::
          #cvss_v2{av :: cvss_v2:av(),
                   ac :: cvss_v2:ac(),
                   au :: cvss_v2:au(),
                   c :: cvss_v2:impact(),
                   i :: cvss_v2:impact(),
                   a :: cvss_v2:impact(),
                   e :: cvss_v2:exploitability() | undefined,
                   rl :: cvss_v2:remediation_level() | undefined,
                   rc :: cvss_v2:report_confidence() | undefined,
                   cdp :: cvss_v2:cdp() | undefined,
                   td :: cvss_v2:td() | undefined,
                   cr :: cvss_v2:requirement() | undefined,
                   ir :: cvss_v2:requirement() | undefined,
                   ar :: cvss_v2:requirement() | undefined}.

exploitability()

-type exploitability() :: unproven | proof_of_concept | functional | high | not_defined.

impact()

-type impact() :: none | partial | complete.

remediation_level()

-type remediation_level() :: official_fix | temporary_fix | workaround | unavailable | not_defined.

report_confidence()

-type report_confidence() :: unconfirmed | uncorroborated | confirmed | not_defined.

requirement()

-type requirement() :: low | medium | high | not_defined.

td()

-type td() :: none | low | medium | high | not_defined.

Functions

base_score/1

-spec base_score(cvss_v2:cvss()) -> cvss:score().

Calculate the CVSS 2.0 Base Score.

> {ok, Cvss} = cvss_v2:parse(<<"AV:N/AC:L/Au:N/C:C/I:C/A:C">>).
> cvss_v2:base_score(Cvss).
10.0

compose/1

-spec compose(cvss_v2:cvss()) -> iolist().

Compose a CVSS 2.0 record into a vector string.

> iolist_to_binary(cvss_v2:compose(#cvss_v2{av = network, ac = low, au = none,
                                           c = complete, i = complete, a = complete})).
<<"AV:N/AC:L/Au:N/C:C/I:C/A:C">>

environmental_score/1

-spec environmental_score(cvss_v2:cvss()) -> cvss:score().

Calculate the CVSS 2.0 Environmental Score. Returns the Temporal Score if no environmental metrics are present.

> {ok, Cvss} = cvss_v2:parse(<<"AV:N/AC:L/Au:N/C:C/I:C/A:C/CDP:H/TD:H/CR:H/IR:H/AR:H">>).
> cvss_v2:environmental_score(Cvss).
10.0

parse(Vector)

-spec parse(binary()) -> {ok, cvss_v2:cvss()} | {error, cvss:parse_error()}.

Parse a CVSS 2.0 vector string. Format: AV:N/AC:L/Au:N/C:P/I:P/A:C (parentheses optional)

> cvss_v2:parse(<<"AV:N/AC:L/Au:N/C:C/I:C/A:C">>).
{ok, #cvss_v2{av = network, ac = low, au = none,
              c = complete, i = complete, a = complete}}

> cvss_v2:parse(<<"(AV:N/AC:L/Au:N/C:P/I:P/A:C)">>).
{ok, #cvss_v2{av = network, ac = low, au = none,
              c = partial, i = partial, a = complete}}

> cvss_v2:parse(<<"AV:N/AC:L/Au:N/C:C/I:C/A:C/E:F/RL:W/RC:C">>).
{ok, #cvss_v2{av = network, ac = low, au = none,
              c = complete, i = complete, a = complete,
              e = functional, rl = workaround, rc = confirmed}}

> cvss_v2:parse(<<"AV:X/AC:L/Au:N/C:C/I:C/A:C">>).
{error, {invalid_metric, <<"AV">>, <<"X">>}}

score/1

-spec score(cvss_v2:cvss()) -> cvss:score().

Calculate the CVSS 2.0 score. Returns the most relevant score: Environmental > Temporal > Base.

> {ok, Cvss} = cvss_v2:parse(<<"AV:N/AC:L/Au:N/C:C/I:C/A:C">>).
> cvss_v2:score(Cvss).
10.0

> {ok, Cvss2} = cvss_v2:parse(<<"AV:N/AC:L/Au:N/C:N/I:N/A:N">>).
> cvss_v2:score(Cvss2).
0.0

> {ok, Cvss3} = cvss_v2:parse(<<"AV:N/AC:L/Au:N/C:N/I:N/A:C">>).
> cvss_v2:score(Cvss3).
7.8

temporal_score/1

-spec temporal_score(cvss_v2:cvss()) -> cvss:score().

Calculate the CVSS 2.0 Temporal Score. Returns the Base Score if no temporal metrics are present.

> {ok, Cvss} = cvss_v2:parse(<<"AV:N/AC:L/Au:N/C:C/I:C/A:C/E:U/RL:OF/RC:UC">>).
> cvss_v2:temporal_score(Cvss).
6.7

valid/1

-spec valid(iodata() | cvss_v2:cvss()) -> boolean().

Check whether a CVSS 2.0 value is valid.

Accepts either a vector string or a parsed record.

> cvss_v2:valid(<<"AV:N/AC:L/Au:N/C:C/I:C/A:C">>).
true

> cvss_v2:valid(#cvss_v2{av = network, ac = low, au = none,
                         c = complete, i = complete, a = complete}).
true

> cvss_v2:valid(<<"AV:X/AC:L/Au:N/C:C/I:C/A:C">>).
false