-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(callstack): Fix private allocation size
Attackers exploit the memory of the benign module (dll) to inject their own shellcode. When the memory of the DLL is tampered, the backing memory pages release the shared attribute and become private pages. If the callstack contains such memory regions, it is a strong indicator of module stomping. To accomplish the detection of stomped modules, we use the `QueryWorkingSet` API to examine the pages starting from the stack return address.
- Loading branch information
1 parent
8e81077
commit 97e5764
Showing
7 changed files
with
245 additions
and
7 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2021-2022 by Nedim Sabic Sabic | ||
* https://www.fibratus.io | ||
* All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package sys | ||
|
||
// MemoryWorkingSetExInformation describes the attributes of the memory region. | ||
type MemoryWorkingSetExInformation struct { | ||
VirtualAddress uintptr | ||
VirtualAttributes MemoryWorkingSetExBlock | ||
} | ||
|
||
type MemoryWorkingSetExBlock uintptr | ||
|
||
// Valid if this bit is 1, the subsequent members are valid. Otherwise, they should be ignored. | ||
func (b MemoryWorkingSetExBlock) Valid() bool { | ||
return b&1 != 0 | ||
} | ||
|
||
// ShareCount specifies the number of processes that share this page. The maximum value of this member is 7. | ||
func (b MemoryWorkingSetExBlock) ShareCount() uintptr { | ||
return (uintptr(b) >> 1) & ((1 << 3) - 1) | ||
} | ||
|
||
// Win32Protection specifies the memory protection attributes of the page. | ||
func (b MemoryWorkingSetExBlock) Win32Protection() uintptr { | ||
return (uintptr(b) >> 4) & ((1 << 11) - 1) | ||
} | ||
|
||
// Shared evaluates to true if the page can be shared or false otherwise. | ||
func (b MemoryWorkingSetExBlock) Shared() bool { | ||
return b&(1<<15) != 0 | ||
} | ||
|
||
// Node represents the NUMA node. The maximum value of this member is 63. | ||
func (b MemoryWorkingSetExBlock) Node() uintptr { | ||
return (uintptr(b) >> 16) & ((1 << 6) - 1) | ||
} | ||
|
||
// Locked returns true if the virtual page is locked in physical memory. | ||
func (b MemoryWorkingSetExBlock) Locked() bool { | ||
return b&(1<<15) != 0 | ||
} | ||
|
||
// LargePage returns true if the page is a large page. | ||
func (b MemoryWorkingSetExBlock) LargePage() bool { | ||
return b&(1<<16) != 0 | ||
} | ||
|
||
// SharedOriginal evaluates to true if the page can be shared or false otherwise. | ||
func (b MemoryWorkingSetExBlock) SharedOriginal() bool { | ||
return b&(1<<30) != 0 | ||
} | ||
|
||
// Bad indicates the page has been reported as bad. | ||
func (b MemoryWorkingSetExBlock) Bad() bool { | ||
return b&(1<<31) != 0 | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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