{{ message }}
Repository navigation
Conversation
`ransomware_behavior`'s `$walk_encrypt` and `$mass_overwrite` have no dot-all flag, so they only match when `os.walk(` shares a line with the `.encrypt(` or `open(..., "wb")` call. Ordinary ransomware code puts the walk, the read, the encryption and the write-back on separate lines. Without a ransom note nothing in the rule fires, and a skill whose script encrypts every file under the home directory in place scores SAFE. Add a separate `ransomware_behavior_multiline` rule at HIGH / 0.6. It requires `os.walk(`, an `.encrypt(`/`.cipher(` call and a binary-write `open()` within 1 KiB of the same walk. A signature cannot prove that the write replaces the walked file, so this rule reports at reduced confidence, the same way `reverse_shell_multiline` does. It stays quiet when `ransomware_behavior` already matches, and that rule is unchanged. Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
…-multiline Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
…-multiline Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
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.

Fixes #859.
Impact: silent-wrong-result
Who reaches this: any
skillspector scan(CLI or MCPscan_skill) of a skill that bundles a Python script, through the built-in YARA rules (static_yara, YR1).Triggered when: a script walks a directory with
os.walk, encrypts each file and writes it back, with the calls on separate lines (the normal way to write it) and no ransom note.$walk_encryptand$mass_overwritehave no dot-all flag, so they needos.walk(on the same line as the encrypt/open call.What the user observes: a script that encrypts every file under
~in place scans asscore: 14, recommendation: SAFEwith no YARA finding. With this change it reports YR1 HIGHransomware_behavior_multilineandscore: 34, recommendation: CAUTION.Fix
ransomware_behavioris unchanged. A new rule,ransomware_behavior_multiline(HIGH, confidence 0.6), fires whenos.walk(, an.encrypt(/.cipher(call and a binary-writeopen()(wb,w+b,r+b,rb+) all fall within 1 KiB of the same walk, before or after it. The "before" side covers a helper function defined above the loop. The rule stays quiet whenransomware_behavioralready matches, so single-line cases still get one CRITICAL finding.A signature cannot prove that the write replaces the walked file. That is why the rule reports at reduced confidence, the same way
reverse_shell_multilinedoes. The known false positive is a backup tool that walks a tree and writes encrypted copies to new files. That case now gets HIGH/0.6 instead of nothing.The rule adds no new compiler warnings, and no file in this repository matches it.
Tests
In
TestBuiltInRansomwareRule:r+bwrite. Each must produce exactly one YR1 HIGH/0.6ransomware_behavior_multilinefinding and noransomware_behaviorfinding.ransomware_behavior.Negative control: reverted
malware.yar.b64tomainand kept the new test:With the fix: 3 passed.
tests/nodes/analyzers/test_static_yara.pyandtests/integration/test_ransomware_rule.pygive 361 passed.ruff checkandruff format --checkare clean.#752 also re-encodes
malware.yar.b64(ininfo_stealer), so whichever PR lands second will need to decode and re-encode.Signed-off-by: Udaya Tejas udayatejas2004@gmail.com