Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

NIST NVD Feed Parser

by semio (Friar)
on Jul 06, 2007 at 15:00 UTC ( [id://625277] : sourcecode . print w/replies, xml ) Need Help??
Category: MISC
Author/Contact Info David Kyger
Description: This script is used to pull the latest high severity CVE entries published by NIST. The end result is a populated html table that can be used for reporting or other purposes. Hopefully someone will find it useful. Comments and suggestions for improvement (code, presentation or otherwise) are very welcome. cheers.
#!/usr/bin/perl
#
# NIST NVD Feed Parser
# David Kyger 7-6-07
# License - GNU GPL

use XML::Simple qw(:strict);

use Data::Dumper;
use POSIX qw(strftime);

my $report = "report.html";

open(REPORT,">$report");

my $url = 'http://nvd.nist.gov/download/nvdcve-recent.xml';
`/usr/local/bin/wget -q $url`;

my $file = "nvdcve-recent.xml";

my $today = strftime( "%Y-%m-%d", localtime );
my $yesterday = strftime( "%Y-%m-%d", localtime(time-86400));

$xml = new XML::Simple;

$data = $xml->XMLin(
    "nvdcve-recent.xml",
    KeyAttr    => { cve    => 'entry' },
    ForceArray => [ 'cve', 'ref' ]
);

my $e;
print REPORT '<html><body>';
print REPORT
'<table style="text-align: left;" border="1" cellpadding="2" cellspaci
+ng="2"><tbody>';
print REPORT
'<tr><td><b>Name</b></td><td><b>Published</b></td><td><b>Modified</b><
+/td><td><b>Severity</b></td><td><b>Description</b></td><td><b>Referen
+ces</b></td></tr>'
;

foreach $e ( @{ $data->{entry} } ) {
    if ( $e->{severity} =~ /High/ && $e->{modified} =~ /($today|$yeste
+rday)/ ) {
        ;
        print REPORT '<tr><td>' . $e->{name} . '</td>';
        print REPORT '<td>' . $e->{published} . '</td>';
        print REPORT '<td>' . $e->{modified} . '</td>';
        print REPORT '<td>' . $e->{severity} . '</td>';
        print REPORT '<td>'
          . $e->{desc}->{descript}->{content}
          . '</td><td><br>';

        foreach $ref ( @{ $e->{refs}->{ref} } ) {
            print REPORT '<a href="' . $ref->{url} . '" target="_blank
+">';
            print REPORT $ref->{source} . '</a><br>';
        }

    }
}
print REPORT '</td></tr>';
print REPORT '</table><p>';
print REPORT '</html></body>';
Replies are listed 'Best First'.
Re: NIST NVD Feed Parser
by cjcollier (Novice) on Dec 08, 2015 at 23:07 UTC
Re: NIST NVD Feed Parser
by Anonymous Monk on Jul 07, 2007 at 11:47 UTC
    Why not use LWP rather than wget to make it a little more flexible - someone may want to run it on a machine that doesn't have /usr/local/bin/wget - also seeing breakout to shell like this imho best avoided - especially when the alternative is only a couple extra line. Also I would tend to drop a couple extra lines to allow it to be called as a cgi by writing a content header if suitable $ENV values are seen. That way you save the need to to filesystem but if that is what you wanted you could still run from command line and direct to file.
Re: NIST NVD Feed Parser
by attiamx (Initiate) on Jul 09, 2014 at 06:52 UTC
    Greetings, eventhough your code was a good starting point from which I was able to parse NVD xml file. The code as is did not work. it crashed as it was trying to deal with $e->{desc}->{descript} at some entry it was a hash and at some other points it was an array. When it was an array, you code did not work. At any rate, thank you very much. it would really be appreciated if shared code is a working code. if I am missing something, please let me know as I would like to learn.