@@ -44,6 +44,7 @@ class AzulPluginYara(BinaryPlugin):
4444 max_yara_include_depth = (int , 5 ),
4545 # Max number of yara streams to keep before dropping the rest.
4646 max_yara_hit_streams_to_keep = (Annotated [int , Field (gt = 0 , le = 100 )], 50 ),
47+ yara_upload_raw_rules_as_streams = (bool , True ),
4748 )
4849
4950 FEATURES = [
@@ -175,23 +176,24 @@ def execute(self, job: Job):
175176 self .add_feature_values ("yararule" , rule )
176177 found_raw_rule [rule ] = False
177178
178- # Find the raw rule and save it as a file
179- rule_file_path = self .namespace_to_rule_path [match .namespace ]
180- self .yara_include_depth = 0
181- raw_rule = self .fetch_original_rule (rule_file_path , match .identifier , self .logger )
182- if len (raw_rule ) > 0 :
183- new_rule = md5 (raw_rule ).hexdigest () # noqa: S324
184- # Rule was found
185- found_raw_rule [rule ] = True
186- if new_rule not in seen_rules_md5s :
187- seen_rules_md5s .append (new_rule )
188- # Add the original yara rule that hit as an augmented stream. Stop at max allowed Augmented streams.
189- if yara_rule_streams_added < self .cfg .max_yara_hit_streams_to_keep : # ty: ignore[unresolved-attribute] ty doesn't understand add_settings
190- raw_rule_with_header = (
191- f"// plugin: { self .NAME } , namespace_identifier: { rule } \n " .encode () + raw_rule
192- )
193- self .add_data (label = DataLabel .YARA_RULE_HIT , tags = {}, data = raw_rule_with_header )
194- yara_rule_streams_added += 1
179+ if self .cfg .yara_upload_raw_rules_as_streams : # ty: ignore[unresolved-attribute] ty doesn't understand add_settings
180+ # Find the raw rule and save it as a file
181+ rule_file_path = self .namespace_to_rule_path [match .namespace ]
182+ self .yara_include_depth = 0
183+ raw_rule = self .fetch_original_rule (rule_file_path , match .identifier , self .logger )
184+ if len (raw_rule ) > 0 :
185+ new_rule = md5 (raw_rule ).hexdigest () # noqa: S324
186+ # Rule was found
187+ found_raw_rule [rule ] = True
188+ if new_rule not in seen_rules_md5s :
189+ seen_rules_md5s .append (new_rule )
190+ # Add the original yara rule that hit as an augmented stream. Stop at max allowed Augmented streams.
191+ if yara_rule_streams_added < self .cfg .max_yara_hit_streams_to_keep : # ty: ignore[unresolved-attribute] ty doesn't understand add_settings
192+ raw_rule_with_header = (
193+ f"// plugin: { self .NAME } , namespace_identifier: { rule } \n " .encode () + raw_rule
194+ )
195+ self .add_data (label = DataLabel .YARA_RULE_HIT , tags = {}, data = raw_rule_with_header )
196+ yara_rule_streams_added += 1
195197
196198 for match_data in match .patterns :
197199 var = match_data .identifier
0 commit comments