-
Notifications
You must be signed in to change notification settings - Fork 164
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
Update and refactor memory allocation/permission rules #836
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ed791c9
separate allocate and change memory protection
mr-tz 5f223ea
rename rules
mr-tz 66f58df
update match rule name
mr-tz 7ddf609
update example
mr-tz 1be6720
add runtime resolved functions
mr-tz a39a2c0
Merge branch 'master' into update-alloc-rules
mr-tz b778d25
Update allocate-memory.yml
mr-tz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
host-interaction/process/inject/allocate-or-change-rwx-memory.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
rule: | ||
meta: | ||
name: allocate or change RWX memory | ||
namespace: host-interaction/process/inject | ||
authors: | ||
- "@mr-tz" | ||
scope: basic block | ||
mbc: | ||
- Memory::Allocate Memory [C0007] | ||
examples: | ||
- Practical Malware Analysis Lab 03-03.exe_:0x4010EA | ||
# ntdll | ||
- 563653399B82CD443F120ECEFF836EA3678D4CF11D9B351BB737573C2D856299:0x140001ABA | ||
features: | ||
- and: | ||
- or: | ||
- match: allocate memory | ||
- match: change memory protection | ||
- or: | ||
- number: 0x40 = PAGE_EXECUTE_READWRITE | ||
# lea r9d, [rcx+40h] ; flProtect | ||
# call cs:VirtualAlloc | ||
- instruction: | ||
- mnemonic: lea | ||
- offset: 0x40 = PAGE_EXECUTE_READWRITE |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,24 +3,30 @@ rule: | |
name: allocate memory | ||
authors: | ||
- [email protected] | ||
- "@mr-tz" | ||
lib: true | ||
scope: basic block | ||
mbc: | ||
- Memory::Allocate Memory [C0007] | ||
examples: | ||
- Practical Malware Analysis Lab 03-03.exe_:0x4010EA | ||
# ntdll | ||
- 563653399B82CD443F120ECEFF836EA3678D4CF11D9B351BB737573C2D856299:0x140001ABA | ||
- 563653399B82CD443F120ECEFF836EA3678D4CF11D9B351BB737573C2D856299:0x140001ABA # ntdll.NtAllocateVirtualMemory | ||
features: | ||
- or: | ||
- api: kernel32.VirtualAlloc | ||
- api: kernel32.VirtualAllocEx | ||
- api: kernel32.VirtualAllocExNuma | ||
- api: kernel32.VirtualProtect | ||
- api: kernel32.VirtualProtectEx | ||
- api: NtAllocateVirtualMemory | ||
- api: ZwAllocateVirtualMemory | ||
- api: NtMapViewOfSection | ||
- api: ZwMapViewOfSection | ||
- api: NtProtectVirtualMemory | ||
- api: ZwProtectVirtualMemory | ||
- and: | ||
- match: link function at runtime on Windows | ||
- or: | ||
- string: "VirtualAlloc" | ||
- string: "VirtualAllocEx" | ||
- string: "VirtualAllocExNuma" | ||
- string: "NtAllocateVirtualMemory" | ||
- string: "ZwAllocateVirtualMemory" | ||
- string: "NtMapViewOfSection" | ||
- string: "ZwMapViewOfSection" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
rule: | ||
meta: | ||
name: allocate or change RW memory | ||
authors: | ||
- [email protected] | ||
- "@mr-tz" | ||
lib: true | ||
scope: basic block | ||
mbc: | ||
- Memory::Allocate Memory [C0007] | ||
examples: | ||
- Practical Malware Analysis Lab 17-02.dll_:0x1000D10D | ||
features: | ||
- and: | ||
- or: | ||
- match: allocate memory | ||
- match: change memory protection | ||
- or: | ||
- number: 0x4 = PAGE_READWRITE | ||
# lea r9d, [rcx+4] ; flProtect | ||
# call cs:VirtualAlloc | ||
- instruction: | ||
- mnemonic: lea | ||
- offset: 0x4 = PAGE_READWRITE |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
rule: | ||
meta: | ||
name: change memory protection | ||
authors: | ||
- "@mr-tz" | ||
lib: true | ||
scope: basic block | ||
mbc: | ||
- Memory::Change Memory Protection [C0008] | ||
examples: | ||
- Practical Malware Analysis Lab 11-02.dll_:0x10001203 | ||
features: | ||
- or: | ||
- api: kernel32.VirtualProtect | ||
- api: kernel32.VirtualProtectEx | ||
- api: NtProtectVirtualMemory | ||
- api: ZwProtectVirtualMemory | ||
- and: | ||
- match: link function at runtime on Windows | ||
- or: | ||
- string: "VirtualProtect" | ||
- string: "VirtualProtectEx" | ||
- string: "NtProtectVirtualMemory" | ||
- string: "ZwProtectVirtualMemory" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,21 +11,7 @@ rule: | |
- c2bb17c12975ea61ff43a71afd9c3ff111d018af161859abae0bdb0b3dae98f9:0x140001010 | ||
features: | ||
- and: | ||
- or: | ||
- match: allocate RWX memory | ||
- basic block: | ||
- and: | ||
# xor ecx, ecx ; lpAddress | ||
# mov edx, 31Fh ; dwSize | ||
# mov r8d, 1000h ; flAllocationType | ||
# lea r9d, [rcx+40h] ; flProtect | ||
# call cs:VirtualAlloc | ||
- match: allocate memory | ||
- or: | ||
- number: 0x40 | ||
- instruction: | ||
- mnemonic: lea | ||
- offset: 0x40 | ||
Comment on lines
-16
to
-28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to |
||
- match: allocate or change RWX memory | ||
- api: CopyFile2 | ||
- api: DeleteFileW | ||
- number: 0x00000001 = COPY_FILE_FAIL_IF_EXISTS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
moved the removed APIs to
change memory protection
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.
this is a nice cleanup