Ejemplo n.º 1
0
            self.cves[-1]['Modified'] = self.PUB

if __name__=='__main__':
    # connect to the DB.
    db = Configuration.getMongoConnection()
    collection = db.cves
    info = db.info
    # get your parser on !!
    parser = make_parser()
    ch = CVEHandler()
    parser.setContentHandler(ch)
    # start here if it's an update.
    if args.u:
        # get the 'modified' file
        getfile = file_prefix+file_mod+file_suffix
        f = urlopen(Configuration.getCVEDict()+getfile)
        i = info.find_one({'db': 'cve'})
        if i is not None:
            if f.headers['last-modified'] == i['last-modified']:
                sys.exit("Not modified")
        info.update({'db': 'cve'}, {"$set":{'last-modified': f.headers['last-modified']}}, upsert=True)

        parser.parse(f)
        for item in ch.cves:
            # check if the CVE already exists.
            x=collection.find({'id': item['id']})
            # if so, update the entry.
            if x.count() > 0:
                if 'cvss' not in item:
                    item['cvss'] = defaultvalue['cvss']
                if 'cwe' not in item:
Ejemplo n.º 2
0
            self.cves[-1]['Modified'] = self.PUB


if __name__ == '__main__':
    # connect to the DB.
    db = Configuration.getMongoConnection()
    collection = db.cves
    info = db.info
    parser = make_parser()
    ch = CVEHandler()
    parser.setContentHandler(ch)
    # start here if it's an update.
    if args.u:
        # get the 'modified' file
        getfile = file_prefix + file_mod + file_suffix
        f = urlopen(Configuration.getCVEDict() + getfile)
        i = info.find_one({'db': 'cve'})
        if i is not None:
            if f.headers['last-modified'] == i['last-modified']:
                sys.exit("Not modified")
        info.update({'db': 'cve'},
                    {"$set": {
                        'last-modified': f.headers['last-modified']
                    }},
                    upsert=True)

        # get your parser on !!
        parser = make_parser()
        ch = CVEHandler()
        parser.setContentHandler(ch)
        parser.parse(f)
Ejemplo n.º 3
0
        if ret:
            print ("Year " + str(x) + " done, imported " + str(len(ch.cves)) + " CVEs")
    else:
        print ("Year " + str(x) + " has no CVE's.")

# Main
if __name__=='__main__':
    # connect to the DB.
    db = Configuration.getMongoConnection()
    collection = db.cves
    info = db.info
     
    # start here if it's an update.
    if args.u:
        # get the 'modified' file
        getfile = Configuration.getCVEDict() + file_prefix + file_mod + file_suffix
        f = download(getfile)
        
        i = info.find_one({'db': 'cve'})
        if i is not None:
            if f.headers['last-modified'] == i['last-modified']:
                sys.exit("Not modified")
        
        info.update({'db': 'cve'}, {"$set": {'last-modified': f.headers['last-modified']}}, upsert=True)
        
        ch = parseXML(f)
        for item in ch.cves:
            upsertItem(item)
        
        # get the 'recent' file
        getfile = Configuration.getCVEDict() + file_prefix + file_rec + file_suffix