Add ransomware detection signatures for file access#534
Add ransomware detection signatures for file access#534kevross33 wants to merge 2 commits intoCAPESandbox:masterfrom
Conversation
This file implements two signatures for detecting ransomware behavior: one for stripping file attributes and another for mass file modification access. Each signature tracks specific file actions and marks calls based on defined criteria.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the system's ability to detect ransomware and wiper activity by introducing two new behavioral signatures. These signatures monitor specific file system interactions, such as attribute stripping and mass file modification attempts, to proactively identify and flag potentially malicious processes. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces two new ransomware detection signatures in ransomware_fileaccess.py. The RansomwareAttributeStripping signature detects mass stripping of file attributes, and MassFileModificationAccess detects when a large number of files are opened with write or delete access. The overall logic is sound. My feedback includes suggestions to improve code clarity and maintainability by removing an unused attribute, replacing magic numbers with named constants, simplifying a redundant condition, and fixing style issues like trailing whitespace.
|
|
||
| if call["api"] == "NtSetInformationFile": | ||
| info_class = self.get_argument(call, "FileInformationClass") | ||
| if info_class == 4 or str(info_class) == "4": |
There was a problem hiding this comment.
This line contains trailing whitespace, which violates PEP 8 style guidelines. Additionally, the condition info_class == 4 or str(info_class) == "4" is redundant. It can be simplified by using a string comparison, which works whether info_class is an integer or a string.
| if info_class == 4 or str(info_class) == "4": | |
| if str(info_class) == "4": |
References
- The PEP 8 style guide recommends avoiding trailing whitespace. (link)
| if len(self.stripped_files) <= 10: | ||
| self.mark_call() | ||
|
|
||
| def on_complete(self): | ||
| ret = False | ||
| if len(self.stripped_files) > 30: |
There was a problem hiding this comment.
| def __init__(self, *args, **kwargs): | ||
| Signature.__init__(self, *args, **kwargs) | ||
| self.targeted_files = set() | ||
| self.example_file = None |
| pretty_access = str(arg.get("value", "")) | ||
| break | ||
|
|
||
| pretty_access = pretty_access.upper() |
There was a problem hiding this comment.
This line has trailing whitespace, which should be removed to adhere to PEP 8 style guidelines.
| pretty_access = pretty_access.upper() | |
| pretty_access = pretty_access.upper() |
References
- The PEP 8 style guide recommends avoiding trailing whitespace. (link)
| if "\\??\\" in filepath_lower or "\\device\\" in filepath_lower: | ||
| return | ||
|
|
||
| if filepath_lower not in self.targeted_files: |
There was a problem hiding this comment.
This line has trailing whitespace, which should be removed to adhere to PEP 8 style guidelines.
| if filepath_lower not in self.targeted_files: | |
| if filepath_lower not in self.targeted_files: |
References
- The PEP 8 style guide recommends avoiding trailing whitespace. (link)
| if len(self.targeted_files) <= 15: | ||
| self.mark_call() | ||
|
|
||
| def on_complete(self): | ||
| ret = False | ||
| if len(self.targeted_files) > 40: |
There was a problem hiding this comment.
This file implements two signatures for detecting ransomware behavior: one for stripping file attributes and another for mass file modification access. call marks are limited in number to avoid huge amounts of events but provides a total count.