Add folder enumeration signature for ransomware detection#527
Add folder enumeration signature for ransomware detection#527kevross33 wants to merge 2 commits intoCAPESandbox:masterfrom
Conversation
Implements a signature for folder enumeration, targeting user directories that are commonly accessed by ransomware or wipers.
Summary of ChangesHello @kevross33, 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 early-stage ransomware and wiper attacks by implementing a new signature. This signature focuses on identifying malicious patterns of folder enumeration within critical user directories, thereby providing an earlier warning mechanism against potential data encryption or destruction attempts. 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
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 a new signature to detect folder enumeration, a common behavior of ransomware. A medium-severity Regular Expression Denial of Service (ReDoS) vulnerability was identified in the regex pattern. Additionally, improvements are suggested for making path matching case-insensitive for Windows, refining code style by removing a magic number and simplifying a return statement, and correcting an MBC classification code.
|
|
||
| def run(self): | ||
| targeted_folders = set() | ||
| pattern = r".*(Users|Documents|Desktop|Downloads|Music|Videos|Pictures|AppData).*\\\*.*" |
There was a problem hiding this comment.
The regular expression on this line is vulnerable to Regular Expression Denial of Service (ReDoS) due to the greedy quantifier .* which can lead to catastrophic backtracking. Additionally, Windows file paths are case-insensitive, and the current regex is case-sensitive, which could lead to missed detections on paths with different casing.
| pattern = r".*(Users|Documents|Desktop|Downloads|Music|Videos|Pictures|AppData).*\\\*.*" | |
| pattern = r"(?i).*?(Users|Documents|Desktop|Downloads|Music|Videos|Pictures|AppData).*\\\*.*" |
| evented = True | ||
| enabled = True | ||
| ttps = ["T1083"] | ||
| mbcs = ["B0002.001"] |
There was a problem hiding this comment.
| if len(targeted_folders) > 10: | ||
| return True | ||
|
|
||
| return False |
There was a problem hiding this comment.
This if...return block can be simplified to a single, more concise return statement. Additionally, the threshold 10 is a magic number. It's recommended to define it as a class-level constant (e.g., TARGETED_FOLDERS_THRESHOLD = 10) to improve readability and maintainability.
return len(targeted_folders) > 10
Implements a signature for folder enumeration, targeting user directories that are commonly accessed by ransomware or wipers.
LockBit

ZOVWiper

DynoWiper
