target / strelka

Real-time, container-based file scanning at enterprise scale
Other
878 stars 113 forks source link

ScanYara Safe Key Collection #412

Closed phutelmyer closed 11 months ago

phutelmyer commented 12 months ago

Describe the change This PR makes a couple changes that assists in YARA loading issues:

1) Ensures that if a backend.yml exists without a specific key (e.g., yara.compiled), a default is used to prevent an unhandled exception.

YARA failure prior to fix:

strelka-backend-1      | 2023-11-13 18:08:22 - [ERROR] root [strelka.scan_wrapper]: ScanYara: unhandled exception while scanning uid a197de79-b500-4cb0-ae4f-64a14f7c54e6 (see traceback below)
strelka-backend-1      | Traceback (most recent call last):
strelka-backend-1      |   File "/usr/local/lib/python3.10/dist-packages/strelka-0.0.0-py3.10.egg/strelka/strelka.py", line 779, in scan_wrapper
strelka-backend-1      |     self.scan(data, file, options, expire_at)
strelka-backend-1      |   File "/usr/local/lib/python3.10/dist-packages/strelka-0.0.0-py3.10.egg/strelka/scanners/scan_yara.py", line 58, in scan
strelka-backend-1      |     self.load_yara_rules(options)
strelka-backend-1      |   File "/usr/local/lib/python3.10/dist-packages/strelka-0.0.0-py3.10.egg/strelka/scanners/scan_yara.py", line 130, in load_yara_rules
strelka-backend-1      |     if compiled.get("enabled", False):
strelka-backend-1      | AttributeError: 'NoneType' object has no attribute 'get'

2) A warning is provided to the user if an issue loading YARA rules is observed. This prevents the user from needing prior knowledge of needing to look at yara.flags for potential exceptions.

backend-1      | *************************************************
backend-1      | * WARNING: YARA File Loading Issue Detected     *
backend-1      | *************************************************
backend-1      | There was an issue loading the compiled YARA file. Please check that all YARA rules can be
backend-1      | successfully compiled. Additionally, verify the 'ScanYara' configuration in Backend.yaml to
backend-1      | ensure the targeted path is correct. This issue needs to be resolved for proper scanning
backend-1      | functionality.
backend-1      | 
backend-1      | Error: /etc/strelka/yara/rules.yara(38): undefined identifier "is__elf"
backend-1      | *************************************************

3) Added a recommendation to the README which recommends users precompile their YARA rules prior to Strelka start.

Describe testing procedures

No unexpected errors / warnings were thrown and files were successfully scanned.

Sample output N/A

Checklist