Commit d8f67c28 authored by Alexandre Dulaunoy's avatar Alexandre Dulaunoy
Browse files

Merge pull request #94 from adulau/master

CVSS float issue fixed in dump and JSON output for CPE search
parents 37b04032 f2107421
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -35,4 +35,7 @@ l = cves.last(rankinglookup=rankinglookup, vfeedlookup=vfeedlookup, capeclookup=

for cveid in db.getCVEIDs(limit=args.l):
    item = l.getcve(cveid=cveid)
    if 'cvss' in item:
        if type(item['cvss']) == str:
            item['cvss'] = float(item['cvss'])
    print (json.dumps(item, sort_keys=True, default=json_util.default))
+14 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
#
# Copyright (c) 2014 	psychedelys
# Copyright (c) 2015 	Pieter-Jan Moreels - pieterjan.moreels@gmail.com
# Copyright (c) 2015    Alexandre Dulaunoy - a@foo.be

# Imports
import os
@@ -14,6 +15,7 @@ sys.path.append(os.path.join(runPath, ".."))

import re
import argparse
import json

from lib.Config import Configuration
import lib.DatabaseLayer as db
@@ -24,7 +26,7 @@ vOutput = ""

argParser = argparse.ArgumentParser(description='Search for CPE with a pattern')
argParser.add_argument('-s', type=str, required=True, help='search in cpe list')
argParser.add_argument('-o', type=str, help='O = output format [compact]')
argParser.add_argument('-o', type=str, default='expanded' ,help='O = output format [expanded, compact, json] (default: expanded)')
argParser.add_argument('-f', action='store_true', help='Enlarge the CPE search to all CPE indexed. Need the cpeother activated.', default=False)

args = argParser.parse_args()
@@ -38,9 +40,19 @@ def search(cpe):
    if vOutput == "compact":
        for item in res:
            print(item['id'])
    else:
    elif vOutput == "expanded":
        for item in res:
            print(item['id'] + "  " + item['title'])
    elif vOutput == "json":
        o = []
        for item in res:
            x = {}
            x['id'] = item['id']
            x['title'] = item['title']
            o.append(x)
        print(json.dumps(o, sort_keys=True, indent=4))



# replace special characters in cpeSearch with encoded version.
cpeSearch = re.sub(r'\(', '%28', cpeSearch)