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

upgrade rules using updated script #839

Merged
merged 17 commits into from
Nov 29, 2023
Merged

upgrade rules using updated script #839

merged 17 commits into from
Nov 29, 2023

Conversation

mr-tz
Copy link
Collaborator

@mr-tz mr-tz commented Oct 25, 2023

#837 and all the comments broke the GitHub web UI...

Repeating the work now here using a script and fixing things locally - for the most part.

@mr-tz
Copy link
Collaborator Author

mr-tz commented Oct 26, 2023

See 409da0b for some first updates to rules with subscopes. Is that what you had in mind @williballenthin @yelhamer?

@mr-tz mr-tz mentioned this pull request Oct 26, 2023
18 tasks
@mr-tz
Copy link
Collaborator Author

mr-tz commented Oct 26, 2023

I think all rules have been upgraded now.

I did not use the process scope in any rule so far.

The linter needs to use the changes from the dynamic-feature-extraction branch to pass.

@mr-tz mr-tz requested a review from williballenthin October 26, 2023 15:32
Comment on lines +20 to +35
# static
- basic block:
- and:
- api: SLIsGenuineLocal
- basic block:
- and:
- api: UuidFromString
- string: "55c92734-d682-4d71-983e-d6ec3f16059f"
# dynamic
- call:
- and:
- api: SLIsGenuineLocal
- call:
- and:
- api: UuidFromString
- string: "55c92734-d682-4d71-983e-d6ec3f16059f"
Copy link
Collaborator

Choose a reason for hiding this comment

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

this duplication is obviously unfortunate, but i understand why

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

potentially there's just a lot of duplication for basic block -> call

could we support basic block / call syntax to simplify this?

Copy link
Collaborator

@williballenthin williballenthin left a comment

Choose a reason for hiding this comment

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

i looked at the first hundred or so - changes look good. what level of review would you like from me? do you need every change reviewed? or are you confident in the changes and we can trust that?

@mr-tz
Copy link
Collaborator Author

mr-tz commented Nov 1, 2023

If you've looked at a dozen or so changes from each commit (as they roughly group changes) I'm fairly confident in these updates and don't think we need a detailed review of each rule.

@williballenthin
Copy link
Collaborator

ah, that's a great way to group changes. i'll do this review tomorrow. thanks!

@mr-tz mr-tz mentioned this pull request Nov 8, 2023
Copy link
Collaborator

@williballenthin williballenthin left a comment

Choose a reason for hiding this comment

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

(the GH PR review interface is basically unusable for this set of commits 🤦🏼 )

I reviewed commit-by-commit, limiting myself to about 20 changed files per commit. I found no blockers.

Things I took away:

  1. good: comment why a flavor is unsupported
  2. good: comments indicating a branch is for static/dynamic flavor
  3. good: nest static/dynamic branches under a single OR to group logic
  4. maybe we can rely on the default logical statement for a subscope to be "AND", which simplifies some rules. consider:
- call:
  - and:
    - api: foo
    - number: 1

versus:

- call:
  - api: foo
  - number: 1

things to check:

a. VMCI socket: should this be scope=call not scope=thread?
b. protected exception handling: check call counting works as desired
c. check if file exists: use scope=call?


sidebar: here's how i did the review commit by commit, mostly for my personal future reference

git switch --detach b05c54734b56dfc77c542b9df723ad88f5799678
git reset $(git merge-base HEAD HEAD~)

this checks out the commit i want to inspect, and then creates a workspace as if only the changes in that commit are active an uncommited. so, then i can do git status to see all the modified fields and git diff to see the diffs.

notably, i can use tools like tig, gitui, and vs code to review the diffs and stage/unstage to mark things i agree with.

@williballenthin

This comment was marked as resolved.

@williballenthin
Copy link
Collaborator

williballenthin commented Nov 14, 2023

@mr-tz please see dbefb55

image

@mr-tz
Copy link
Collaborator Author

mr-tz commented Nov 14, 2023

Is VMCI_SOCKETS_GET_AF_VALUE a valid argument to socket?

The other changes look good, thank you!

@williballenthin
Copy link
Collaborator

via here: https://github.com/mandiant/capa/blob/210a13d94ea40114e01b40927c77c1c74047780f/capa/rules/__init__.py#L544

an instruction subscope acts implicitly like an and: so we can save a line/indentation by not adding those. same with call. maybe we can do a cleanup of all the rules in another PR.

@williballenthin
Copy link
Collaborator

williballenthin commented Nov 15, 2023

Is VMCI_SOCKETS_GET_AF_VALUE a valid argument to socket?

ah, you're right, this is only passed to DeviceIoControl/ioctl. updated the logic to look like:

      - and:
        - os: windows
        - api: DeviceIoControl
        - number: 0x81032068 = VMCI_SOCKETS_GET_AF_VALUE
        - optional:
          - api: socket
      - and:
        - os: linux
        - api: ioctl
        - number: 0x7B8 = VMCI_SOCKETS_GET_AF_VALUE
        - optional:
          - api: socket

scope: basic block/call

Copy link
Collaborator

@williballenthin williballenthin left a comment

Choose a reason for hiding this comment

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

i think this PR is ready for merge (once dynamic analysis is merged)!

@mr-tz
Copy link
Collaborator Author

mr-tz commented Nov 15, 2023

For call scope the optional socket would never match and the scopes should still be thread (and function) IMO.

@mr-tz
Copy link
Collaborator Author

mr-tz commented Nov 15, 2023

via here: https://github.com/mandiant/capa/blob/210a13d94ea40114e01b40927c77c1c74047780f/capa/rules/__init__.py#L544

an instruction subscope acts implicitly like an and: so we can save a line/indentation by not adding those. same with call. maybe we can do a cleanup of all the rules in another PR.

I don't see that implemented for call, but think we should add and simplify the rules.

@mr-tz mr-tz force-pushed the dynamic-rules-mr-2 branch from 1aae081 to 305adfd Compare November 24, 2023 10:54
@mr-tz
Copy link
Collaborator Author

mr-tz commented Nov 24, 2023

rebased to master and:

  • changed scopes again for VMCI socket: 5e2dae1
  • updated scopes for new rules: 5430889
  • graduated rule: 305adfd

mr-tz and others added 5 commits November 28, 2023 16:21
* suggest to run on dynamic trace for packed samples

---------

Co-authored-by: Willi Ballenthin <[email protected]>
* wip: update rule format documentation with dynamic details

* format: add example links

* format: reorganize features vs scopes

* Update doc/format.md

Co-authored-by: Moritz <[email protected]>

* Update doc/format.md

Co-authored-by: Moritz <[email protected]>

* Update doc/format.md

Co-authored-by: Moritz <[email protected]>

* Update doc/format.md

Co-authored-by: Moritz <[email protected]>

* Update doc/format.md

Co-authored-by: Moritz <[email protected]>

* Update doc/format.md

Co-authored-by: Moritz <[email protected]>

* Update doc/format.md

Co-authored-by: Moritz <[email protected]>

* Update doc/format.md

Co-authored-by: Moritz <[email protected]>

* format: table formatting

* format: try to express scoping for features

* Update doc/format.md

Co-authored-by: Moritz <[email protected]>

* Update doc/format.md

Co-authored-by: Moritz <[email protected]>

---------

Co-authored-by: Moritz <[email protected]>
@mr-tz mr-tz merged commit 9820a21 into master Nov 29, 2023
2 of 3 checks passed
@mr-tz mr-tz deleted the dynamic-rules-mr-2 branch November 29, 2023 13:50
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