if i is not None:
            if last_modified == i and not args.f:
                print("Not modified")
                sys.exit(0)

        cpej = json.loads(f.read())
        cpeList = []
        for cpeitem in cpej["matches"]:
            item = process_cpe_item(cpeitem)
            cpeList.append(item)
        db.bulkUpdate("cpe", cpeList)

        #update database info after successful program-run
        db.setColUpdate('cpe', last_modified)
    elif args.p:
        c = db.getSize('cpe')
        if args.v:
            print(str(c))
        if c > 0 and args.a is False:
            print("Database already populated")
        else:
            print("Database population started")
            db.dropCollection("cpe")
            try:
                (f, r) = Configuration.getFile(Configuration.getFeedURL('cpe'))
            except:
                sys.exit(
                    "Cannot open url %s. Bad URL or not connected to the internet?"
                    % (Configuration.getFeedURL("cpe")))

            cpej = json.loads(f.read())
Exemple #2
0
     cvej = json.loads(f.read())
     for cveitem in cvej['CVE_Items']:
         item = process_cve_item(item=cveitem)
         # check if the CVE already exists.
         x = db.getCVE(item['id'])
         # if so, update the entry.
         if x:
             if args.v:
                 print("Existing CVE found : {} then update".format(
                     item['id']))
             db.updateCVE(item)
         # if not, create it.
         else:
             db.insertCVE(item)
 elif args.p:
     c = db.getSize('cves')
     if args.v:
         print(str(c))
     if c > 0 and args.a is False:
         print("database already populated")
     else:
         print("Database population started")
         db.dropCollection("cves")
         for x in range(cveStartYear, year):
             getfile = file_prefix + str(x) + file_suffix
             try:
                 (f, r) = Configuration.getFile(
                     Configuration.getFeedURL('cve') + getfile)
             except:
                 sys.exit(
                     "Cannot open url %s. Bad URL or not connected to the internet?"
Exemple #3
0
def nbelement(collection=None):
    if collection is None:
        collection = "cve"
    return db.getSize(collection)

def isLastAdmin(user):
    if dbLayer.isSingleMaster(user):
        sys.exit(exits['lastMaster'])

# script run
try:
    if args.a:
        username = args.a
        if username.strip() == "_dummy_":
            sys.exit(exits['dummy'])
        if dbLayer.userExists(username):
            sys.exit(exits['userInDb'])
        # set master if db is empty
        if dbLayer.getSize(col) > 0:
            masterLogin()
            password = promptNewPass()
            dbLayer.addUser(username, password)
        else:
            password = promptNewPass()
            dbLayer.addUser(username, password, admin=True)
        sys.exit("User added")
    elif args.c:
        username = args.c
        verifyPass(getpass.getpass("Old password:"******"Password updated")
    elif args.r:
        username = args.r
Exemple #5
0
             if args.v:
                 print("item found : " + item['id'])
             if 'cvss' not in item:
                 item['cvss'] = None
             else:
                 item['cvss'] = float(item['cvss'])
             if 'cwe' not in item:
                 item['cwe'] = defaultvalue['cwe']
             db.updateCVE(item)
         # if not, create it.
         else:
             db.insertCVE(item)
 elif args.p:
     # populate is pretty straight-forward, just grab all the files from NVD
     # and dump them into a DB.
     c = db.getSize('cves')
     if args.v:
         print(str(c))
     if c > 0 and args.a is False:
         print("database already populated")
     else:
         print("Database population started")
         for x in range(cveStartYear, year):
             parser = make_parser()
             ch = CVEHandler()
             parser.setContentHandler(ch)
             getfile = file_prefix + str(x) + file_suffix
             try:
                 (f, r) = Configuration.getFile(Configuration.getCVEDict() + getfile, compressed = True)
             except:
                 sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(Configuration.getCVEDict() + getfile))
Exemple #6
0
 def countItems(self):
     return db.getSize("mgmt_" + self.collection.lower())
def isLastAdmin(user):
    if dbLayer.isSingleMaster(user):
        sys.exit(exits['lastMaster'])


# script run
try:
    if args.a:
        username = args.a
        if username.strip() == "_dummy_":
            sys.exit(exits['dummy'])
        if dbLayer.userExists(username):
            sys.exit(exits['userInDb'])
        # set master if db is empty
        if dbLayer.getSize(col) > 0:
            masterLogin()
            password = promptNewPass()
            dbLayer.addUser(username, password)
        else:
            password = promptNewPass()
            dbLayer.addUser(username, password, admin=True)
        sys.exit("User added")
    elif args.c:
        username = args.c
        verifyPass(getpass.getpass("Old password:"******"Password updated")
    elif args.r:
        username = args.r
Exemple #8
0
 def countItems(self):
     return db.getSize("mgmt_"+self.collection.lower())
Exemple #9
0
def nbelement(collection=None):
    if collection is None or collection == "cve":
        collection = "cves"
    return db.getSize(collection)
Exemple #10
0
def nbelement(collection=None):
    if collection is None:
        collection = "cves"
    return dbLayer.getSize(collection)
Exemple #11
0
             if args.v:
                 print("item found : " + item["id"])
             if "cvss" not in item:
                 item["cvss"] = None
             else:
                 item["cvss"] = float(item["cvss"])
             if "cwe" not in item:
                 item["cwe"] = defaultvalue["cwe"]
             db.updateCVE(item)
         # if not, create it.
         else:
             db.insertCVE(item)
 elif args.p:
     # populate is pretty straight-forward, just grab all the files from NVD
     # and dump them into a DB.
     c = db.getSize("cves")
     if args.v:
         print(str(c))
     if c > 0 and args.a is False:
         print("database already populated")
     else:
         print("Database population started")
         for x in range(cveStartYear, year):
             parser = make_parser()
             ch = CVEHandler()
             parser.setContentHandler(ch)
             getfile = file_prefix + str(x) + file_suffix
             try:
                 (f, r) = Configuration.getFile(Configuration.getCVEDict() + getfile, compressed=True)
             except:
                 sys.exit(