| 437 | # Filter duplicate CVEs for the Windows Server operating systems which often have a |
| 438 | # 'Windows Server 2XXX' and a 'Windows Server 2XXX (Server Core installation)' CVE that are exactly the same |
| 439 | def filter_duplicates(found): |
| 440 | cves = list(set([cve['CVE'] for cve in found])) |
| 441 | newfound = [] |
| 442 | |
| 443 | # Iterate over unique CVEs |
| 444 | for cve in cves: |
| 445 | coreresults = list(filter(lambda cr: cr['CVE'] == cve and 'Server Core' in cr['AffectedProduct'], found)) |
| 446 | |
| 447 | # If no 'Server Core' results for CVE, just add all records matching the CVE |
| 448 | if len(coreresults) == 0: |
| 449 | normalresults = list(filter(lambda nr: nr['CVE'] == cve, found)) |
| 450 | for n in normalresults: |
| 451 | newfound.append(n) |
| 452 | continue |
| 453 | |
| 454 | # In case 'Server Core' records are found, identify matching non-core results |
| 455 | for r in coreresults: |
| 456 | regularcounterparts = list(filter(lambda c: |
| 457 | 'Server Core' not in c['AffectedProduct'] and |
| 458 | c['CVE'] == r['CVE'] and |
| 459 | c['BulletinKB'] == r['BulletinKB'] and |
| 460 | c['Title'] == r['Title'] and |
| 461 | c['AffectedComponent'] == r['AffectedComponent'] and |
| 462 | c['Severity'] == r['Severity'] and |
| 463 | c['Impact'] == r['Impact'] and |
| 464 | c['Exploits'] == r['Exploits'], found)) |
| 465 | |
| 466 | # If non-'Server Core' counterparts are found, add these |
| 467 | if len(regularcounterparts) >= 1: |
| 468 | for rc in regularcounterparts: |
| 469 | newfound.append(rc) |
| 470 | # Otherwise, add the 'Server Core' CVE |
| 471 | else: |
| 472 | newfound.append(r) |
| 473 | |
| 474 | return newfound |
| 475 | |
| 476 | |
| 477 | # Filter CVEs that are applicable to this system |