Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new renderer to display string matches for rules #488

Merged
merged 5 commits into from
Oct 6, 2024

Conversation

egibs
Copy link
Member

@egibs egibs commented Oct 5, 2024

I've been running yara -r <rule path> <path> -s a lot recently. Now that we track rule names in the Behavior struct, we can correlate this to the rule matches.

This PR adds a new renderer to display the file report path, its risk level, the number of rules that matched, each rule that has string matches, and the number of strings per rule match (sorted alphabetically by rule name ascending).

For example:

go run cmd/mal/mal.go --format strings analyze /usr/bin/bash
Matches for /usr/bin/bash [HIGH] (35 rules):
HOME [LOW] (2 strings): 
- HOME
- getenv
LANG_getenv [LOW] (2 strings): 
- LANG
- getenv
SHELL [LOW] (1 string): 
- SHELL
TERM [LOW] (1 string): 
- TERM
TMPDIR [LOW] (2 strings): 
- TMPDIR
- getenv
bash_history [HIGH] (1 string): 
- .bash_history
calls_shell [MED] (1 string): 
- /bin/sh
chdir_shell [LOW] (1 string): 
- cd which change the
chmod [MED] (1 string): 
- chmod
custom_path [LOW] (4 strings): 
- /bin:/usr/
- /sbin:/bin
- /usr/bin:/sbin
- PATH
dlsym [MED] (1 string): 
- dlsym
etc_hosts [MED] (1 string): 
- /etc/hosts
etc_path [LOW] (4 strings): 
- /etc/bash.bashrc
- /etc/hosts
- /etc/inputrc
- /etc/profile

Here's what it looks like in-terminal for analyze (partial screenshot):
image

The renderer works for scan as well:
image

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@egibs egibs requested a review from tstromberg October 5, 2024 21:54
egibs added 2 commits October 5, 2024 17:30
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
egibs added 2 commits October 6, 2024 15:37
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@egibs egibs merged commit 2a59576 into chainguard-dev:main Oct 6, 2024
6 checks passed
@egibs egibs deleted the print-string-matches branch October 8, 2024 12:41
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.

2 participants