Beispiel #1
0
from lib.Config import Configuration
from lib.Toolkit import pad

# connect to db
db = Configuration.getMongoConnection()
cpe = db.cpe

try:
    r = Configuration.getRedisVendorConnection()
except:
    sys.exit(1)

for e in cpe.find({}):
    try:
        value = e['cpe_2_2']
        if e['cpe_2_2'].count(':') > 4:
            value = ":".join(value.split(':')[:5])
        (prefix, cpetype, vendor, product, version) = pad(value.split(':'), 5)
    except Exception as ex:
        print(ex)
        pass
    try:
        r.sadd("prefix:" + prefix, cpetype)
        r.sadd("t:" + cpetype, vendor)
        r.sadd("v:" + vendor, product)
        if version:
            r.sadd("p:" + product, version)
    except redisExceptions.ConnectionError:
        sys.exit("Redis server not running on %s:%s" %
                 (Configuration.getRedisHost(), Configuration.getRedisPort()))
Beispiel #2
0
          {'in':['a','b','c','d','e'],     'expect':['a','b','c','d','e']},
          {'in':['a','b','c','d','e','f'], 'expect':['a','b','c','d','e','f']}]
padtext2=[{'in':['a','b','c'],             'expect':['a','b','c','text','text']},
          {'in':['a','b','c','d','e'],     'expect':['a','b','c','d','e']},
          {'in':['a','b','c','d','e','f'], 'expect':['a','b','c','d','e','f']}]

result=[]
for x in extend:
  result.append(resultOf(x['in'],toStringFormattedCPE(x['in'],autofill=True),x['expect']))
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 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)

result=[]
for x in pad1:
  result.append(resultOf(x['in'],pad(x['in'],5),x['expect']))
for x in padtext1:
  result.append(resultOf(x['in'],pad(x['in'],5,'-'),x['expect']))
for x in padtext2:
  result.append(resultOf(x['in'],pad(x['in'],5,'text'),x['expect']))
printResults('Padding lists    - empty, char and text - ',result)

Beispiel #3
0
    'in': ['a', 'b', 'c', 'd', 'e', 'f'],
    'expect': ['a', 'b', 'c', 'd', 'e', 'f']
}]

result = []
for x in extend:
    result.append(
        resultOf(x['in'], toStringFormattedCPE(x['in'], autofill=True),
                 x['expect']))
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 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)

result = []
for x in pad1:
    result.append(resultOf(x['in'], pad(x['in'], 5), x['expect']))
for x in padtext1:
    result.append(resultOf(x['in'], pad(x['in'], 5, '-'), x['expect']))
for x in padtext2:
    result.append(resultOf(x['in'], pad(x['in'], 5, 'text'), x['expect']))
printResults('Padding lists    - empty, char and text - ', result)
Beispiel #4
0
    r = Configuration.getRedisVendorConnection()
except:
    sys.exit(1)

for e in cpe:
    try:
        if args.o is not True:
            prefix = 'cpe_2_2'
            value = e[prefix]
        else:
            value = e['id']
        if args.o is not True:
            if e[prefix].count(':') > 4:
                value = ":".join(value.split(':')[:5])
            (prefix, cpetype, vendor, product,
             version) = pad(value.split(':'), 5)
        else:
            (prefix, cpeversion, cpetype, vendor, product, version,
             *remaining) = pad(value.split(':'), 6)
    except Exception as ex:
        print(ex)
        pass
    try:
        if args.v:
            print(value + " added")
        r.sadd("prefix:" + prefix, cpetype)
        r.sadd("t:" + cpetype, vendor)
        r.sadd("v:" + vendor, product)
        if version:
            r.sadd("p:" + product, version)
    except redisExceptions.ConnectionError:
Beispiel #5
0
try:
    r = Configuration.getRedisVendorConnection()
except:
    sys.exit(1)

for e in cpe.find({}):
    try:
        if args.o is not True:
            prefix = 'cpe_2_2'
            value = e[prefix]
        else:
            value = e['id']
        if args.o is not True:
            if e[prefix].count(':') > 4:
                value = ":".join(value.split(':')[:5])
            (prefix, cpetype, vendor, product, version) = pad(value.split(':'),5)
        else:
            (prefix, cpeversion, cpetype, vendor, product, version, *remaining) = pad(value.split(':'),6)
    except Exception as ex:
        print(ex)
        pass
    try:
        if args.v:
            print(value + " added")
        r.sadd("prefix:" + prefix, cpetype)
        r.sadd("t:" + cpetype, vendor)
        r.sadd("v:" + vendor, product)
        if version:
            r.sadd("p:" + product, version)
    except redisExceptions.ConnectionError:
        sys.exit("Redis server not running on %s:%s"%(Configuration.getRedisHost(),Configuration.getRedisPort()))
from lib.Config import Configuration
from lib.Toolkit import pad

# connect to db
db = Configuration.getMongoConnection()
cpe = db.cpe

try:
    r = Configuration.getRedisVendorConnection()
except:
    sys.exit(1)

for e in cpe.find({}):
    try:
        value = e['cpe_2_2']
        if e['cpe_2_2'].count(':') > 4:
            value = ":".join(value.split(':')[:5])
        (prefix, cpetype, vendor, product, version) = pad(value.split(':'),5)
    except Exception as ex:
        print(ex)
        pass
    try:
        r.sadd("prefix:" + prefix, cpetype)
        r.sadd("t:" + cpetype, vendor)
        r.sadd("v:" + vendor, product)
        if version:
            r.sadd("p:" + product, version)
    except redisExceptions.ConnectionError:
        sys.exit("Redis server not running on %s:%s"%(Configuration.getRedisHost(),Configuration.getRedisPort()))
Beispiel #7
0
]
padtext2 = [
    {"in": ["a", "b", "c"], "expect": ["a", "b", "c", "text", "text"]},
    {"in": ["a", "b", "c", "d", "e"], "expect": ["a", "b", "c", "d", "e"]},
    {"in": ["a", "b", "c", "d", "e", "f"], "expect": ["a", "b", "c", "d", "e", "f"]},
]

result = []
for x in extend:
    result.append(resultOf(x["in"], toStringFormattedCPE(x["in"], autofill=True), x["expect"]))
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 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)

result = []
for x in pad1:
    result.append(resultOf(x["in"], pad(x["in"], 5), x["expect"]))
for x in padtext1:
    result.append(resultOf(x["in"], pad(x["in"], 5, "-"), x["expect"]))
for x in padtext2:
    result.append(resultOf(x["in"], pad(x["in"], 5, "text"), x["expect"]))
printResults("Padding lists    - empty, char and text - ", result)
Beispiel #8
0
def getCVEolder(modif, end=None, collection=None):
	rez={}
	summary=[]
	cvss=[]
	vulnerable=[]
	idcve=[]
	cve=getCVE(modif)
	#cve=getCVEtemp(modif,end)
	print(cve)
	for i in cve:
		cvss.append(i["cvss"])
		#print(i["id"])
		summary.append(i["summary"])
		vulnerable.append(i["vulnerable_configuration"])
		idcve.append(i["id"])
	sindex=list(zip(idcve, vulnerable,cvss, summary))	
	fields = ["id","vulnerable",'cvss', 'summary']
	dicts = [dict(zip(fields, d)) for d in sindex] #list of dicts
	#print(len(dicts))
	#print(dicts)
	
	for e in dicts:
		if e["vulnerable"]:
			#print(e["vulnerable"])
			vendors=[]
			products=[]
			versions=[]
			for i in e["vulnerable"]:

				prefix="vulnerable"
				#value=i
				forma=toStringFormattedCPE(i)
				
				#usporedba radi ::
				value=forma
				#print(value)
				if i.count(":")>4:
					value=":".join(value.split(":")[:5])
					x=pad(value.split(":"),5)
					#print(x)
					vendor=x[3]
					
					product=x[4]
					version=x[1]
					#print(vendor, product,version)
					vendors.append(vendor)
					products.append(product)
					versions.append(version)
					#print(vendors,products,versions)
					e["vendor"]=vendors
					e["product"]=products
					e["version"]=versions

					# e["vendor"]=", ".join(str(v) for v in vendors)
					# e["product"]=", ".join(str(k) for k in products)
					# e["version"]=", ".join(str(l) for l in versions)
				
				else:

					x=pad(value.split(":"),6)
					#print(x)
					vendor=x[2]
					product=x[3]
					version=x[4]
					#print(vendor, product,version)

					vendors.append(vendor)
					products.append(product)
					versions.append(version)
					e["vendor"]=vendors
					e["product"]=products
					e["version"]=versions

				# e["vendor"]=", ".join(str(v) for v in vendors)
				# e["product"]=", ".join(str(k) for k in products)
				# e["version"]=", ".join(str(l) for l in versions)
				
				#print(e["vendor"],e["product"],e["version"])
###maknut kad se rijesi valid
			try:#puni redis s novim instancama ak nisu vec tamo hopefully
				r.sadd("v:" + vendor, product)
				if version:
					r.sadd("p:" + product, version)
			except redisExceptions.ConnectionError:
				sys.exit("Redis server not running on %s:%s"%(Configuration.getRedisHost(),Configuration.getRedisPort()))
		else:
			continue
		
		
		try:
			del e["vulnerable"] #e["vulnerable"],
		except KeyError:
			pass
	return dicts