Check IoC of dirty bit in PTEs from executable VMAs.#995
Conversation
this can for example detect code injected using ptrace(). this can also detect injected code that was reset to the original code (malware uninstalled before memory dump happened).
ikelos
left a comment
There was a problem hiding this comment.
Thanks a few gotchas, and please apply black to your submission, to make sure the code is all formatted uniformly. You can see on the build list why black believes it's failing if you just want to manually fix it up...
…erformance Use black Better logging
|
@ikelos Any remaining concern? |
|
There's a corner case with some old binaries/libraries that trigger false positives. It's explained in Here's a small example to reproduce the corner case: |
ikelos
left a comment
There was a problem hiding this comment.
Sorry for the delay in reviewing this. I'm quite nervous about adding things into the Intel space, but I believe this is ok so I'm going to merge it in.
| except exceptions.InvalidAddressException: | ||
| return False | ||
|
|
||
| def is_dirty(self, offset: int) -> bool: |
There was a problem hiding this comment.
My slight concern is that we only add this to the intel layer, and not the underlying TranslationLayerInterface, but I think we've done that in other places. I guess it just requires that any time we use it we ensure we know we're working with an intel layer (at the moment, that's likely to be all we're working with, but in the future it could be an arm layer or something else)...
Currently, the Malfind plugin in volatility3 does not check the dirty bit in PTEs associated with executable VMAs. When someone modifies running code for example using ptrace (e.g. by writing to /proc/pid/mem), the permissions of the VMA remain r-x (ptrace does not require rwx) and the targeted pages become dirty. This is visible in /proc/pid/smaps where the Private_Dirty of executable VMAs become non zero.
The goal of this patch is to detect such dirty executable pages as it likely means that the target process was debugged at some point or that malicious code was injected.
It could happen that no modification is found when comparing the memory dump of the process with the original executable/libraries. In that case, it can mean that the malware got uninstalled, i.e. the original code was rewritten on top of the malicious code before the memory dump took place. Nevertheless, it is still interesting to know that some code got injected at some point in the past.
The downside of this patch is that it makes Malfind slower.