-
Notifications
You must be signed in to change notification settings - Fork 75
/
CveRecords5.0Upload.py
45 lines (41 loc) · 1.39 KB
/
CveRecords5.0Upload.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
# Upload 5.0 records
# Global variables should be set appropiately, and a directory of json 5.0 files must be given
import sys
import getopt
import os.path
import json
import requests
RSUS_URL = ''
CVE_API_USER = ''
CVE_API_KEY = ''
CVE_API_ORG = ''
def main(argv):
inputPath = ''
try:
opts, args = getopt.getopt(argv, "hi:", ["ifile="])
except getopt.GetopError:
print ('USAGE python cve4to5up.py -i <inputdirectory')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
sys.exit()
elif opt in ("-i", "--ifile"):
inputPath = arg
if inputPath:
for subdir, dirs, files in os.walk(inputPath):
for file in files:
with open(inputPath + '/' + file) as json_file:
data = json.load(json_file)
cve_id = data.get('cveMetadata', {}).get('id')
params = {'id': cve_id}
headers = {'CVE-API-USER': CVE_API_USER,
'CVE-API-ORG': CVE_API_ORG,
'CVE-API-KEY': CVE_API_KEY,
'Content-Type': "application/json"}
r = requests.put(
RSUS_URL + cve_id,
headers=headers,
data=json.dumps(data)
)
if __name__ == "__main__":
main(sys.argv[1:])