<?xml version="1.0" encoding="utf-8"?>
<Sysmon schemaversion="4.90">

  <!--
    Konzervativní serverová konfigurace Sysmon pro sběr do Wazuh.

    Nepoužívá FileDelete Event ID 23, takže smazané soubory
    nearchivuje.

    FileDeleteDetected Event ID 26 pouze zaznamenává vybraná mazání.
  -->

  <HashAlgorithms>sha256,imphash</HashAlgorithms>
  <CheckRevocation>true</CheckRevocation>
  <DnsLookup>false</DnsLookup>

  <EventFiltering>

    <!-- =============================================================== -->
    <!-- EVENT ID 1: PROCESS CREATE                                      -->
    <!-- =============================================================== -->

    <RuleGroup
      name="ProcessCreate - security relevant binaries"
      groupRelation="or">

      <ProcessCreate onmatch="include">

        <Image name="PowerShell" condition="end with">\powershell.exe</Image>
        <Image name="PowerShell Core" condition="end with">\pwsh.exe</Image>

        <Image name="Command Prompt" condition="end with">\cmd.exe</Image>
        <Image name="Windows Script Host" condition="end with">\wscript.exe</Image>
        <Image name="Console Script Host" condition="end with">\cscript.exe</Image>
        <Image name="MSHTA" condition="end with">\mshta.exe</Image>

        <Image name="Rundll32" condition="end with">\rundll32.exe</Image>
        <Image name="Regsvr32" condition="end with">\regsvr32.exe</Image>
        <Image name="Certutil" condition="end with">\certutil.exe</Image>
        <Image name="Bitsadmin" condition="end with">\bitsadmin.exe</Image>
        <Image name="MSIExec" condition="end with">\msiexec.exe</Image>
        <Image name="CMSTP" condition="end with">\cmstp.exe</Image>
        <Image name="InstallUtil" condition="end with">\installutil.exe</Image>
        <Image name="RegAsm" condition="end with">\regasm.exe</Image>
        <Image name="RegSvcs" condition="end with">\regsvcs.exe</Image>
        <Image name="MSBuild" condition="end with">\msbuild.exe</Image>

        <Image name="PsExec" condition="end with">\psexec.exe</Image>
        <Image name="PsExec service" condition="end with">\psexesvc.exe</Image>
        <Image name="ProcDump" condition="end with">\procdump.exe</Image>
        <Image name="WhoAmI" condition="end with">\whoami.exe</Image>
        <Image name="NLTest" condition="end with">\nltest.exe</Image>
        <Image name="DSQuery" condition="end with">\dsquery.exe</Image>
        <Image name="Net" condition="end with">\net.exe</Image>
        <Image name="Net1" condition="end with">\net1.exe</Image>
        <Image name="SC" condition="end with">\sc.exe</Image>
        <Image name="Scheduled Tasks" condition="end with">\schtasks.exe</Image>
        <Image name="Wevtutil" condition="end with">\wevtutil.exe</Image>
        <Image name="VSSAdmin" condition="end with">\vssadmin.exe</Image>
        <Image name="WBAdmin" condition="end with">\wbadmin.exe</Image>
        <Image name="BCDEdit" condition="end with">\bcdedit.exe</Image>

      </ProcessCreate>
    </RuleGroup>

    <RuleGroup
      name="ProcessCreate - suspicious command line"
      groupRelation="or">

      <ProcessCreate onmatch="include">

        <CommandLine
          name="Encoded or hidden PowerShell"
          condition="contains any">-encodedcommand;-enc ;-enc";-enc';-windowstyle hidden;-w hidden;-nop;-noni</CommandLine>

        <CommandLine
          name="PowerShell execution and download"
          condition="contains any">downloadstring;downloadfile;invoke-expression;iex(;invoke-webrequest;iwr ;start-bitstransfer;frombase64string;reflection.assembly</CommandLine>

        <CommandLine
          name="Credential dumping indicators"
          condition="contains any">sekurlsa;logonpasswords;lsadump;dcsync;minidump;comsvcs.dll</CommandLine>

        <CommandLine
          name="Shadow copy and recovery destruction"
          condition="contains any">delete shadows;shadowcopy delete;delete catalog;resize shadowstorage;recoveryenabled no;bootstatuspolicy ignoreallfailures</CommandLine>

        <CommandLine
          name="Security log clearing"
          condition="contains any">wevtutil cl ;clear-eventlog;remove-eventlog</CommandLine>

        <CommandLine
          name="Suspicious service or task creation"
          condition="contains any">schtasks /create;sc.exe create;sc create </CommandLine>

      </ProcessCreate>
    </RuleGroup>

    <RuleGroup
      name="ProcessCreate - execution from writable locations"
      groupRelation="or">

      <ProcessCreate onmatch="include">

        <Image
          name="Execution from Temp"
          condition="contains">\Temp\</Image>

        <Image
          name="Execution from AppData"
          condition="contains">\AppData\</Image>

        <Image
          name="Execution from Downloads"
          condition="contains">\Downloads\</Image>

        <Image
          name="Execution from Public profile"
          condition="contains">\Users\Public\</Image>

        <Image
          name="Execution from recycle bin"
          condition="contains">\$Recycle.Bin\</Image>

      </ProcessCreate>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 3: NETWORK CONNECTION                                  -->
    <!-- =============================================================== -->

    <RuleGroup
      name="NetworkConnect - suspicious processes"
      groupRelation="or">

      <NetworkConnect onmatch="include">

        <Image name="PowerShell network connection" condition="end with">\powershell.exe</Image>
        <Image name="PowerShell Core network connection" condition="end with">\pwsh.exe</Image>
        <Image name="CMD network connection" condition="end with">\cmd.exe</Image>
        <Image name="WScript network connection" condition="end with">\wscript.exe</Image>
        <Image name="CScript network connection" condition="end with">\cscript.exe</Image>
        <Image name="MSHTA network connection" condition="end with">\mshta.exe</Image>

        <Image name="Rundll32 network connection" condition="end with">\rundll32.exe</Image>
        <Image name="Regsvr32 network connection" condition="end with">\regsvr32.exe</Image>
        <Image name="Certutil network connection" condition="end with">\certutil.exe</Image>
        <Image name="Bitsadmin network connection" condition="end with">\bitsadmin.exe</Image>
        <Image name="MSIExec network connection" condition="end with">\msiexec.exe</Image>
        <Image name="CMSTP network connection" condition="end with">\cmstp.exe</Image>

      </NetworkConnect>
    </RuleGroup>

    <RuleGroup
      name="NetworkConnect - high risk destination ports"
      groupRelation="or">

      <NetworkConnect onmatch="include">

        <DestinationPort
          name="High risk destination ports"
          condition="is any">4444;5555;6666;1234;31337</DestinationPort>

      </NetworkConnect>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 6: DRIVER LOAD                                         -->
    <!-- =============================================================== -->

    <RuleGroup
      name="DriverLoad - unsigned drivers"
      groupRelation="or">

      <DriverLoad onmatch="include">

        <Signed
          name="Unsigned driver loaded"
          condition="is">false</Signed>

      </DriverLoad>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 7: IMAGE LOAD                                          -->
    <!-- =============================================================== -->

    <RuleGroup
      name="ImageLoad - unsigned module in critical process"
      groupRelation="and">

      <ImageLoad onmatch="include">

        <Image name="LSASS" condition="end with">\lsass.exe</Image>
        <Image name="Services" condition="end with">\services.exe</Image>
        <Image name="SVCHOST" condition="end with">\svchost.exe</Image>
        <Image name="Winlogon" condition="end with">\winlogon.exe</Image>

        <Signed
          name="Unsigned image"
          condition="is">false</Signed>

      </ImageLoad>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 8: CREATE REMOTE THREAD                                -->
    <!-- =============================================================== -->

    <RuleGroup
      name="CreateRemoteThread - critical targets"
      groupRelation="or">

      <CreateRemoteThread onmatch="include">

        <TargetImage name="LSASS target" condition="end with">\lsass.exe</TargetImage>
        <TargetImage name="Winlogon target" condition="end with">\winlogon.exe</TargetImage>
        <TargetImage name="Services target" condition="end with">\services.exe</TargetImage>
        <TargetImage name="SVCHOST target" condition="end with">\svchost.exe</TargetImage>
        <TargetImage name="Explorer target" condition="end with">\explorer.exe</TargetImage>

      </CreateRemoteThread>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 9: RAW ACCESS READ                                     -->
    <!-- =============================================================== -->

    <RuleGroup
      name="RawAccessRead - all"
      groupRelation="or">

      <RawAccessRead onmatch="include" />

    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 10: PROCESS ACCESS                                     -->
    <!-- =============================================================== -->

    <RuleGroup
      name="ProcessAccess - suspicious LSASS access"
      groupRelation="and">

      <ProcessAccess onmatch="include">

        <TargetImage
          name="LSASS target"
          condition="end with">\lsass.exe</TargetImage>

        <GrantedAccess
          name="Suspicious access mask"
          condition="is any">0x1010;0x1038;0x1410;0x1438;0x143a;0x1fffff</GrantedAccess>

      </ProcessAccess>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 11: FILE CREATE                                        -->
    <!-- =============================================================== -->

    <RuleGroup
      name="FileCreate - executable in writable location"
      groupRelation="and">

      <FileCreate onmatch="include">

        <TargetFilename
          name="Writable location"
          condition="contains any">\Temp\;\AppData\;\Downloads\;\Users\Public\;\$Recycle.Bin\</TargetFilename>

        <TargetFilename name="EXE extension" condition="end with">.exe</TargetFilename>
        <TargetFilename name="DLL extension" condition="end with">.dll</TargetFilename>
        <TargetFilename name="SYS extension" condition="end with">.sys</TargetFilename>
        <TargetFilename name="COM extension" condition="end with">.com</TargetFilename>
        <TargetFilename name="SCR extension" condition="end with">.scr</TargetFilename>
        <TargetFilename name="CPL extension" condition="end with">.cpl</TargetFilename>
        <TargetFilename name="MSI extension" condition="end with">.msi</TargetFilename>
        <TargetFilename name="MSP extension" condition="end with">.msp</TargetFilename>
        <TargetFilename name="BAT extension" condition="end with">.bat</TargetFilename>
        <TargetFilename name="CMD extension" condition="end with">.cmd</TargetFilename>
        <TargetFilename name="PS1 extension" condition="end with">.ps1</TargetFilename>
        <TargetFilename name="PSM1 extension" condition="end with">.psm1</TargetFilename>
        <TargetFilename name="VBS extension" condition="end with">.vbs</TargetFilename>
        <TargetFilename name="VBE extension" condition="end with">.vbe</TargetFilename>
        <TargetFilename name="JS extension" condition="end with">.js</TargetFilename>
        <TargetFilename name="JSE extension" condition="end with">.jse</TargetFilename>
        <TargetFilename name="WSF extension" condition="end with">.wsf</TargetFilename>
        <TargetFilename name="WSH extension" condition="end with">.wsh</TargetFilename>
        <TargetFilename name="HTA extension" condition="end with">.hta</TargetFilename>
        <TargetFilename name="LNK extension" condition="end with">.lnk</TargetFilename>

      </FileCreate>
    </RuleGroup>

    <RuleGroup
      name="FileCreate - persistence locations"
      groupRelation="or">

      <FileCreate onmatch="include">

        <TargetFilename
          name="Startup folder"
          condition="contains">\Start Menu\Programs\Startup\</TargetFilename>

        <TargetFilename
          name="Scheduled task file"
          condition="contains">\Windows\System32\Tasks\</TargetFilename>

      </FileCreate>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 12-14: REGISTRY                                        -->
    <!-- =============================================================== -->

    <RuleGroup
      name="RegistryEvent - autorun persistence"
      groupRelation="or">

      <RegistryEvent onmatch="include">

        <TargetObject
          name="Run keys"
          condition="contains any">\CurrentVersion\Run;\CurrentVersion\RunOnce;\CurrentVersion\Policies\Explorer\Run</TargetObject>

        <TargetObject
          name="Winlogon persistence"
          condition="contains any">\Winlogon\Shell;\Winlogon\Userinit;\Winlogon\Notify</TargetObject>

        <TargetObject
          name="IFEO and SilentProcessExit"
          condition="contains any">\Image File Execution Options\;\SilentProcessExit\</TargetObject>

        <TargetObject
          name="AppInit and AppCert persistence"
          condition="contains any">\AppInit_DLLs;\AppCertDlls</TargetObject>

        <TargetObject
          name="LSA security packages"
          condition="contains any">\Lsa\Security Packages;\Lsa\Authentication Packages;\Lsa\Notification Packages</TargetObject>

      </RegistryEvent>
    </RuleGroup>

    <RuleGroup
      name="RegistryEvent - service persistence values"
      groupRelation="and">

      <RegistryEvent onmatch="include">

        <TargetObject
          name="Services registry tree"
          condition="contains">\SYSTEM\CurrentControlSet\Services\</TargetObject>

        <TargetObject name="ImagePath value" condition="end with">\ImagePath</TargetObject>
        <TargetObject name="ServiceDll value" condition="end with">\ServiceDll</TargetObject>
        <TargetObject name="FailureCommand value" condition="end with">\FailureCommand</TargetObject>
        <TargetObject name="ObjectName value" condition="end with">\ObjectName</TargetObject>

      </RegistryEvent>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 15: ALTERNATE DATA STREAM                              -->
    <!-- =============================================================== -->

    <RuleGroup
      name="FileCreateStreamHash - suspicious ADS"
      groupRelation="or">

      <FileCreateStreamHash onmatch="include">

        <TargetFilename
          name="ADS on executable or script"
          condition="contains any">.exe:;.dll:;.ps1:;.bat:;.cmd:;.vbs:;.js:;.hta:</TargetFilename>

      </FileCreateStreamHash>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 17-18: NAMED PIPES                                     -->
    <!-- =============================================================== -->

    <RuleGroup
      name="PipeEvent - known offensive tool patterns"
      groupRelation="or">

      <PipeEvent onmatch="include">

        <PipeName
          name="Suspicious named pipes"
          condition="contains any">\psexesvc;\paexec;\remcom;\csexec;\atsvc;\winreg;\svcctl;\samr;\lsarpc;\wkssvc;\DserNamePipe;\mojo.;\postex_;\status_;\MSSE-</PipeName>

      </PipeEvent>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 19-21: WMI PERSISTENCE                                 -->
    <!-- =============================================================== -->

    <RuleGroup
      name="WmiEvent - all permanent subscription activity"
      groupRelation="or">

      <WmiEvent onmatch="include" />

    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 22: DNS QUERY                                          -->
    <!-- =============================================================== -->

    <RuleGroup
      name="DnsQuery - suspicious processes"
      groupRelation="or">

      <DnsQuery onmatch="include">

        <Image name="PowerShell DNS query" condition="end with">\powershell.exe</Image>
        <Image name="PowerShell Core DNS query" condition="end with">\pwsh.exe</Image>
        <Image name="CMD DNS query" condition="end with">\cmd.exe</Image>
        <Image name="WScript DNS query" condition="end with">\wscript.exe</Image>
        <Image name="CScript DNS query" condition="end with">\cscript.exe</Image>
        <Image name="MSHTA DNS query" condition="end with">\mshta.exe</Image>
        <Image name="Rundll32 DNS query" condition="end with">\rundll32.exe</Image>
        <Image name="Regsvr32 DNS query" condition="end with">\regsvr32.exe</Image>
        <Image name="Certutil DNS query" condition="end with">\certutil.exe</Image>
        <Image name="Bitsadmin DNS query" condition="end with">\bitsadmin.exe</Image>

      </DnsQuery>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 25: PROCESS TAMPERING                                  -->
    <!-- =============================================================== -->

    <RuleGroup
      name="ProcessTampering - all"
      groupRelation="or">

      <ProcessTampering onmatch="include" />

    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 26: FILE DELETE DETECTED                               -->
    <!-- =============================================================== -->

    <RuleGroup
      name="FileDeleteDetected - executable deleted from writable location"
      groupRelation="and">

      <FileDeleteDetected onmatch="include">

        <TargetFilename
          name="Writable location"
          condition="contains any">\Temp\;\AppData\;\Downloads\;\Users\Public\;\$Recycle.Bin\</TargetFilename>

        <TargetFilename name="Deleted EXE" condition="end with">.exe</TargetFilename>
        <TargetFilename name="Deleted DLL" condition="end with">.dll</TargetFilename>
        <TargetFilename name="Deleted SYS" condition="end with">.sys</TargetFilename>
        <TargetFilename name="Deleted COM" condition="end with">.com</TargetFilename>
        <TargetFilename name="Deleted SCR" condition="end with">.scr</TargetFilename>
        <TargetFilename name="Deleted CPL" condition="end with">.cpl</TargetFilename>
        <TargetFilename name="Deleted MSI" condition="end with">.msi</TargetFilename>
        <TargetFilename name="Deleted BAT" condition="end with">.bat</TargetFilename>
        <TargetFilename name="Deleted CMD" condition="end with">.cmd</TargetFilename>
        <TargetFilename name="Deleted PS1" condition="end with">.ps1</TargetFilename>
        <TargetFilename name="Deleted VBS" condition="end with">.vbs</TargetFilename>
        <TargetFilename name="Deleted JS" condition="end with">.js</TargetFilename>
        <TargetFilename name="Deleted HTA" condition="end with">.hta</TargetFilename>

      </FileDeleteDetected>
    </RuleGroup>

    <!-- =============================================================== -->
    <!-- EVENT ID 29: FILE EXECUTABLE DETECTED                           -->
    <!-- =============================================================== -->

    <RuleGroup
      name="FileExecutableDetected - writable locations"
      groupRelation="or">

      <FileExecutableDetected onmatch="include">

        <TargetFilename
          name="Executable created in writable location"
          condition="contains any">\Temp\;\AppData\;\Downloads\;\Users\Public\;\$Recycle.Bin\;\ProgramData\</TargetFilename>

      </FileExecutableDetected>
    </RuleGroup>

  </EventFiltering>
</Sysmon>