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

Rename architecture-specific rules and update rule names inside YAML files #1011

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

akh7177
Copy link

@akh7177 akh7177 commented Feb 28, 2025

This PR addresses issue #979 by renaming architecture-specific rules.

Since all identified architecture-specific rules are x86-only, only x86-related rules have been renamed.

  • Each renamed rule now explicitly includes -x86.yml in its filename.
  • The name: field inside each YAML file has been updated to append "via x86 assembly" for consistency.

closes #979

@akh7177
Copy link
Author

akh7177 commented Feb 28, 2025

I also noticed that there's a mistake in the logic of this script because the rule always returns False. Could you please let me know if I'm right? If so I'll quick fix that one too!

@williballenthin
Copy link
Collaborator

i agree that looks impossible. nice catch! would you please research and fix this? (if you want, of course)

@akh7177
Copy link
Author

akh7177 commented Mar 1, 2025

Sure! I'm happy to fix it!
Will start working on it soon

@akh7177 akh7177 force-pushed the rename-arch-specific-rules branch from 62bc59e to a87eb3e Compare March 1, 2025 07:37
@akh7177
Copy link
Author

akh7177 commented Mar 1, 2025

Done with changing the logic of the rule 🌟

@mike-hunhoff
Copy link
Collaborator

@akh7177 it appears lints are failing now:

ERROR    capa: invalid rule: rule "packed with generic packer"       main.py:678
         depends on missing rule "contain pusha popa sequence"          

This is likely the results of a match feature that references an outdated rule name. You can verify rule lints are passing locally by setting capa up for development following the instructions outlined here.

@mike-hunhoff mike-hunhoff self-requested a review March 10, 2025 19:06
Copy link
Collaborator

@mike-hunhoff mike-hunhoff left a comment

Choose a reason for hiding this comment

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

Please see my comment about lints failing.

@akh7177
Copy link
Author

akh7177 commented Mar 10, 2025

Please see my comment about lints failing.

Yup! I'll verify that and put up a comment over here. Is that okay?

@akh7177
Copy link
Author

akh7177 commented Mar 11, 2025

@mike-hunhoff Verified that it passes the lints locally!

@mike-hunhoff
Copy link
Collaborator

@akh7177 lints are still failing:

Run python scripts/lint.py rules/
  python scripts/lint.py rules/
[...]
ERROR    capa: invalid rule: rule "packed with generic packer"       main.py:678
         depends on missing rule "contain pusha popa sequence"              
[...]

@akh7177
Copy link
Author

akh7177 commented Mar 11, 2025

@akh7177 lints are still failing:

Run python scripts/lint.py rules/
  python scripts/lint.py rules/
[...]
ERROR    capa: invalid rule: rule "packed with generic packer"       main.py:678
         depends on missing rule "contain pusha popa sequence"              
[...]

I ran the lint.py script again just now on my PC with the new rules and it seems to be passing perfectly 🤔

image

@mike-hunhoff
Copy link
Collaborator

@akh7177 lints are still failing:

Run python scripts/lint.py rules/
  python scripts/lint.py rules/
[...]
ERROR    capa: invalid rule: rule "packed with generic packer"       main.py:678
         depends on missing rule "contain pusha popa sequence"              
[...]

I ran the lint.py script again just now on my PC with the new rules and it seems to be passing perfectly 🤔

image

Have you pushed all of your local changes?

@akh7177
Copy link
Author

akh7177 commented Mar 11, 2025

Yes, I've made sure to push the entire rules folder. As discussed yesterday, I believe it is the match feature which is causing the issue over here because all the rules that are flagged in the above test report are the ones that I've renamed

@mike-hunhoff
Copy link
Collaborator

This PR currently does not include any changes to the rule packed with generic packer, which is causing lints to fail. What are the contents of this rule in your local copy?

@akh7177
Copy link
Author

akh7177 commented Mar 11, 2025

This PR currently does not include any changes to the rule packed with generic packer, which is causing lints to fail. What are the contents of this rule in your local copy?

That rule is indeed untouched. But it does not seem to be effecting the lint script locally when I run it to the entire rules folder.

rule:
meta:
name: packed with generic packer
namespace: anti-analysis/packer/generic
authors:
- [email protected]
scopes:
static: function
dynamic: unsupported
att&ck:
- Defense Evasion::Obfuscated Files or Information::Software Packing [T1027.002]
mbc:
- Anti-Static Analysis::Software Packing::Standard Compression [F0001.002]
examples:
- Practical Malware Analysis Lab 18-01.exe_:0x409dc0
features:
- and:
- or:
- mnemonic: pusha
- mnemonic: pushad # vivisect
- or:
- mnemonic: popa
- mnemonic: popad # vivisect
- characteristic: cross section flow
- not:
- match: contain pusha popa sequence

@mike-hunhoff
Copy link
Collaborator

mike-hunhoff commented Mar 11, 2025

Hmm I'm not sure what is happening in your local environment that would allow the tests to pass. Please verify that you're running lint.py on the expected rules folder and, if so, that the rules folder contains the updates that you've pushed here.

@akh7177
Copy link
Author

akh7177 commented Mar 11, 2025

Hmm I'm not sure what is happening in your local environment that would allow the tests to pass. Please verify that you're running lint.py on the expected rules folder and, if so, that the rules folder contains the updates that you've pushed here.

Yes, it indeed is indeed intriguing. I have a fix in my mind. I'll try implementing it and get back to you ( Still not 100% sure why its failing. All the changes are are pushed 🥲 )

@akh7177
Copy link
Author

akh7177 commented Mar 11, 2025

@mike-hunhoff Could you pls try running the test now? 🤞

@akh7177
Copy link
Author

akh7177 commented Mar 11, 2025

Okay. I believe changing the match feature of all the files will do the job. On my way!

@mike-hunhoff
Copy link
Collaborator

@akh7177 lints failed again. I pulled your changes locally and ran lint.py to receive the error:

$ python scripts/lint.py rules/
ERROR    capa: invalid rule: rule "get kernel32 base address via x86 assembly" depends on missing rule "access PEB ldr_data"                                                   main.py:678
ERROR    capa: Make sure your file directory contains properly formatted capa rules. You can download the standard collection of capa rules from                               main.py:679
         https://github.com/mandiant/capa-rules/releases.                                                                                                                                 
ERROR    capa: Please ensure you're using the rules that correspond to your major version of capa (9)                                                                          main.py:683
ERROR    capa: Or, for more details, see the rule set documentation here: https://github.com/mandiant/capa/blob/master/doc/rules.md      

There must be something going on with your local environment, I'd recommend fixing this before proceeding.

@akh7177
Copy link
Author

akh7177 commented Mar 11, 2025

Sure! I'll try to find a solution for it. My other PR regarding screen-capture rule seems to be passing the lints though 🤔

@akh7177
Copy link
Author

akh7177 commented Mar 12, 2025

There must be something going on with your local environment, I'd recommend fixing this before proceeding.

@mike-hunhoff Yes, there indeed was something off with my local environment. I re-installed everything and then ran the lints. Faced the same error that you had mentioned. Now, I've fixed the match feature that references the old rule names to use new new names. I also ran the capafmt.py through the entire folder to result in proper formatting and made sure to pass the lints. Let's see how it goes.

@akh7177 akh7177 force-pushed the rename-arch-specific-rules branch from a8498e9 to aa5764f Compare March 12, 2025 07:45
Copy link
Collaborator

@mike-hunhoff mike-hunhoff left a comment

Choose a reason for hiding this comment

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

I've left comments for your review. It appears that the file mode of multiple files have been changed. Please revert these changes.

@@ -1,6 +1,6 @@
rule:
meta:
name: get number of processors
name: get number of processors via x86 assembly
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is branch that does not use x86 assembly, please revert.

Copy link
Author

Choose a reason for hiding this comment

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

There is branch that does not use x86 assembly, please revert.

My bad! I oversaw the last statement. Will revert it back

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert the changes to this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert the changes to this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert the changes to this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert the changes to this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert the changes to this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert the changes to this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert the changes to this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert the changes to this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert the changes to this file.

@akh7177 akh7177 force-pushed the rename-arch-specific-rules branch 2 times, most recently from 4f20e44 to 5f55ee4 Compare March 12, 2025 16:11
@akh7177
Copy link
Author

akh7177 commented Mar 12, 2025

Hello @mike-hunhoff
Any idea how these files got changed? Now I tried replacing these rules with the ones in the mandiant capa-rules but git status doesn't seem to notice the changes.

@mike-hunhoff
Copy link
Collaborator

I'm not sure as I only can see the file state from the view of this PR. It's especially confusing because only some of the files had this permission change. What commands/scripts did you run against your local rules directory prior to the commit these changes took place?

@akh7177
Copy link
Author

akh7177 commented Mar 12, 2025

I'm not sure as I only can see the file state from the view of this PR. It's especially confusing because only some of the files had this permission change. What commands/scripts did you run against your local rules directory prior to the commit these changes took place?

@mike-hunhoff I'm pretty sure the only time I've accessed these files were when I ran capafmt.py against the entire rules directory. When I open these files in edit mode through github, the only change I notice in all of these is the addition of a new line at the end, which might've been added by capafmt.py as it could've been previously absent.

Could you please check if a new line was present at the end of these particular scripts previously?

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.

consider appending "via [insert_name] assembly" to applicable rule names
3 participants