theflakes / sigma_to_wazuh

Convert Sigma rules to Wazuh rules
MIT License
58 stars 14 forks source link

Issue with Or Translation with negate=Yes regex #20

Open CyberOverflow opened 10 months ago

CyberOverflow commented 10 months ago

With Using the default Core sigma rule set there is an issue with the following rule when its translated:

Original Sigma rule: https://github.com/SigmaHQ/sigma/blob/master/rules/windows/process_creation/proc_creation_win_hktl_relay_attacks_tools.yml

What I noticed:

<rule id="200521" level="15">
        <info type="link">https://github.com/SigmaHQ/sigma/tree/master/rules/windows/process_creation/proc_creation_win_hktl_relay_attacks_tools.yml</info>
        <!--Sigma Rule Author: Florian Roth (Nextron Systems)-->
        <!--Description: Detects different hacktools used for relay attacks on Windows for privilege escalation-->
        <!--Date: 2021/07/24-->
        <!--Status: test-->
        <!--ID: 5589ab4f-a767-433c-961d-c91f3f704db1-->
        <mitre>
            <id>attack.execution</id>
            <id>attack.t1557.001</id>
        </mitre>
        <description>Potential SMB Relay Attack Tool Execution</description>
        <options>no_full_log</options>
        <group>process_creation,windows,</group>
        <if_sid>18100, 60000, 60001, 60002, 60003, 60004, 60006, 60007, 60008, 60009, 60010, 60011, 60012</if_sid>
        <field name="win.eventdata.image" negate="yes" type="pcre2">(?i)HotPotatoes6</field>
        <field name="win.eventdata.image" negate="yes" type="pcre2">(?i)HotPotatoes7</field>
        <field name="win.eventdata.image" negate="yes" type="pcre2">(?i)(?:HotPotatoes\ )</field>
    </rule>

Potential resolutions:

theflakes commented 10 months ago

I'm not sure when I'll return to working on this unfortunately. I've moved to other solutions for rule writing. There are just too many logic limitations with OSSEC/Wazuh rules that I haven't time to push through right now.

Its complicated converting from a more expressive rule writing syntax to OSSEC/Wazuh. Where I ended up is trying to break Sigma rules down into passing sets, basically a tree structure that can be logically walked and create a Wazuh rule for each branch, but it isn't complete and you will see issues like what you ran into here.

CyberOverflow commented 10 months ago

totally understood.

I also just wanted some documentation of this issue in case someone runs into it in the future.

Thanks for doing a lot of the original heavy lifting for this project though! Wazuh logic is really limiting unfortunately. They're working on updating it I hear, but its slow moving and probably not for another year.

I've seen some other people using chainsaw to process sigma logic locally on the device so there are other options out there.

PiRomant commented 7 months ago

I've moved to other solutions for rule writing.

@theflakes, сan you tell what you're using?

theflakes commented 7 months ago

Still supporting legacy Wazuh rules but mostly in teaching labs.

Using Sigma in SecurityOnion playbooks.

Also using Elastalert and ELK alerts. No perfect solution that's open unfortunately. Wazuh still does the job but really wish it had OR logic between two statements in a rule.

theflakes commented 7 months ago

I added a filter to filter out any "1 of" that also includes "and" logic. This removes ~ 460 Sigma rules from conversion.

This won't fix all of the logic translation problems, but it will reduce them a good bit.

If I could use DeMorgan's Law to move all OR logic rules to AND, I could more easily convert Sigma to Wazuh. But, Wazuh would need to support two levels of negation which it doesn't unfortunately.

PiRomant commented 7 months ago

@theflakes, What if you split all conditions into separate rules and сombine it at the end.

<rule level=1>
<if_sid>selection_pe|selection_script|selection_juicypotato_enum</if_sid>
 <field name="win.eventdata.image" negate="no" type="pcre2">(?i)HotPotatoes6</field>

<rule level=1>
<if_sid>selection_pe|selection_script|selection_juicypotato_enum</if_sid>
 <field name="win.eventdata.image" negate="no" type="pcre2">(?i)HotPotatoes7</field>

<rule level=1>
<if_sid>selection_pe|selection_script|selection_juicypotato_enum</if_sid>
 <field name="win.eventdata.image" negate="no" type="pcre2">(?i)HotPotatoes </field>

With level !=0 you can change levels of negation

theflakes commented 7 months ago

I've implemented not propagation so that everything that is negated is explicitly so; e.g. not (selection and other) -> not selection and not other. This should remove some negation conversion errors.

The main issue is still ORs and 1_of's. Again, because of Wazuh limitations. i.e. need to create a rule per each new field that is ORed with other fields.

Have also filtered out cidr Sigma rules as converting this to Wazuh will need some thought.

theflakes commented 7 months ago

@theflakes, What if you split all conditions into separate rules and сombine it at the end.

<rule level=1>
<if_sid>selection_pe|selection_script|selection_juicypotato_enum</if_sid>
 <field name="win.eventdata.image" negate="no" type="pcre2">(?i)HotPotatoes6</field>

<rule level=1>
<if_sid>selection_pe|selection_script|selection_juicypotato_enum</if_sid>
 <field name="win.eventdata.image" negate="no" type="pcre2">(?i)HotPotatoes7</field>

<rule level=1>
<if_sid>selection_pe|selection_script|selection_juicypotato_enum</if_sid>
 <field name="win.eventdata.image" negate="no" type="pcre2">(?i)HotPotatoes </field>

With level !=0 you can change levels of negation

I've thought about this but not enough. I think maybe two passes over each sigma rule. Just not sure and will require a good bit of rewrite.