Giter VIP home page Giter VIP logo

perl-cvss's Introduction

Release Actions Status License Starts Forks Issues Coverage Status

CVSS - Perl extension for CVSS (Common Vulnerability Scoring System) 2.0/3.x/4.0

Synopsis

use CVSS;

# OO-interface

# Method 1 - Use params

$cvss = CVSS->new(
  version => '3.1',
  metrics => {
      AV => 'A',
      AC => 'L',
      PR => 'L',
      UI => 'R',
      S => 'U',
      C => 'H',
      I => 'H',
      A => 'H',
  }
);


# Method 2 - Decode and parse the vector string

use CVSS;

$cvss = CVSS->from_vector_string('CVSS:3.1/AV:A/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H');

say $cvss->base_score; # 7.4


# Method 3 - Builder

use CVSS;

$cvss = CVSS->new(version => '3.1');
$cvss->attackVector('ADJACENT_NETWORK');
$cvss->attackComplexity('LOW');
$cvss->privilegesRequired('LOW');
$cvss->userInteraction('REQUIRED');
$cvss->scope('UNCHANGED');
$cvss->confidentialityImpact('HIGH');
$cvss->integrityImpact('HIGH');
$cvss->availabilityImpact('HIGH');

$cvss->calculate_score;

# Common methods

# Convert the CVSS object in "vector string"
say $cvss; # CVSS:3.1/AV:A/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H

# Get metric value
say $cvss->AV; # A
say $cvss->attackVector; # ADJACENT_NETWORK

# Get the base score
say $cvss->base_score; # 7.4

# Get all scores
say Dumper($cvss->scores);

# { "base"           => "7.4",
#   "exploitability" => "1.6",
#   "impact"         => "5.9" }

# Get the base severity
say $cvss->base_severity # HIGH

# Convert CVSS in XML in according of CVSS XML Schema Definition
$xml = $cvss->to_xml;

# Convert CVSS in JSON in according of CVSS JSON Schema
$json = encode_json($cvss);


# exported functions

use CVSS qw(decode_cvss encode_cvss)

$cvss = decode_cvss('CVSS:3.1/AV:A/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H');
say $cvss->base_score;  # 7.4

$vector_string = encode_cvss(version => '3.1', metrics => {...});
say $cvss_string; # CVSS:3.1/AV:A/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H

cvss command-line-interface

Get the base score:

$ cvss CVSS:3.1/AV:A/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H --base-score
7.4

Get the base severity:

$ cvss CVSS:3.1/AV:A/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H --base-severity
HIGH

Parses the provided vector string and returns the JSON representation:

$ cvss CVSS:3.1/AV:A/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H --json | jq
{
  "attackComplexity": "LOW",
  "attackVector": "ADJACENT_NETWORK",
  "availabilityImpact": "HIGH",
  "baseScore": 7.4,
  "baseSeverity": "HIGH",
  "confidentialityImpact": "HIGH",
  "integrityImpact": "HIGH",
  "privilegesRequired": "LOW",
  "scope": "UNCHANGED",
  "userInteraction": "REQUIRED",
  "vectorString": "CVSS:3.1/AV:A/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H",
  "version": "3.1"
}

Parses the provided vector string and returns the XML representation:

$ cvss CVSS:3.1/AV:A/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H --xml
<?xml version="1.0" encoding="UTF-8"?>
<cvssv3.1 xmlns="https://www.first.org/cvss/cvss-v3.1.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="https://www.first.org/cvss/cvss-v3.1.xsd https://www.first.org/cvss/cvss-v3.1.xsd"
  >

  <base_metrics>
    <attack-vector>ADJACENT_NETWORK</attack-vector>
    <attack-complexity>LOW</attack-complexity>
    <privileges-required>LOW</privileges-required>
    <user-interaction>REQUIRED</user-interaction>
    <scope>UNCHANGED</scope>
    <confidentiality-impact>HIGH</confidentiality-impact>
    <integrity-impact>HIGH</integrity-impact>
    <availability-impact>HIGH</availability-impact>
    <base-score>7.4</base-score>
    <base-severity>HIGH</base-severity>
  </base_metrics>

</cvssv3.1>

Install

Using Makefile.PL:

To install CVSS distribution, run the following commands.

perl Makefile.PL
make
make test
make install

Using App::cpanminus:

cpanm CVSS

Documentation

Copyright

  • Copyright 2007-2024 © FIRST.org - Forum of Incident Response and Security Teams, Inc.
  • Copyright 2023-2024 © Giuseppe Di Terlizzi

perl-cvss's People

Contributors

giterlizzi avatar

Watchers

 avatar

perl-cvss's Issues

Error: "round" is not exported by the POSIX module

Module compilation fails on some of my smoker systems, probably only for perls with an older version of the POSIX module:

#   Failed test 'use CVSS;'
#   at t/00-load.t line 8.
#     Tried to use 'CVSS'.
#     Error:  "round" is not exported by the POSIX module
# Can't continue after import errors at /usr/perl5.20.1Dp/lib/5.20.1/amd64-freebsd-ld/POSIX.pm line 30.
# BEGIN failed--compilation aborted at /home/cpansand/.cpan/build/2024080123/CVSS-1.10-xj4SIp/blib/lib/CVSS/v3.pm line 9.
# Compilation failed in require at /home/cpansand/.cpan/build/2024080123/CVSS-1.10-xj4SIp/blib/lib/CVSS.pm line 14.
# BEGIN failed--compilation aborted at /home/cpansand/.cpan/build/2024080123/CVSS-1.10-xj4SIp/blib/lib/CVSS.pm line 14.
# Compilation failed in require at t/00-load.t line 8.
# BEGIN failed--compilation aborted at t/00-load.t line 8.

#   Failed test 'use CVSS::v3;'
#   at t/00-load.t line 10.
#     Tried to use 'CVSS::v3'.
#     Error:  Attempt to reload CVSS/v3.pm aborted.
# Compilation failed in require at t/00-load.t line 10.
# BEGIN failed--compilation aborted at t/00-load.t line 10.
Use of uninitialized value $CVSS::VERSION in concatenation (.) or string at t/00-load.t line 15.
# CVSS , Perl 5.020001, /usr/perl5.20.1Dp/bin/perl
# Looks like you failed 2 tests of 4.
t/00-load.t ....... 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/4 subtests 
... etc ...

Newer List::Util required

t/00-load.t and t/10-cvss4.t if List::Util is too old (i.e. without "any"):

#   Failed test 'use CVSS;'
#   at t/00-load.t line 8.
#     Tried to use 'CVSS'.
#     Error:  "any" is not exported by the List::Util module
# Can't continue after import errors at /home/e/eserte/.cpan/build/2024080320/CVSS-1.11-2/blib/lib/CVSS/v4.pm line 9.
# BEGIN failed--compilation aborted at /home/e/eserte/.cpan/build/2024080320/CVSS-1.11-2/blib/lib/CVSS/v4.pm line 9.
# Compilation failed in require at /home/e/eserte/.cpan/build/2024080320/CVSS-1.11-2/blib/lib/CVSS.pm line 15.
# BEGIN failed--compilation aborted at /home/e/eserte/.cpan/build/2024080320/CVSS-1.11-2/blib/lib/CVSS.pm line 15.
# Compilation failed in require at t/00-load.t line 8.
# BEGIN failed--compilation aborted at t/00-load.t line 8.

#   Failed test 'use CVSS::v4;'
#   at t/00-load.t line 11.
#     Tried to use 'CVSS::v4'.
#     Error:  Attempt to reload CVSS/v4.pm aborted.
# Compilation failed in require at t/00-load.t line 11.
# BEGIN failed--compilation aborted at t/00-load.t line 11.
Use of uninitialized value $CVSS::VERSION in concatenation (.) or string at t/00-load.t line 15.
# CVSS , Perl 5.016003, /opt/perl-5.16.3/bin/perl
# Looks like you failed 2 tests of 4.
t/00-load.t ....... 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/4 subtests 
... etc ...

t/10-cvss4.t fails on some systems (-Duselongdouble?)

The test suite fails on some of my smoker systems like this:

#   Failed test '5.6 --> CVSS:4.0/AV:N/AC:H/AT:P/PR:H/UI:A/VC:L/VI:H/VA:N/SC:N/SI:N/SA:N'
#   at t/10-cvss4.t line 16.
#          got: 5.7
#     expected: 5.6
# Looks like you failed 1 test of 442.
t/10-cvss4.t ...... 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/442 subtests 

I have four such fail reports, all generated with perls which were compiled with increased floating point accuracy (-Duselongdouble). However, there's also one system which had a pass (aarch64-linux-ld).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.