carbonblack / cb-yara-connector

Analyze binaries collected in VMware Carbon Black EDR against Yara rules.
36 stars 8 forks source link

[bugfix] rules without score not generating alerts #47

Open ericzinnikas opened 1 year ago

ericzinnikas commented 1 year ago

Pull request checklist

Please check if your PR fulfills the following requirements:

Pull request type

Please check the type of change your PR introduces:

What is the ticket or issue number?

Pull Request Description

Per this CB Knowledge Base article and what I'm assuming is the intent of the get_high_score function here:

If there is no "score" value assigned by the rule, but a hit is determined, it will get a default score of 100

However, there is a bug in the get_high_score function. Since match.meta.get("score", 0) evaluates to 0 if "score" is unset in the rule, but "score" is set to -1 before this loop, the condition will always evaluate to True. Thus, the following line match.meta.get("score") sets score to None and the return 100 line is unreachable.

This has the effect of causing rules without a score set to not generate any alerts. It appears the bug was introduced in this change: https://github.com/carbonblack/cb-yara-connector/commit/35afcac8908db95850d66b45f2933bf7f1bea601 -- when the default score value was changed from 0 to 1, the condition was not updated along with it.

While the README indicates: "Your rules must have meta section with a score = [1-10] tag to appropriately score matching binaries", this conflicts with the guidance given in the KB article, the (assumed) intent of the get_high_score function and the fact that CB seems to score alerts from 1-100 -- thus, I have updated the README as well.

Does this introduce a breaking change?

How Has This Been Tested?

Buggy behavior confirmed locally with test yara rules (with and without score values). New mock test added to simulate a rule with an empty meta section and thus no set "score" value. Have not yet been able to create manual rpm package to test this fix directly on a CB server.