Conversation
$python_socket and $perl_socket in the built-in reverse_shell rule
(src/skillspector/yara_rules/malware.yar.b64) use `.*` between the
socket-family constant and the connect call with no dotall modifier.
YARA's `.` does not match `\n` by default, so the pattern only matches
when the whole snippet is on one physical line. A reverse shell
bundled as a script file (rather than passed to `python3 -c '...'` /
`perl -e '...'`) writes socket.socket(...) and .connect(...) as
separate statements and the rule never fires — reverse_shell falls
back to any of the other, unrelated strings in the same rule, so a
plain multi-line Python or Perl socket reverse shell with no other
telltale string is scored SAFE.
Add `s` (dotall) with a bounded {0,200} gap on both strings so the
match still requires the socket call and the connect call to be
close together, rather than opening an unbounded any-file-wide match
that would trade the false negative for a false positive.
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 #592
What was wrong
The built-in
reverse_shellrule's$python_socketand$perl_socketstrings (src/skillspector/yara_rules/malware.yar.b64, base64-packaged) use.*between the socket-family constant and the connect call with no dotall modifier:YARA's
.does not match\nby default, so both only match when the whole snippet is on one physical line — thepython3 -c '...'/perl -e '...'one-liner form. A reverse shell bundled as an actual script file writessocket.socket(...)and.connect(...)as separate statements, and neither string — nor any other string in the rule — matches it.static_yarareportscompleted, the scan stays SAFE,--fail-on-incompleteexits 0.Who reaches this / entry point: every
skillspector scaninvocation goes through the built-inreverse_shellYARA rule on every scanned artifact — this is the default, always-on detection path, not an opt-in flag. Triggered by: a skill bundle containing a Python (or Perl) source file with a raw socket-based reverse shell written as normal multi-line code, which is how this payload looks when it ships as a file rather than a one-liner.Fix
Add
s(dotall) to both strings, bounded with.{0,200}instead of unbounded.*, so the match still requires the socket call and the connect call to sit within roughly a couple of screens of each other rather than opening an any-file-wide match. Verified this bound does not introduce a false positive: an unrelatedsocket.socket(...)/.connect(...)pair 200 lines apart in the same file does not match.Confirmed the regex content is unchanged since the initial release (
7ced4fb) and untouched by the base64-repackaging commit (90a9181, #236) — that commit changed only the on-disk encoding, not any rule text.Testing
New test
test_reverse_shell_rule_matches_multiline_python_socketbuilds a realistic multi-line Python reverse shell (base64-encoded fixture, matching this test file's existing convention of not embedding raw malware-signature strings in the source, per the module docstring) and assertsreverse_shell/YR1fires.Negative control, reverting only
malware.yar.b64and keeping the new test:restoring the fix:
ruff check src/ tests/nodes/analyzers/test_static_yara.pyandruff format --check tests/nodes/analyzers/test_static_yara.py: all clean. (malware.yar.b64is not Python;ruff check src/ tests/in directory mode correctly skips it, matching how the repo's ownmake lintruns.)Note on the diff: because the rule file is base64-packaged, this two-line source change renders as a full-file diff in the
.b64blob. The decoded before/after above is the actual change; nothing else in the rule file moved.Impact: silent-wrong-result
Signed-off-by: Udaya Tejas udayatejas2004@gmail.com