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

feat: Add support for rule metadata to be output in scan mode #170

Merged
merged 9 commits into from
Aug 2, 2024

Conversation

wxsBSD
Copy link
Contributor

@wxsBSD wxsBSD commented Aug 1, 2024

This adds support for the -m flag to the scan command, which will print rule metadata.

I'm following the output of the original YARA implementation when outputting things as to try and not break any scripts that may expect the output in a certain format. I'm open to suggestions on ways to make this easier to read if you think we should just break existing scripts and come up with a new format here.

wxsBSD added 3 commits August 1, 2024 15:37
This adds support for the -m flag (print metadata) so that rule metadata is
printed when a scan matches. Currently only outputs in text form, json will be
next.
cli/src/commands/scan.rs Outdated Show resolved Hide resolved
wxsBSD added 2 commits August 2, 2024 10:39
If a string is using the xor modifier we now display the xor information (key
and plaintext) in both text and json output modes.

```
wxs@mbp yara-x % ./target/debug/yr scan -o ndjson -s rules/a.yara ~/src/yara/tests/data/xor.out | jq .
{
  "path": "/Users/wxs/src/yara/tests/data/xor.out",
  "rules": [
    {
      "identifier": "freebsd",
      "strings": [
        {
          "identifier": "$a",
          "start": 28,
          "length": 19,
          "data": "Uihr!qsnfs`l!b`oonu",
          "xor_key": 1,
          "plaintext": "This program cannot"
        },
        {
          "identifier": "$a",
          "start": 52,
          "length": 19,
          "data": "Vjkq\\\"rpmepco\\\"acllmv",
          "xor_key": 2,
          "plaintext": "This program cannot"
        },
        {
          "identifier": "$b",
          "start": 4,
          "length": 19,
          "data": "This program cannot"
        }
      ]
    }
  ]
}
wxs@mbp yara-x % ./target/debug/yr scan -s rules/a.yara ~/src/yara/tests/data/xor.out
freebsd /Users/wxs/src/yara/tests/data/xor.out
0x1c:19:$a xor(0x1,This program cannot): Uihr!qsnfs`l!b`oonu
0x34:19:$a xor(0x2,This program cannot): Vjkq\"rpmepco\"acllmv
0x4:19:$b: This program cannot
────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 1 file(s) scanned in 0.0s. 1 file(s) matched.
wxs@mbp yara-x %
```

When using --print-strings-limit it looks like this in text mode:

```
wxs@mbp yara-x % ./target/debug/yr scan -s --print-strings-limit 5 rules/a.yara ~/src/yara/tests/data/xor.out
freebsd /Users/wxs/src/yara/tests/data/xor.out
0x1c:19:$a xor(0x1,This ): Uihr! ... 14 more bytes
0x34:19:$a xor(0x2,This ): Vjkq\" ... 14 more bytes
0x4:19:$b: This  ... 14 more bytes
────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 1 file(s) scanned in 0.0s. 1 file(s) matched.
wxs@mbp yara-x %
```

Not sure if we want to print the "... X more bytes" part in the plaintext or
just leave it implied.

I've also included a bug fix here where we were only printing the last matching
pattern.
@plusvic
Copy link
Member

plusvic commented Aug 2, 2024

Hey @wxsBSD, while reviewing your PR, I'd suggest the following code changes:

👉 Code Suggestion for #170

#170

You can also review and apply these suggestions locally on your machine.

Learn more about GitKraken Code Suggest

Code Suggest liberates your code reviews from GitHub's restrictive, comment-only feedback style. As simple as suggesting changes in a Google-doc, provide real code suggestions from where you code, e.g. your IDE, and on anything in your project — not just on the lines of code changed in the PR.

Join your team on GitKraken to speed up PR review.

@plusvic
Copy link
Member

plusvic commented Aug 2, 2024

Ignore this "Code Suggestion" stuff, it was my first time using it, and requires that you use the git UI application that I use. I submitted my changes to as a commit to this branch.

@plusvic plusvic merged commit 7332a7b into VirusTotal:main Aug 2, 2024
15 checks passed
@wxsBSD wxsBSD deleted the missing_flags branch August 2, 2024 17:12
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