Metabrik-Repository
view release on metacpan or search on metacpan
lib/Metabrik/Database/Nvd.pm view on Meta::CPAN
#
# $Id$
#
# database::nvd Brik
#
package Metabrik::Database::Nvd;
use strict;
use warnings;
use base qw(Metabrik::Client::Www);
sub brik_properties {
return {
revision => '$Revision$',
tags => [ qw(unstable cve cpe nist) ],
author => 'GomoR <GomoR[at]metabrik.org>',
license => 'http://opensource.org/licenses/BSD-3-Clause',
attributes => {
datadir => [ qw(datadir) ],
loaded_xml => [ qw(loaded_xml) ],
},
commands => {
update => [ qw(recent|modified|others|all) ],
load => [ qw(recent|modified|others|all year|OPTIONAL) ],
search_all => [ ],
cve_search => [ qw(pattern) ],
cpe_search => [ qw(pattern) ],
get_cve_xml => [ qw(cve_id) ],
to_hash => [ qw(entry_xml) ],
to_string => [ qw(entry_hash) ],
print => [ qw(entry_hash) ],
},
require_modules => {
'Metabrik::File::Xml' => [ ],
'Metabrik::File::Compress' => [ ],
},
};
}
# http://nvd.nist.gov/download.cfm
# nvdcve-2.0-Modified.xml.gz includes all recently published and recently updated vulnerabilities.
# nvdcve-2.0-Recent.xml.gz includes all recently published vulnerabilities.
# nvdcve-2.0-2002.xml includes vulnerabilities prior to and including 2002.
my $resource = {
uri => 'http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-NAME.xml.gz',
gz => 'nvdcve-2.0-NAME.xml.gz',
xml => 'nvdcve-2.0-NAME.xml',
};
sub update {
my $self = shift;
my ($type) = @_;
$type ||= 'recent';
if ($type ne 'recent'
&& $type ne 'modified'
&& $type ne 'others'
&& $type ne 'all') {
return $self->log->error($self->brik_help_run('update'));
}
if ($type eq 'all') {
my @output = ();
push @output, $self->update('recent');
push @output, $self->update('modified');
push @output, @{$self->update('others')};
return \@output;
}
my $datadir = $self->datadir;
my $fc = Metabrik::File::Compress->new_from_brik_init($self) or return;
if ($type eq 'recent') {
(my $uri = $resource->{uri}) =~ s/NAME/Recent/;
(my $gz = $resource->{gz}) =~ s/NAME/Recent/;
(my $xml = $resource->{xml}) =~ s/NAME/Recent/;
my $output = "$datadir/$gz";
$self->mirror($uri, $gz, $datadir) or return;
my $files = $fc->uncompress($output, $xml, $datadir) or return;
return $files->[0];
}
elsif ($type eq 'modified') {
(my $uri = $resource->{uri}) =~ s/NAME/Modified/;
(my $gz = $resource->{gz}) =~ s/NAME/Modified/;
(my $xml = $resource->{xml}) =~ s/NAME/Modified/;
my $output = "$datadir/$gz";
$self->mirror($uri, $gz, $datadir) or return;
my $files = $fc->uncompress($output, $xml, $datadir) or return;
return $files->[0];
}
elsif ($type eq 'others') {
my @output = ();
for my $year (2002..2015) {
(my $uri = $resource->{uri}) =~ s/NAME/$year/;
(my $gz = $resource->{gz}) =~ s/NAME/$year/;
(my $xml = $resource->{xml}) =~ s/NAME/$year/;
my $output = "$datadir/$gz";
$self->mirror($uri, $gz, $datadir) or return;
my $files = $fc->uncompress($output, $xml, $datadir) or next;
push @output, @$files;
}
return \@output;
}
# Error
return;
}
( run in 0.849 second using v1.01-cache-2.11-cpan-39bf76dae61 )