Implementing NOT operation as !=
#80
-
Hello, I am migrating the STIX backend to pySigma, in order to translate rules includes
so in case of (and the other way around with OR cases) How do you recommend to do such translation? we do control the nodes in the Sigmac version (https://github.com/SigmaHQ/sigma/blob/8fa8a7355141b525f5764ad5ff86caf6afc641c7/tools/sigma/backends/stix.py#L143), but wonder what would be the best way to implement that in the new pySigma |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
All node conversion methods of a backend have a parameter The first step of the solution of your problem would be to add a negation toggle to this property that is set to Then you override the Finally, you have to override the methods for converting OR, AND and field=value nodes that they use the other operators. This could be done by checking the negation toggle from the state and call the other method (e.g. in Replacement of the |
Beta Was this translation helpful? Give feedback.
-
Hi @barvhaim! We had exactly the same issue when creating the Loki backend for pySigma. We initially took the approach suggested here by @thomaspatzke - which worked, but we found a number of edge cases that caused issues for us. We ended up writing a function that is called before the conversion process runs, which updates the Sigma parse tree rather than trying to handle the negated state on the fly during the conversion. Overall, I found this approach reduced the complexity of our conversion code and made it easier to test - a win on both fronts! |
Beta Was this translation helpful? Give feedback.
All node conversion methods of a backend have a parameter
state
(e.g.convert_condition_field_eq_val_str
. This is aConversionState
object that contains aprocessing_state
property.The first step of the solution of your problem would be to add a negation toggle to this property that is set to
False
at the beginning of the conversion. The best place for this would be theconvert_condition
method of a backend by overriding it and first adding this property and then callingsuper().convert_condition(...)
.Then you override the
convert_condition_not
method in a similar way, but now use it to toggle the state.Finally, you have to override the methods for converting OR, AND and field=value no…