forked from toolswatch/vFeed
-
Notifications
You must be signed in to change notification settings - Fork 5
/
vfeedcli.py
executable file
·88 lines (74 loc) · 3.29 KB
/
vfeedcli.py
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
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
# Copyright (C) 2016 vFeed IO
# This file is part of vFeed Correlated Vulnerability & Threat Database API - https://vfeed.io
# See the file 'LICENSE' for copying permission.
from __future__ import print_function
try:
import sys
import argparse
from config.stats import Stats
from lib.core.search import Search
from lib.common.banner import banner
from lib.migration.mongo import Migrate
from config.constants import build, title
from lib.common.utils import enum_classes, mongo_server
except ImportError as e:
print("[!] Missing a dependency:", str(e))
sys.exit()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-v", action="version", version=".:. {0} .:. ".format(title) + "API version: {0}".format(build))
parser.add_argument("-m", "--method", metavar=('method', 'CVE'), help="Invoking multiple vFeed built-in functions",
nargs=2)
parser.add_argument("-e", "--export", metavar=('json_dump', 'CVE'), help="Export the JSON content", nargs=2)
parser.add_argument("-s", "--search", metavar=('cve|cpe|cwe|oval|text', 'entry'),
help="Search for CVE,CPE,CWE, OVAL or free text",
nargs=2)
parser.add_argument("-u", "--update", help="Update the database", action="store_true", required=False)
parser.add_argument("--stats", metavar="get_stats | get_latest", type=str,
help="View the vFeed Database statistics", nargs=1)
parser.add_argument("--list", help="Enumerate the list of available built-in functions", action="store_true",
required=False)
parser.add_argument("--banner", help="Print the banner", action="store_true", required=False)
parser.add_argument("--migrate", help="Migration to MongoDB", action="store_true", required=False)
args = parser.parse_args()
if args.search:
method = args.search[0]
cve_id = args.search[1]
try:
result = getattr(Search(cve_id), method)
print(result())
except Exception as e:
print("[!] Unknown built-in function:", str(e))
if args.update:
print("[+] The vFeed Database must be downloaded from the official repository at https://vfeed.io")
print("[+] Once downloaded, decompress it into your API repository.")
if args.banner:
banner()
if args.migrate:
# checking whether the MongoDB server is running
if mongo_server("mongod"):
print("[+] Mongo service is up. Starting migrating ....")
Migrate()
else:
print("[!] Mongo service is probably not up.")
if args.stats:
method_name = args.stats[0]
try:
result = getattr(Stats(), method_name)
print(result())
except Exception as e:
print("[!] Unknown built-in function:", str(e))
if args.list:
enum_classes("list", "")
if args.method:
method_name = args.method[0]
cve_id = args.method[1]
result = enum_classes(method_name, cve_id)
print(result)
if args.export:
method_name = args.export[0]
cve_id = args.export[1]
result = enum_classes(method_name, cve_id)
if result is not False:
print(result)