Skip to content

fix(yara): detect multiline walk-encrypt-overwrite ransomware - #860

Merged
rng1995 merged 3 commits into
NVIDIA:mainfrom
udsy19:fix/yara-ransomware-multiline
Oct 28, 2026
Merged

rng1995 merged 3 commits into
NVIDIA:mainfrom
udsy19:fix/yara-ransomware-multiline

Conversation

@udsy19

@udsy19 udsy19 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #859.

Impact: silent-wrong-result

Who reaches this: any skillspector scan (CLI or MCP scan_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_encrypt and $mass_overwrite have no dot-all flag, so they need os.walk( on the same line as the encrypt/open call.

What the user observes: a script that encrypts every file under ~ in place scans as score: 14, recommendation: SAFE with no YARA finding. With this change it reports YR1 HIGH ransomware_behavior_multiline and score: 34, recommendation: CAUTION.

Fix

ransomware_behavior is unchanged. A new rule, ransomware_behavior_multiline (HIGH, confidence 0.6), fires when os.walk(, an .encrypt(/.cipher( call and a binary-write open() (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 when ransomware_behavior already 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_multiline does. 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:

  • three positives: overwrite inside the walk loop, a helper defined before the walk, and an in-place r+b write. Each must produce exactly one YR1 HIGH/0.6 ransomware_behavior_multiline finding and no ransomware_behavior finding.
  • four negatives: walk plus an unrelated download, walk plus read-only hashing, single-file encryption with no walk, and a walk more than 1 KiB from the encrypt/write.
  • a single-line case that still reports only the CRITICAL ransomware_behavior.

Negative control: reverted malware.yar.b64 to main and kept the new test:

FAILED tests/nodes/analyzers/test_static_yara.py::TestBuiltInRansomwareRule::test_multiline_walk_encrypt_overwrite_without_note_is_detected[overwrite-in-walk-loop]
FAILED tests/nodes/analyzers/test_static_yara.py::TestBuiltInRansomwareRule::test_multiline_walk_encrypt_overwrite_without_note_is_detected[helper-defined-before-walk]
FAILED tests/nodes/analyzers/test_static_yara.py::TestBuiltInRansomwareRule::test_multiline_walk_encrypt_overwrite_without_note_is_detected[read-write-in-place]
3 failed

With the fix: 3 passed. tests/nodes/analyzers/test_static_yara.py and tests/integration/test_ransomware_rule.py give 361 passed. ruff check and ruff format --check are clean.

#752 also re-encodes malware.yar.b64 (in info_stealer), so whichever PR lands second will need to decode and re-encode.

Signed-off-by: Udaya Tejas udayatejas2004@gmail.com

`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 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@rng1995
rng1995 merged commit 3ca7def into NVIDIA:main Oct 28, 2026
6 checks passed
rng1995 pushed a commit that referenced this pull request Oct 30, 2026
`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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ransomware_behavior misses multi-line encrypt-in-place scripts

2 participants