1
+ # Copyright 2020-2023 VMware, Inc.
2
+ # SPDX-License-Identifier: BSD-2-Clause
3
+
4
+ from typing import List
5
+ from parsers .base import ParserBase
6
+ from models import DependencyRelation , ExtractedDependency , ExtractedFinding
7
+ import re
8
+
9
+
10
+ class DNFParser (ParserBase ):
11
+
12
+ yara_rule = """
13
+ rule yum
14
+ {
15
+ meta:
16
+ description = "detects dnf being run and provides package and version extraction"
17
+ parser = "DNFParser"
18
+ strings:
19
+ $install_or_update = /\\ bdnf(\\ b|\\ b.*\\ b)(update|install)\\ b/
20
+ condition:
21
+ any of them
22
+ }
23
+ """
24
+ parser_name = "DNFParser"
25
+ parser_description = "This parser is designed to extract dependencies brought in through the DNF package installer."
26
+
27
+ def on_load (self ) -> None :
28
+ # self.dependency_extractor_regex = re.compile(r"Installed:(.*?)(?=Complete.)")
29
+ self .dependency_extractor_regex = re .compile (
30
+ r"\s+(\S+-\S+-\S+(-\d+)?\.\S+)+"
31
+ )
32
+
33
+ def get_document_dependencies (self , document : str ) -> List [ExtractedDependency ]:
34
+ dependencies = []
35
+ print ("%%%%%%is it coming in dnf parser%%%%%%%%%" )
36
+ dependency_matches = self .dependency_extractor_regex .findall (document )
37
+ packages = []
38
+ for match in dependency_matches :
39
+ package_pattern = r"([a-zA-Z-]+)-([\d\.\-a-zA-Z]+)\.(\S+)\s*"
40
+ package_matches = re .findall (package_pattern , match [0 ])
41
+ packages .extend (package_matches )
42
+
43
+ for package in packages :
44
+ print ("$$$$$$$$$$$$$$$$$$$$" )
45
+ pack = '' .join (package )
46
+ dependencies .append (
47
+ ExtractedDependency (
48
+ name = f"{ package [0 ]} " ,
49
+ version = f"{ package [1 ]} " ,
50
+ type = "Fedora" ,
51
+ extraction_source = f"{ '' .join (package )+ '.rpm' } " ,
52
+ download_location = "Fedora" ,
53
+ result = DependencyRelation .CONSUMED ,
54
+ )
55
+ )
56
+ return dependencies
57
+
58
+ def get_document_findings (self , document : str ) -> List [ExtractedFinding ]:
59
+ findings = []
60
+
61
+ return findings
0 commit comments