Repository navigation
fix(yara): detect multiline walk-encrypt-overwrite ransomware - #860
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>
rng1995
left a comment
There was a problem hiding this comment.
[SkillSpector Review]
Value and readiness
Ready. The decoded rule adds a bounded walk/encrypt/binary-write heuristic and avoids duplicating an existing ransomware_behavior result.
Material findings
No required changes found.
PIC tradeoffs
The 1 KiB proximity heuristic cannot prove that the encrypted output overwrites the walked files. The lower HIGH/0.6 confidence and explicit description make the encrypted-backup false-positive tradeoff visible. Broader data flow remains outside this signature.
Verification and gaps
Reviewed the complete diff, description, linked issue material, all previous reviews/comments/replies and pinned-head surrounding source at 293ff281d41e2baa98ed64c0e1ea666249bc64c2. Decoded the rule as data and compared the normalized decoded base/head; only the new ransomware_behavior_multiline rule is added. Reviewed the three positives, four negatives and exact-rule single-line deduplication assertion. The negative helper uses substring matching, so it also rejects the new multiline rule. GitHub reports changes: SUCCESS, lint: SUCCESS, test-unit: SUCCESS, OpenCode TypeScript Tests: SUCCESS, DCO Check: SUCCESS, docker-smoke: SUCCESS. No contributor code, tests, imports, build steps or scanner invocations were executed during this review.
`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> (cherry picked from commit 3ca7def) Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
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