This PR adds in the ability to search Windows process memory for needles. These needles are searched for using regex, provided by the tiny-regex-c library. This library has been modified to match an arbitrary length of bytes (null-bytes included). This was necessary so that we do not treat null-bytes as the end of a string/buffer, and continue trying to match the regular expression.
Example Usage
I went through the following steps:
Compile the project using Visual Studio in a Windows 10 x64 VM as an x64 project in Debug mode.
Mount the Framework data directory into the VM as a share with write permissions.
On the VM, execute: cp -rf ./output/* /z/meterpreter && ~/Desktop/met.exe to copy the debug dll files to Framework. met.exe is a symlink to a Framework-generated Meterpreter payload.
In Framework, setg MeterpreterDebugBuild true
Get a session
sessions -i -1
irb
Now we can define our memory search function that we will use for testing:
This should result in no memory usage increases for Meterpreter and the session should remain stable.
Debugging
When wanting to debug the new re.c file, we can first:
#include <windows.h>
This will also typedef CHAR which initially conflicted with the enum CHAR; this has been renamed to CHAR_RE.
Then define a buffer, format it using sprintf and call OutputDebugStringA, mimicking what dprintf was doing.
char buffer[1024];
unsigned long long example_llu = 42;
sprintf(buffer, "Example output: %llu", example_llu);
OutputDebugStringA(buffer);
You will need to use the DebugView program to view debug logs.
Dr. Memory
I also ran the generated executable with Dr. Memory using drmemory -- ~/Desktop/met.exe:
This PR adds in the ability to search Windows process memory for needles. These needles are searched for using regex, provided by the tiny-regex-c library. This library has been modified to match an arbitrary length of bytes (null-bytes included). This was necessary so that we do not treat null-bytes as the end of a string/buffer, and continue trying to match the regular expression.
Example Usage
I went through the following steps:
data
directory into the VM as a share with write permissions.cp -rf ./output/* /z/meterpreter && ~/Desktop/met.exe
to copy the debug dll files to Framework. met.exe is a symlink to a Framework-generated Meterpreter payload.setg MeterpreterDebugBuild true
sessions -i -1
irb
Now we can define our memory search function that we will use for testing:
Then we can use regex to search for needles:
When searching for multiple needles, call:
The changes in the tiny-regex-c library allow us to match null-bytes as well, meaning we can match wide characters:
To make sure the command is stable, you can run the following in
irb
for a single needle:or with multiple needles:
This should result in no memory usage increases for Meterpreter and the session should remain stable.
Debugging
When wanting to debug the new
re.c
file, we can first:This will also
typedef CHAR
which initially conflicted with theenum CHAR
; this has been renamed toCHAR_RE
. Then define a buffer, format it usingsprintf
and callOutputDebugStringA
, mimicking whatdprintf
was doing.You will need to use the DebugView program to view debug logs.
Dr. Memory
I also ran the generated executable with Dr. Memory using
drmemory -- ~/Desktop/met.exe
:This points at issues not related to the added memory search functionality and occurred before the memory search function was called.
Diagram
To help future travellers or potentially myself, below is a diagram of the memory search buffer implementation: