aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/cvert-update
blob: 3b3f5572a83c7190856d1e97f8fab84a46a72402 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
#
# Copyright (c) 2018 by Cisco Systems, Inc.
#
# This program is 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 Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

""" Update NVD feeds and store CVE blob locally
"""


import textwrap
import argparse
import logging
import logging.config
import cvert


def update_cvert():
    """Update CVE storage"""

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description=textwrap.dedent("""
        Update NVD feeds and store CVE blob locally.
        """),
        epilog=textwrap.dedent("""
        examples:

        # Download NVD feeds to  "nvdfeed" directory.
        # If there are meta files in the directory, they will be updated
        # and only fresh archives will be downloaded
        %% %(prog)s nvdfeed

        # Inspect NVD feeds in "nvdfeed" directory
        # and prepare a CVE dump python blob "cvedump".
        # Use it later as input for cvert-* scripts (for speeding up)
        %% %(prog)s --offline --store cvedump nvdfeed

        # Download (update) NVD feeds and prepare the CVE dump
        %% %(prog)s --store cvedump nvdfeed
        """))

    parser.add_argument("-d", "--store", help="save CVE data structures in file",
                        metavar="FILENAME")
    parser.add_argument("--offline", help="do not update from NVD site",
                        action="store_true")
    parser.add_argument("--debug", help="print debug messages",
                        action="store_true")

    parser.add_argument("feed_dir", help="feeds directory",
                        metavar="feed-dir")

    args = parser.parse_args()

    logging.config.dictConfig(cvert.logconfig(args.debug))

    cve_struct = cvert.update_feeds(args.feed_dir, args.offline)

    if not cve_struct and args.offline:
        parser.error("No CVEs found in {0}. Try turn off offline mode.".format(args.feed_dir))

    if args.store:
        cvert.save_cve(args.store, cve_struct)


if __name__ == "__main__":
    update_cvert()