Skip to content

fix(yara): detect multiline socket reverse shells - #594

Open
deepujain wants to merge 2 commits into
NVIDIA:mainfrom
deepujain:fix/592-multiline-reverse-shell
Open

deepujain wants to merge 2 commits into
NVIDIA:mainfrom
deepujain:fix/592-multiline-reverse-shell

Conversation

@deepujain

Copy link
Copy Markdown
Contributor

Summary

Fixes #592 by bounding the Python and Perl socket reverse-shell YARA expressions across multiline source.

Validation

  • ruff check tests/nodes/analyzers/test_static_yara.py
  • ruff format --check tests/nodes/analyzers/test_static_yara.py
  • Base64 rule package decodes successfully

Risk

The bounded 200-character spans preserve proximity between socket creation and connection, avoiding an unbounded cross-file match.

Signed-off-by: Deepak Jain <deepujain@gmail.com>
The bounded-gap patterns used '.' which does not match newlines in
YARA regexes, so socket creation and .connect() on separate lines
never matched. Add the 's' (dotall) modifier to the python_socket
and perl_socket patterns so multiline forms are detected.

Fixes the two failing parametrized cases in
test_builtin_reverse_shell_matches_multiline_socket_forms.

Signed-off-by: Deepak Jain <deepujain@gmail.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.

Built-in reverse_shell YARA rule misses multi-line Python/Perl socket reverse shells

1 participant