Commit a1b7e511 authored by Alexandre Dulaunoy's avatar Alexandre Dulaunoy
Browse files

Merge pull request #67 from PidgeyL/master

Development + Bugfixes
parents 3b247d6e 1429d6e2
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -64,18 +64,19 @@ else:
batch = []

# skip on empty collections
if not list(collections):
col=list(collections)
if not col:
    print ("Empty collections, import skipped")
    sys.exit(2)

for item in progressbar(list(collections)):
for item in progressbar(col):
    for cpeentry in item['vulnerable_configuration']:
        checkdup = cpeother.find(({'id': cpeentry}))
        if checkdup.count() <= 0:
            entry = cpe.find(({'id': cpeentry}))
            if entry.count() <= 0:
                title = cpeentry
                title = title[7:]
                title = title[10:]
                title = title.replace(':-:', ' ',10)
                title = title.replace(':', ' ',10)
                title = title.replace('_', ' ',10)
+23 −0
Original line number Diff line number Diff line
@@ -26,6 +26,29 @@ def toStringFormattedCPE(cpe,autofill=False):
        cpe+=':-'
    return cpe

# Note of warning: Old CPE's can come in different formats, and are not uniform. Possibilities are:
# cpe:/a:7-zip:7-zip:4.65::~~~~x64~
# cpe:/a:7-zip:7-zip:4.65:-:~~~~x64~
# cpe:/a:7-zip:7-zip:4.65:-:~-~-~-~x64~
def toOldCPE(cpe):
    cpe=cpe.strip()
    if not cpe.startswith('cpe:/'):
      if not cpe.startswith('cpe:2.3:'): return False
      cpe=cpe.replace('cpe:2.3:','')
      parts = cpe.split(':')
      next = []
      first= "cpe:/"+":".join(parts[:5])
      last = parts[5:]
      if last:
        for x in last:
          next.append('~') if x == "-" else next.append(x)
        if "~" in next:
          pad(next,6,"~")
      cpe="%s:%s"%(first,"".join(next))
      cpe=cpe.replace(':-:','::')
      cpe=cpe.strip(":")
    return cpe

def impactScore(cve):
    score={'NONE':0,'PARTIAL':0.275,'COMPLETE':0.660}
    try:
+19 −3
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ import sys
runPath = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(runPath, ".."))

from lib.Toolkit import toStringFormattedCPE
from lib.Toolkit import toStringFormattedCPE, toOldCPE

def resultOf(original, result, expected):
  test={'in':original,'out':result,'expect':expected}
@@ -51,12 +51,28 @@ trans= [{'in':'cpe:/o:microsoft:windows_server_2008::sp2:itanium',
        {'in':'cpe:/a:7-zip:7-zip:4.65::~~~~x64~',                                         'expect':'cpe:2.3:a:7-zip:7-zip:4.65:-:-:-:-:-:x64'},
        {'in':'cpe:/a:acl:acl:9.1.0.213',                                                  'expect':'cpe:2.3:a:acl:acl:9.1.0.213'}]

old =  [{'in':'cpe:2.3:o:microsoft:windows_server_2008:-:sp2:itanium',                          'expect':'cpe:/o:microsoft:windows_server_2008::sp2:itanium'},
        {'in':'cpe:2.3:a:activehelper:activehelper_livehelp_live_chat:2.7.4:-:-:-:-:wordpress', 'expect':'cpe:/a:activehelper:activehelper_livehelp_live_chat:2.7.4::~~~wordpress~~'},
        {'in':'cpe:2.3:o:microsoft:windows:vista:sp1:x64-enterprise',                           'expect':'cpe:/o:microsoft:windows:vista:sp1:x64-enterprise'},
        {'in':'cpe:2.3:o:microsoft:windows-nt:vista:-:enterprise',                              'expect':'cpe:/o:microsoft:windows-nt:vista::enterprise'},
        {'in':'cpe:2.3:a:novell:iprint:5.90:-:-:-:-:windows_vista',                             'expect':'cpe:/a:novell:iprint:5.90::~~~windows_vista~~'},
        {'in':'cpe:2.3:o:linux:linux_kernel',                                                   'expect':'cpe:/o:linux:linux_kernel'},
        {'in':'cpe:2.3:a:aokitaka:zip_with_pass_pro:6.3.4:-:-:-:-:android',                     'expect':'cpe:/a:aokitaka:zip_with_pass_pro:6.3.4::~~~android~~'},
        {'in':'cpe:2.3:a:7-zip:7-zip:4.65:-:-:-:-:-:x64',                                       'expect':'cpe:/a:7-zip:7-zip:4.65::~~~~x64~'},
        {'in':'cpe:2.3:a:acl:acl:9.1.0.213',                                                    'expect':'cpe:/a:acl:acl:9.1.0.213'}]

result=[]
for x in extend:
  result.append(resultOf(x['in'],toStringFormattedCPE(x['in'],autofill=True),x['expect']))
printResults('Translate - success/autofill',result)
printResults('Translate to 2.3 - success/autofill',result)

result=[]
for x in trans:
  result.append(resultOf(x['in'],toStringFormattedCPE(x['in']),x['expect']))
printResults('Translate - success/no autofill',result)
printResults('Translate to 2.3 - success/no autofill',result)

result=[]
for x in old:
  result.append(resultOf(x['in'],toOldCPE(x['in']),x['expect']))
printResults('Translate to 2.2 - success/no autofill',result)
+9 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ from logging.handlers import RotatingFileHandler

from lib.User import User
from lib.Config import Configuration
from lib.Toolkit import toStringFormattedCPE
from lib.Toolkit import toStringFormattedCPE, toOldCPE
import lib.CVEs as cves
from bin.db_whitelist import *
from bin.db_blacklist import *
@@ -384,6 +384,12 @@ def cpe23(cpe):
    if not cpe: cpe='None'
    return cpe

@app.route('/api/cpe2.2/<path:cpe>', methods=['GET'])
def cpe22(cpe):
    cpe = toOldCPE(cpe)
    if not cpe: cpe='None'
    return cpe

@app.route('/api/cvefor/<path:cpe>', methods=['GET'])
def apiCVEFor(cpe):
    col = db['cves']
@@ -869,6 +875,8 @@ if __name__ == '__main__':
    if Configuration.getLogging():
        logfile = Configuration.getLogfile()
        pathToLog = logfile.rsplit('/', 1)[0]
        pathToLog = os.path.join(_runPath, pathToLog)
        logfile = os.path.join(_runPath, logfile)
        if not os.path.exists(pathToLog):
            os.makedirs(pathToLog)
        maxLogSize = Configuration.getMaxLogSize()
+7 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import logging
from logging.handlers import RotatingFileHandler

from lib.Config import Configuration
from lib.Toolkit import toStringFormattedCPE
from lib.Toolkit import toStringFormattedCPE, toOldCPE
import lib.CVEs as cves

# parse command line arguments
@@ -229,6 +229,12 @@ def cpe23(cpe):
    if not cpe: cpe='None'
    return cpe

@app.route('/api/cpe2.2/<path:cpe>', methods=['GET'])
def cpe22(cpe):
    cpe = toOldCPE(cpe)
    if not cpe: cpe='None'
    return cpe

@app.route('/api/cvefor/<path:cpe>', methods=['GET'])
def apiCVEFor(cpe):
    col = db['cves']