Esempio n. 1
0
 def last(self, entries=None):
     if self.apiurl:
         url = "api/last"
         if entries:
             url = "%s/%s" % (url, str(entries))
         cves = self._query(url)
         return cves and [CVE.fromDict(x) for x in cves] or cves
     return self.api.api_last(entries)[0]
Esempio n. 2
0
 def cve(self, cveid):
     if self.apiurl:
         cve = self._query("api/cve/%s" % str(cveid))
         return cve and CVE.fromDict(cve) or None
     try:
         return self.api.api_cve(cveid)
     except:
         return None
Esempio n. 3
0
 def cve_query(self, limit=False, skip=0, sort=None, query={}):
     if not sort: sort = ("Modified", "desc")
     if isinstance(query, list): query = {"$and": query}
     if isinstance(sort, (list, tuple)) and len(sort) == 2:
         if sort[1].lower() == "asc": sort = (sort[0], 1)
         else: sort = (sort[0], -1)  # Default Descending
     cves = list(
         self.colCVE.find(query).sort(sort[0],
                                      sort[1]).limit(limit).skip(skip))
     return [CVE.fromDict(x) for x in self.sanitize(cves)]
Esempio n. 4
0
 def cve_forCPE(self, cpe):
     if not cpe: return []
     return [
         CVE.fromDict(cve) for cve in self.sanitize(
             self.colCVE.find({
                 "vulnerable_configuration": {
                     "$regex": cpe
                 }
             }).sort("Modified", -1))
     ]
Esempio n. 5
0
 def cve_textSearch(self, text):
     try:  # Before Mongo 3
         data = [
             x["obj"] for x in self.db.command("text", "cves", search=text)
             ["results"]
         ]
     except:  # As of Mongo 3
         data = self.sanitize(self.colCVE.find({"$text": {
             "$search": text
         }}))
     return [CVE.fromDict(x) for x in data]
Esempio n. 6
0
 def cve_get(self, id):
     cve = self.sanitize(self.colCVE.find_one({"id": id}))
     return CVE.fromDict(cve) if cve else None
Esempio n. 7
0
        i = db.CVE.updated()
        last_modified = parse_datetime(r.headers['last-modified'],
                                       ignoretz=True)
        if i is not None:
            if last_modified == i:
                print("Not modified")
                sys.exit(0)

        # get your parser on !!
        parser = make_parser()
        ch = CVEHandler()
        parser.setContentHandler(ch)
        parser.parse(f)
        bulk = []
        for item in ch.cves:
            cve = CVE.fromDict(item)
            bulk.append(cve)

        # get the 'recent' file
        getfile = file_prefix + file_rec + 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?"
                % (Configuration.getFeedURL("cve") + getfile))
        parser = make_parser()
        ch = CVEHandler()
        parser.setContentHandler(ch)
        parser.parse(f)
Esempio n. 8
0
 def search(self, query):
     if self.apiurl:
         cves = self._query("api/search/%s" % str(query))
         return cves and [CVE.fromDict(x) for x in cves['data']] or []
     return self.api.api_text_search(query) or []
Esempio n. 9
0
 def cveforcpe(self, cpe):
     if self.apiurl:
         cpes = self._query("api/cvefor/%s" % str(cpe))
         return cpes and [CVE.fromDict(x) for x in cpes] or cpes
     return self.api.api_cvesFor(cpe)