Skip to content

Add ransomware detection signatures for file access#534

Open
kevross33 wants to merge 2 commits intoCAPESandbox:masterfrom
kevross33:patch-98
Open

Add ransomware detection signatures for file access#534
kevross33 wants to merge 2 commits intoCAPESandbox:masterfrom
kevross33:patch-98

Conversation

@kevross33
Copy link
Contributor

@kevross33 kevross33 commented Feb 28, 2026

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.

image image

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.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Ransomware Attribute Stripping Signature: Implemented a new signature, RansomwareAttributeStripping, to detect attempts to strip file attributes (e.g., setting to normal) on a large number of files. This behavior often precedes ransomware or wiper attacks and monitors NtSetInformationFile and SetFileAttributes API calls.
  • Mass File Modification Access Signature: Introduced a new signature, MassFileModificationAccess, designed to identify suspicious behavior where a large number of existing files are opened with write or delete access. This is a common indicator of ransomware or wiper activity and focuses on NtOpenFile calls with dangerous access flags.

🧠 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
  • modules/signatures/windows/ransomware_fileaccess.py
    • Added new file containing ransomware detection signatures.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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":
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
if info_class == 4 or str(info_class) == "4":
if str(info_class) == "4":
References
  1. The PEP 8 style guide recommends avoiding trailing whitespace. (link)

Comment on lines +59 to +64
if len(self.stripped_files) <= 10:
self.mark_call()

def on_complete(self):
ret = False
if len(self.stripped_files) > 30:
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The numbers 10 (line 59) and 30 (line 64) are used as magic numbers. It's a good practice to define them as named constants at the class level (e.g., MARK_CALL_LIMIT = 10, TRIGGER_THRESHOLD = 30). This improves readability and makes it easier to adjust these values in the future.

def __init__(self, *args, **kwargs):
Signature.__init__(self, *args, **kwargs)
self.targeted_files = set()
self.example_file = None
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The attribute self.example_file is initialized but never used within the class. It should be removed to avoid confusion and improve code clarity.

pretty_access = str(arg.get("value", ""))
break

pretty_access = pretty_access.upper()
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This line has trailing whitespace, which should be removed to adhere to PEP 8 style guidelines.

Suggested change
pretty_access = pretty_access.upper()
pretty_access = pretty_access.upper()
References
  1. 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:
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This line has trailing whitespace, which should be removed to adhere to PEP 8 style guidelines.

Suggested change
if filepath_lower not in self.targeted_files:
if filepath_lower not in self.targeted_files:
References
  1. The PEP 8 style guide recommends avoiding trailing whitespace. (link)

Comment on lines +114 to +119
if len(self.targeted_files) <= 15:
self.mark_call()

def on_complete(self):
ret = False
if len(self.targeted_files) > 40:
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The numbers 15 (line 114) and 40 (line 119) are used as magic numbers. It's a good practice to define them as named constants at the class level (e.g., MARK_CALL_LIMIT = 15, TRIGGER_THRESHOLD = 40). This improves readability and makes it easier to adjust these values in the future.

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.

1 participant