Detecting Memory based exploits
Building a Detection for Process Injection
Process injection is a common technique used by adversaries to execute malicious code in the memory space of a legitimate process. In this post, we'll walk through how to simulate this technique, gather the necessary telemetry, and build a Sigma rule to detect it in your own environment.
Simulating the Attack
To begin, I used two powerful open-source tools: PurpleSharp, an adversary simulation tool, and my own project, Arcadian, to execute the tests. You can check out Arcadian on GitHub: https://github.com/TakayamaSec/arcadian.
I focused on two specific MITRE ATT&CK techniques:
T1055.002: Process Injection: Portable Executable Injection
T1055.004: Process Injection: Asynchronous Procedure Call
You can find more details on these techniques and others on the MITRE ATT&CK website.
Gathering Telemetry
For effective detection, it's crucial to collect the right data. A best practice is to enable the collection of DLL load events (Event ID 7) using Sysmon on your Windows endpoints. Be aware that this can generate a high volume of data, so you may want to create filters to exclude routine DLL loads from your collection pipeline.

After running the simulations with PurpleSharp, I used the Elastic Defend agent to capture the resulting activity. The agent's EDR capabilities provided detailed telemetry on Windows API calls.
In the logs, a key event stood out: prototype.exe (my Arcadian test executable) was making a call to WriteProcessMemory. This is highly anomalous. The WriteProcessMemory API is not typically called by such a process, making it a strong indicator of suspicious behavior.
Using the Elastic Defend agent I am able to capture multiple Windows API events using the EDR agent. We can use this telemetry to help us build a detection, in this situation it is odd in itself that "prototype.exe" is calling "WriteProcessMemory". This would be considered anomalous activity because "WriteProcessMemory" API is not normally called via that process.


Creating the Sigma Rule
Using the telemetry we gathered, I created the following Sigma rule to detect this type of anomalous activity. The rule is designed to identify WriteProcessMemory events originating from processes that are not typically associated with this function, effectively filtering out the noise of legitimate system operations.
You can find this rule and more in my public Sigma rule repository here: https://github.com/TakayamaSec/custom_sigma_rules/tree/main/Privilege%20Escalation
Last updated