/
nvd-generator.sh
executable file
·61 lines (50 loc) · 1.21 KB
/
nvd-generator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# Wazuh script to generate a Vulnerability Detector's feed from the National Vulnerability Database
# Copyright (C) 2015-2020, Wazuh Inc.
# May 9, 2018.
#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.
max_year=`date +"%Y"`
year=$1
last_year=0
directory=$2
if [ $# -ne 2 ]
then
echo "Use: $0 <min_year> <dest_path>"
exit 1
fi
if [ $year -le 2001 ]
then
echo "The year must be greater than 2002"
fi
if [[ ! -d $directory ]]
then
echo "Invalid destination path: '$directory'. It must be a directory."
exit 1
fi
while [ true ]
do
link="https://nvd.nist.gov/feeds/json/cve/1.1/nvdcve-1.1-$year.json.gz"
file=$directory/nvd-feed$year.json
if [ $last_year -ne $year ]
then
echo "Fetching $link"
fi
last_year=$year
result=$(curl $link --output $file.gz --silent -w '%{http_code}')
if [ $result -ne 200 ]
then
echo "Page download failed ($result), retrying..."
rm -f $file.gz
continue
fi
if [ $year -eq $max_year ]
then
break
fi
year=$[ $year + 1 ]
done
exit 0