Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dedup YARA findings #480

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion guarddog/analyzer/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def analyze_yara(self, path: str, rules: Optional[set] = None) -> dict:
errors: Dict[str, str] = {}
issues = 0

rule_results = defaultdict(list)
rule_results: defaultdict[dict, list[dict]] = defaultdict(list)

rules_path = {
rule_name: os.path.join(SOURCECODE_RULES_PATH, f"{rule_name}.yar")
Expand Down Expand Up @@ -210,6 +210,17 @@ def analyze_yara(self, path: str, rules: Optional[set] = None) -> dict:
"code": self.trim_code_snippet(str(i.matched_data)),
'message': m.meta.get("description", f"{m.rule} rule matched")
}

# since yara can match the multiple times in the same file
# leading to finding several times the same word or pattern
# this dedup the matches
if [
f
for f in rule_results[m.rule]
if finding["code"] == f["code"]
]:
continue

issues += len(m.strings)
rule_results[m.rule].append(finding)
except Exception as e:
Expand Down