Commit b33f23dd authored by PidgeyL's avatar PidgeyL
Browse files

Ranking

parent ec02326e
Loading
Loading
Loading
Loading
+26 −0
Original line number Original line Diff line number Diff line
@@ -322,6 +322,32 @@ class Database(metaclass=Singleton):
    cveList=[x['id'] for x in colVIA4.find({key: val})]
    cveList=[x['id'] for x in colVIA4.find({key: val})]
    return self.sanitize(cve_query(query={'id':{'$in':cveList}}))
    return self.sanitize(cve_query(query={'id':{'$in':cveList}}))


  ###########
  # Ranking #
  ###########
  def ranking_add(self, cpe, key, rank):
    item = self.ranking_find(cpe)
    if item is None:
      colRANKING.update({'cpe': cpe}, {"$push": {'rank': {key: rank}}}, upsert=True)
    else:
      l = []
      for i in item['rank']:
        i[key] = rank
        l.append(i)
      colRANKING.update({'cpe': cpe}, {"$set": {'rank': l}})
    return True

  def ranking_remove(self, cpe):
    self.colRANKING.remove({'cpe': {'$regex': cpe}})

  def ranking_find(self, cpe=None, regex=False):
    if not cpe:
      return sanitize(self.colRANKING.find())
    if regex and cpe:
      return sanitize(self.colRANKING.find_one({'cpe': {'$regex': cpe}}))
    else:
      return sanitize(self.colRANKING.find_one({'cpe': cpe}))

  ########
  ########
  # Info #
  # Info #
  ########
  ########
+37 −1
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ class DatabaseLayer(metaclass=Singleton):
    self.Whitelist = MarkList('whitelist')
    self.Whitelist = MarkList('whitelist')
    self.Blacklist = MarkList('blacklist')
    self.Blacklist = MarkList('blacklist')
    self.Users     = Users()
    self.Users     = Users()
    self.Ranking   = Ranking()


  def db_info(self, include_admin=False):
  def db_info(self, include_admin=False):
    return self.db.db_getStats(include_admin)
    return self.db.db_getStats(include_admin)
@@ -247,7 +248,11 @@ class CVEs:
      if via4:
      if via4:
        c.via4 = DatabaseLayer().VIA4.get(c.id)
        c.via4 = DatabaseLayer().VIA4.get(c.id)
      if ranking:
      if ranking:
        pass
        ranks = set()
        for conf cve.vulnerable_configuration:
          rank = DatabaseLayer().CPE.ranking(cpeid=conf)
          if rank: ranks.add(rank)
        c.ranking = ranks
      if subscore:
      if subscore:
        exploitCVSS=exploitabilityScore(cve)
        exploitCVSS=exploitabilityScore(cve)
        impactCVSS =impactScore(cve)
        impactCVSS =impactScore(cve)
@@ -294,6 +299,24 @@ class CPEs:
  def getAll(self):
  def getAll(self):
    return self.db.cpe_getAll()
    return self.db.cpe_getAll()


  def ranking(self, cpeID, loosy=True):
    result = False
    if loosy:
      for x in cpeid.split(':'):
        if x is not '':
          i = self.db.ranking_find(x, regex=True)
        if i is None:
          continue
        if 'rank' in i:
          result = i['rank']
    else:
      i = self.db.ranking_find(cpeid, regex=True)
      if i is None:
        result =  False
      if 'rank' in i:
        return i['rank']
    return result

  def updated(self, date=None):
  def updated(self, date=None):
    if date:
    if date:
      self.db.cpe_setUpdate(date)
      self.db.cpe_setUpdate(date)
@@ -418,3 +441,16 @@ class VIA4s:


  def link(self, key, value):
  def link(self, key, value):
    return self.db.via4_link(key, value)
    return self.db.via4_link(key, value)

###########
# Ranking #
###########
class Ranking:
  def get(self, cpe=None, regex=False):
    return self.db.ranking_find(cpe=cpe, regex=regex)

  def remove(self, cpe):
    self.db.ranking_remove(cpe)

  def add(self, cpe, key, rank):
    self.db.ranking_add(cpe, key, rank)