wagga40 / Zircolite

A standalone SIGMA-based detection tool for EVTX, Auditd and Sysmon for Linux logs
671 stars 91 forks source link

Windows misconfiguration #27

Closed blabla123sdfa closed 2 years ago

blabla123sdfa commented 2 years ago

Windows is not made by default to understand what a python script is or how to run it, even after the python installation. In order to not modify the registry settings, just add a simple element in the command line array, maintain the cross-platform ability and add more stability.

wagga40 commented 2 years ago

Hi, thank you for this PR !

blabla123sdfa commented 2 years ago
# import the library needed
import os
import sys

def retrieveRule(self, ruleFile):
        try:
            d={}
            #get python path
            pythonPath = Path(sys.executable)
            cmd = [pythonPath, self.sigmac, "-d", "--target", "sqlite", "-c", self.config, ruleFile, "--backend-option", f'table={self.table}']
            outputRaw = subprocess.run(args=cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, encoding='cp437')

            output = [rule for rule in outputRaw.stdout.split("\n") if not "Feel free" in rule]
            if "unsupported" in str(output):
                return {"rule": "", "file": ruleFile, "notsupported": True}
            else:
                with open(ruleFile, 'r') as stream:
                    docs = yaml.load_all(stream, Loader=yaml.FullLoader)
                    for doc in docs:
                        for k,v in doc.items():
                            if k == 'title':
                                title = v
                            if k == 'id':
                                d['title'] = title + " - " + self.CRC32_from_string(v)
                            if k in ['description','tags','level','author']:
                                d[k] = v
                d['rule']=output[:-1]
                return {"rule": d.copy(), "file": ruleFile, "notsupported": False}
        except Exception as e:
            return {"bad_file" : ruleFile, "exception" : e}

100% cross-platform. Also please check the other commit.

wagga40 commented 2 years ago

Also please check the other commit.

They were OK.

Please commit your new code in the PR. Please note that I won't merge if you leave encoding='cp437', you can add an optional parameter to choose encoding.

Thanks for the work.

wagga40 commented 2 years ago

genRules has been removed in favor of using directly Sigmac.