fix: [export_mod/yara_export] escape attribute values in generated YARA string/meta literals - #896
Open
elhoim wants to merge 1 commit into
Open
fix: [export_mod/yara_export] escape attribute values in generated YARA string/meta literals#896elhoim wants to merge 1 commit into
elhoim wants to merge 1 commit into
Conversation
…RA string/meta literals The dynamically-generated rule (YaraRule.__str__) interpolates attribute values and event/org metadata directly into double-quoted YARA string literals without escaping backslashes or embedded double quotes. An attacker-influenced attribute value (or event info/org name) containing a `"` breaks out of the literal and corrupts the generated rule; unlike the handle_yara path, which validates the raw YARA text supplied by a user via yara.compile(), this generated path was never validated at all, so a broken rule was silently exported as if it were valid YARA. Both string and meta values are now backslash/quote-escaped before being quoted, and the full generated ruleset is compiled with yara.compile() before being returned; if it fails to compile, the module now reports an error instead of silently emitting an invalid ruleset. Verified with flake8 (clean) and the full test suite against a locally started misp-modules server on port 6784: 161 passed, 4 skipped, 5 subtests passed, matching baseline, including the existing test_yara_export case (which exercises the handle_yara path and is unaffected). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
YaraRule.__str__inmisp_modules/modules/export_mod/yara_export.pyinterpolated MISP attribute values and meta values (event info, org name, link attributes) directly into double-quoted YARA string literals without escaping backslash or embedded double-quote characters:Unlike the
handle_yarapath in the same module, the ruleset built by this class was also never passed throughyara.compile()before being returned.Impact: an attacker-controlled MISP attribute value (or event info / org name) containing a
"or\breaks out of the YARA string literal it was placed in. Depending on the surrounding content this either produces a ruleset that fails to compile in the analyst's YARA engine (an unusable export with no warning from the module) or, more seriously, lets attacker-supplied text be spliced into the rule body as YARA syntax rather than staying inert data — an analyst exporting attributes to a YARA rule has no indication the export is malformed or manipulated until it fails, or misbehaves, downstream.Fix
Escape
\and"in both the strings-section and meta-section interpolation sites, and compile the fully generated ruleset withyara.compile()before returning it, returning amisperrorsresponse instead of silently emitting an invalid/unsafe ruleset if compilation fails.Verification
flake8on the changed file: clean, no output.python -m pytest tests/against a localmisp-modulesinstance:161 passed, 4 skipped, 5 subtests passed.Found during a review of the repository; other findings are being submitted as separate PRs.
🤖 Generated with Claude Code
https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8