Exemplo n.º 1
0
 def generate_full_query(self, f):
     query = self.generate_minimal_query(f)
     if current_user.is_authenticated():
         if f['blacklistSelect'] == "on":
             regexes = db.getRules('blacklist')
             if len(regexes) != 0:
                 exp = "^(?!" + "|".join(regexes) + ")"
                 query.append({
                     '$or': [{
                         'vulnerable_configuration': re.compile(exp)
                     }, {
                         'vulnerable_configuration': {
                             '$exists': False
                         }
                     }, {
                         'vulnerable_configuration': []
                     }]
                 })
         if f['whitelistSelect'] == "hide":
             regexes = db.getRules('whitelist')
             if len(regexes) != 0:
                 exp = "^(?!" + "|".join(regexes) + ")"
                 query.append({
                     '$or': [{
                         'vulnerable_configuration': re.compile(exp)
                     }, {
                         'vulnerable_configuration': {
                             '$exists': False
                         }
                     }, {
                         'vulnerable_configuration': []
                     }]
                 })
         if f['unlistedSelect'] == "hide":
             wlregexes = tk.compile(db.getRules('whitelist'))
             blregexes = tk.compile(db.getRules('blacklist'))
             query.append({
                 '$or': [{
                     'vulnerable_configuration': {
                         '$in': wlregexes
                     }
                 }, {
                     'vulnerable_configuration': {
                         '$in': blregexes
                     }
                 }]
             })
     return query
Exemplo n.º 2
0
 def generate_full_query(self, f):
   query = self.generate_minimal_query(f)
   if current_user.is_authenticated():
       if f['blacklistSelect'] == "on":
           regexes = db.getRules('blacklist')
           if len(regexes) != 0:
               exp = "^(?!" + "|".join(regexes) + ")"
               query.append({'$or': [{'vulnerable_configuration': re.compile(exp)},
                                     {'vulnerable_configuration': {'$exists': False}},
                                     {'vulnerable_configuration': []} ]})
       if f['whitelistSelect'] == "hide":
           regexes = db.getRules('whitelist')
           if len(regexes) != 0:
               exp = "^(?!" + "|".join(regexes) + ")"
               query.append({'$or': [{'vulnerable_configuration': re.compile(exp)},
                                     {'vulnerable_configuration': {'$exists': False}},
                                     {'vulnerable_configuration': []} ]})
       if f['unlistedSelect'] == "hide":
           wlregexes = tk.compile(db.getRules('whitelist'))
           blregexes = tk.compile(db.getRules('blacklist'))
           query.append({'$or': [{'vulnerable_configuration': {'$in': wlregexes}},
                                 {'vulnerable_configuration': {'$in': blregexes}}]})
   return query
Exemplo n.º 3
0
    def generate_minimal_query(self, f):
        query = []
        # retrieving lists
        if f['rejectedSelect'] == "hide":
            exp = "^(?!\*\* REJECT \*\*\s+DO NOT USE THIS CANDIDATE NUMBER.*)"
            query.append({'summary': re.compile(exp)})

        # cvss logic
        if f['cvssSelect'] == "above":
            query.append({'cvss': {'$gt': float(f['cvss'])}})
        elif f['cvssSelect'] == "equals":
            query.append({'cvss': float(f['cvss'])})
        elif f['cvssSelect'] == "below":
            query.append({'cvss': {'$lt': float(f['cvss'])}})

        # date logic
        if f['timeSelect'] != "all":
            if f['startDate']:
                startDate = parse_datetime(f['startDate'],
                                           ignoretz=True,
                                           dayfirst=True)
            if f['endDate']:
                endDate = parse_datetime(f['endDate'],
                                         ignoretz=True,
                                         dayfirst=True)

            if f['timeSelect'] == "from":
                query.append({f['timeTypeSelect']: {'$gt': startDate}})
            elif f['timeSelect'] == "until":
                query.append({f['timeTypeSelect']: {'$lt': endDate}})
            elif f['timeSelect'] == "between":
                query.append(
                    {f['timeTypeSelect']: {
                         '$gt': startDate,
                         '$lt': endDate
                     }})
            elif f['timeSelect'] == "outside":
                query.append({
                    '$or': [{
                        f['timeTypeSelect']: {
                            '$lt': startDate
                        }
                    }, {
                        f['timeTypeSelect']: {
                            '$gt': endDate
                        }
                    }]
                })
        return query
Exemplo n.º 4
0
  def generate_minimal_query(self, f):
    query = []
    # retrieving lists
    if f['rejectedSelect'] == "hide":
      exp = "^(?!\*\* REJECT \*\*\s+DO NOT USE THIS CANDIDATE NUMBER.*)"
      query.append({'summary': re.compile(exp)})

    # cvss logic
    if   f['cvssSelect'] == "above":  query.append({'cvss': {'$gt': float(f['cvss'])}})
    elif f['cvssSelect'] == "equals": query.append({'cvss': float(f['cvss'])})
    elif f['cvssSelect'] == "below":  query.append({'cvss': {'$lt': float(f['cvss'])}})

    # date logic
    if f['timeSelect'] != "all":
      if f['startDate']:
        startDate = parse_datetime(f['startDate'], ignoretz=True, dayfirst=True)
      if f['endDate']:
        endDate   = parse_datetime(f['endDate'],   ignoretz=True, dayfirst=True)

      if   f['timeSelect'] == "from":
        query.append({f['timeTypeSelect']: {'$gt': startDate}})
      elif f['timeSelect'] == "until":
        query.append({f['timeTypeSelect']: {'$lt': endDate}})
      elif f['timeSelect'] == "between":
        query.append({f['timeTypeSelect']: {'$gt': startDate, '$lt': endDate}})
      elif f['timeSelect'] == "outside":
        query.append({'$or': [{f['timeTypeSelect']: {'$lt': startDate}}, {f['timeTypeSelect']: {'$gt': endDate}}]})
    return query