Last active
April 27, 2022 21:51
-
-
Save drewchurch/cd513d67ef9005f60e9c1fb0c02990b6 to your computer and use it in GitHub Desktop.
Find CVEs tagged in Splunk Security Content (splunk/security_content) and Check Against CISA's List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from operator import truediv | |
import yaml, requests, json | |
from pathlib import Path | |
from argparse import ArgumentParser | |
import re | |
cisaUrl = 'https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json' | |
knownBadCVEs = [] | |
parser = ArgumentParser() | |
parser.add_argument( | |
"-i", | |
"--cve-ids", | |
default=None, | |
nargs="+", | |
help="Seek these CVE IDs in the ESCU repo.", | |
) | |
parser.add_argument( | |
"-u", | |
"--url", | |
default=None, | |
help="Find CVEs in this page" | |
) | |
args = parser.parse_args() | |
if args.cve_ids or args.url: | |
if args.cve_ids: | |
cveToFind = set(args.cve_ids) | |
else: | |
page = requests.get(args.url) | |
if page.status_code == 200: | |
cveList = re.findall("CVE-\\d{4}-\\d{4,7}",page.text) | |
cveToFind = set(cveList) | |
for c in cveToFind: | |
knownBadCVEs.append({ | |
'cveId': c, | |
'detection_found': "false" | |
}) | |
print('cve,correlation_search_name') | |
for detection in Path("security_content/detections/").rglob('*.yml'): | |
with open (detection, 'r') as file: | |
doc = yaml.load(file, Loader=yaml.FullLoader) | |
if 'cve' in doc["tags"]: | |
cvedict = doc["tags"]["cve"] | |
name = "ESCU - " + doc["name"] + " - Rule" | |
if len(cvedict) > 0: | |
for cve_detection in cvedict: | |
for c in knownBadCVEs: | |
if c['cveId'] == cve_detection: | |
c['detection_found'] = "true" | |
print(cve_detection + "," + name) | |
cveWithNoDetection = filter(lambda c: c['detection_found'] == "false", knownBadCVEs) | |
prettyList = [] | |
for i in list(cveWithNoDetection): | |
prettyList.append(i['cveId']) | |
print("{0} CVEs with no detection found:".format(len(prettyList))) | |
print(prettyList) | |
else: | |
response = requests.get(cisaUrl) | |
if response.status_code == 200: | |
jsonData = json.loads(response.text) | |
for cve in jsonData['vulnerabilities']: | |
knownBadCVEs.append({ | |
'cveId' : cve['cveID'], | |
'dateAdded': cve['dateAdded']}) | |
print('cve,correlation_search_name,cisa_known_exploited,cisa_date_added') | |
for detection in Path("security_content/detections/").rglob('*.yml'): | |
with open (detection, 'r') as file: | |
doc = yaml.load(file, Loader=yaml.FullLoader) | |
if 'cve' in doc["tags"]: | |
cvedict = doc["tags"]["cve"] | |
name = "ESCU - " + doc["name"] + " - Rule" | |
if len(cvedict) > 0: | |
for cve in cvedict: | |
for c in knownBadCVEs: | |
dateAdded = "" | |
knownBad = "false" | |
if c['cveId'] == cve: | |
knownBad = "true" | |
dateAdded = c['dateAdded'] | |
break | |
print(cve + "," + name + "," + knownBad + "," + dateAdded) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Output as of 27APR2022 running in --cve-id/-I mode:
and running in normal 'report all the CVEs and CISA KEVs mode':