Skip to content

Commit 76c08f9

Browse files
authored
Merge pull request #2457 from CERT-Bund/extract_cve_from_tag
Add extract_cve_from_tag to Shadowserver parser _config.py
2 parents 5cd5a40 + 3c32675 commit 76c08f9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

intelmq/bots/parsers/shadowserver/_config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,20 @@ def category_or_detail(value: str, row: Dict[str, str]) -> str:
290290
return row.get('detail', '')
291291

292292

293+
def extract_cve_from_tag(tag: str) -> Optional[str]:
294+
""" Returns a string with a sorted semicolon-separated list of CVEs or None if no CVE found in tag. """
295+
cveset = set()
296+
tags = tag.split(";")
297+
298+
for t in tags:
299+
if re.match('^cve-[0-9]+-[0-9]+$', t):
300+
cveset.add(t)
301+
302+
if not (len(cveset)):
303+
return None
304+
return (';'.join(str(c) for c in sorted(cveset)))
305+
306+
293307
functions = {
294308
'add_UTC_to_timestamp': add_UTC_to_timestamp,
295309
'convert_bool': convert_bool,
@@ -308,6 +322,7 @@ def category_or_detail(value: str, row: Dict[str, str]) -> str:
308322
'scan_exchange_type': scan_exchange_type,
309323
'scan_exchange_identifier': scan_exchange_identifier,
310324
'category_or_detail': category_or_detail,
325+
'extract_cve_from_tag': extract_cve_from_tag,
311326
}
312327

313328

0 commit comments

Comments
 (0)