-
Notifications
You must be signed in to change notification settings - Fork 557
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 a script for upgrading rules into the new dynamic format #1696
Add a script for upgrading rules into the new dynamic format #1696
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when you're ready for more review, would you please also provide some example output, such as the git diff for some upgraded rules? this will help us assess the logic of the script.
Co-authored-by: Willi Ballenthin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree that some example output and results would be helpful
The script's logic is finished I believe, so feel free to review it. All that remains is to add support for filtering-out Here's the script's result on a made up complex rule: original rule:rule:
meta:
name: test rule
namespace: test
authors:
- [email protected]
scope: function
att&ck:
- Persistence::Event Triggered Execution::Unix Shell Configuration Modification
[T1546.004]
examples:
- 7351f8a40c5450557b24622417fc478d:0x407D11
features:
- and:
- basic block:
- or:
- os: linux
- match: host-interaction/file-system/write
- or:
- mnemonic: call
- api: someapi_1
- instruction:
- mnemonic: write
- string: somestring_1
- instruction:
- api: someapi_2
- number: 1
- string: somestring_2 modified rule:rule:
meta:
name: test rule
namespace: test
authors:
- [email protected]
scopes:
static: function
dynamic: process
att&ck:
- Persistence::Event Triggered Execution::Unix Shell Configuration Modification
[T1546.004]
examples:
- 7351f8a40c5450557b24622417fc478d:0x407D11
features:
- and:
- or:
- basic block:
- or:
- os: linux
- match: host-interaction/file-system/write
- or:
- mnemonic: call
- api: someapi_1
- instruction:
- mnemonic: write
- string: somestring_1
- thread:
- or:
- os: linux
- match: host-interaction/file-system/write
- or:
- api: someapi_1
- or:
- instruction:
- api: someapi_2
- number: 1
- call:
- and:
- api: someapi_2
- number: 1
- string: somestring_2 |
edit: @yelhamer this seems to still be the case
|
Co-authored-by: Moritz <[email protected]>
good finds @mr-tz these might be tricky to address, since the yaml parser probably doesn't preserve things like the hex/decimal number format once the data is parsed. worst case, we could do something like:
|
See |
|
@mr-tz regarding the removal of |
For the static rule part mnemonic and offset should still be there. |
Ah yeah I see. Will work on it... |
TODO(yelhamer): |
…into upgrade-legacy-rules-script
…amer/capa into upgrade-legacy-rules-script
Currently, getting |
@mr-tz could you please take a look at the rules now for any other issues? what remains is preserving the double backwards slashes (important), and the comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See inline comments in mandiant/capa-rules#814
Nice progress, there's some code style issues to address here as well.
I think this can be closed? |
At the time of the opening of this PR, the script provides the main logic for parsing the rules. This logic is composed of 3 recursive functions that each handle a specific task, and that call into each other. I settled on this approach after trying other things (such as the strategy mentioned in #1674) and failing/getting stuff too complicated.
There remains the following important tasks, but they should be easy to add for the most part:
Checklist