Advanced Memory Analysis Methods for Malware Researchers

Advanced Memory Analysis Methods for Malware Researchers

The Evolving Landscape of Memory Forensics

As the cybersecurity landscape grows increasingly complex, memory forensics has emerged as a critical field for investigating and identifying potential security threats. Unlike traditional methods that focus on hard drive analysis, memory forensics delves into the volatile memory of computer systems, uncovering valuable evidence and insights that can be instrumental in combating the latest digital menaces.

Malware researchers and IT professionals tasked with incident response often face the challenge of detecting sophisticated threats that leave minimal traces on the disk. These so-called “fileless” malware variants execute directly in memory, evading detection by conventional security solutions. By analyzing the raw binary data residing in a system’s RAM, memory forensics techniques can uncover a wealth of information, from running processes and network connections to previously executed commands and malware artifacts.

In this article, we’ll explore the intricacies of memory forensics, examining its applications, the tools and methodologies involved, and the unique challenges presented by in-memory threats. As we navigate this captivating field, we’ll highlight the crucial role of memory analysis in contemporary cybersecurity strategies and the ongoing battle against digital adversaries lurking within our systems’ volatile memory.

Uncovering the Secrets of Memory Forensics

Memory forensics is the process of capturing and analyzing a computer’s memory to uncover valuable digital artifacts. These artifacts can include information about currently running processes, open files, network connections, system and user configurations, and, crucially, evidence of malware or hacker activity that might not be detectable through traditional disk-based analysis.

Unlike disk forensics, which examines data stored on hard drives and other permanent storage media, memory forensics targets the transient, fleeting data that exists only while a device is powered on. This volatile nature of RAM data presents unique challenges and opportunities for forensic analysts.

Memory forensics can retrieve a wide array of data types that provide a snapshot of the system’s state at the time of capture. These data types include, but are not limited to:

  • Running Processes: Information about active processes, their process IDs (PIDs), parent process IDs (PPIDs), and associated command line arguments.
  • Network Connections: Details about established network connections, including remote IP addresses, ports, and connection states.
  • Loaded Modules: Details about kernel modules, DLLs, and other loadable code entities.
  • User and System Artifacts: Configuration data, registry entries, and other artifacts that reveal insights about the system’s state and user activities.
  • Malware Indicators: Traces of malicious code, suspicious memory regions, and other artifacts that may indicate the presence of malware.

In-Memory vs. Disk-Based Threats

The distinction between in-memory threats and those residing on disk lies in their method of operation and persistence mechanisms, each presenting unique challenges for detection and mitigation.

In-memory threats and fileless malware execute and reside entirely within a system’s volatile memory. This volatile nature allows them to evade traditional antivirus and disk-based forensics tools that rely on scanning files and persistent storage for indicators of compromise. These threats leave minimal to no footprint on the hard drive, making them particularly elusive and difficult to detect.

On the other hand, threats that persist on disk involve malware or malicious activities that write files or configurations for non-volatile storage. These threats often include executable files, scripts, or altered system files. In some cases, they are designed to initiate malicious activities upon system startup, thereby ensuring their persistence even after a reboot.

Disk-based threats are more readily detectable by conventional security solutions, as they involve tangible artifacts that can be scanned, analyzed, and remediated. However, the increasing sophistication of attackers who employ advanced obfuscation and evasion techniques complicates the detection of both in-memory and on-disk threats, necessitating a comprehensive security strategy that includes memory forensics to uncover and address the full spectrum of cyber threats.

Challenges in Memory Forensics

Despite memory forensics’ critical importance in cybersecurity and digital forensics, it is challenging to analyze memory manually. These challenges stem from various technical, logistical, and operational factors contributing to the complexity and sometimes the frustration associated with memory forensics.

One of the main hurdles is the sheer volume of data contained in a memory dump, which can be overwhelming for analysts to sift through manually. Additionally, the transient nature of RAM data means that the window of opportunity to capture and analyze relevant information is often narrow, requiring a well-coordinated and efficient response.

Logistical challenges also arise, such as the need for specialized hardware and software to acquire memory dumps, the potential for data corruption during the acquisition process, and the compatibility issues that may arise when analyzing memory dumps from different systems or environments.

Operational challenges include the requirement for specialized expertise and training, as memory forensics demands a deep understanding of system internals, malware behavior, and the ability to interpret complex data structures. The lack of standardized procedures and the constantly evolving nature of digital threats further complicate the task of memory analysis.

While memory forensics presents significant challenges for many organizations, advancements in tools, techniques, and training help to mitigate these difficulties. Automation and machine learning are leveraged to sift through large datasets more efficiently. Community-driven efforts are improving the sharing of knowledge and best practices. Furthermore, the development of more intuitive and powerful forensic tools is gradually lowering the barrier to entry, making memory forensics more accessible to a broader range of professionals.

Threats in Memory: A Closer Look

Regarding examples of threats in memory, we do not lack choice. From novices using snippets of code and scripts, to sophisticated APT groups, many malicious actors use memory payloads.

One of the most famous examples of a memory threat is the penetration testing tool Cobalt Strike. Used by both red teams and threat actors alike, Cobalt Strike has multiple ways to sneakily inject its Beacon into memory. The easiest way is using a stageless payload artifact. The stageless Cobalt Strike payload starts by executing an EXE or script that involves the creation of a thread that sets up a named pipe for privilege escalation. Once the shellcode is written to the named pipe, it is decrypted and executed in a separate thread in memory.

More commonly with Cobalt Strike, a stager is used. A stager is an extra step in the deployment of the Beacon payload that uses a small snippet of shellcode that can be delivered using any multitude of methods. Cobalt Strike stagers are designed to be loaded and executed only in-memory. This opens up many possibilities for how this shellcode is shipped, making signature-based detection on the delivery method a cat-and-mouse game. Depending on how the code is delivered, the code can be injected into other legitimate running processes, bypassing defenses that do not scan legitimate processes or code in-memory.

In the Operation HamsaUpdate campaign, a payload was delivered and executed only in memory. The chain started with a Delphi executable that dropped an AutoIt interpreter and an obfuscated AutoIt script. The AutoIt script contained shellcode and an encrypted payload. First, the shellcode was injected into memory. The shellcode is an RC4 decryption routine that was used to decrypt the payload, and the decrypted payload was itself then executed in memory.

A really common method used to execute malware in memory is using DLL Side-Loading. To perform this, some threat actors use a trifecta of a legitimate EXE, a malicious DLL loader, and an encrypted payload to execute payloads in memory. This method is especially prevalently used by China-based threat actors to execute payloads such as PlugX or ShadowPad.

Memory Forensic Tools in Action

There are a number of existing tools for memory forensics, many of which are open-source. Let’s talk about a few of the options for manual analysis now.

One of the most popular frameworks for memory forensics is the Volatility Framework, which contains a collection of tools that can extract digital artifacts from memory samples. It supports a variety of file formats and has a plethora of community plugins that extend its capabilities.

YARA is mostly known for its ability in signature-based malware detection, and is also invaluable in memory forensics. With YARA, forensics investigators are able to to easily identify and characterize malware residing solely in RAM.

Originally part of the Rekall Framework, WinPmem is a memory acquisition tool to dump the volatile memory of a machine. With WinPmem, analysts can extract a snapshot of the system’s memory state, including running processes, network connections, and loaded kernel modules, facilitating in-depth forensic analysis and incident response.

Memoryze is a free tool provided by Mandiant for data collection and analysis. It is able to acquire memory images; it has analysis features built in that are similar to some of the plugins provided by Volatility.

GRR is a tool maintained by Google that is an incident response framework focused on remote live forensics. It works by installing an agent on target systems that an admin is able to use to query the live system.

If you’re looking to understand the basics and explore memory forensics, then starting with a free and open-source tool that is popular in the industry, like the Volatility Framework, is a great place to start.

Volatility in Action: A Memory Forensics Example

Let’s take an example using this classic forensic tool. First, we need to dump the volatile memory of our machine. For the purpose of this, we will use WinPmem, to dump a raw image. With this raw image we can now analyze using the Volatility Framework.

First, we can look at what running processes there were when the image was taken by running the pslist command. This is useful as it provides a comprehensive list of all processes running in memory, including their process IDs (PIDs), parent process IDs (PPIDs), and other relevant information such as process names and command line arguments.

Maybe there is nothing that immediately sticks out to you. With Volatility, you can also check all the network connections that were established at the time that the image was taken. It might be easier to read if you pipe out the results to a text file, rather than trying to scroll through a terminal. Maybe that connection to 10.0.0.13 is suspicious?

Another very helpful plugin for Volatility is the “malfind” plugin. Malfind helps find hidden or injected code/DLLs in user mode memory, based on characteristics such as VAD tag and page permissions. The malfind plugin looks for specific anomalies or indicators that suggest the presence of injected code. These indicators may include characteristics such as executable code in non-executable memory regions, suspicious memory permissions (e.g., executable memory in read-only regions), or unexpected changes in memory protection flags.

Malfind brings up quite a lot of results, as even many legitimate programs can have suspicious indicators, such as Microsoft Edge, but one result really sticks out to us, the very stealthily named “my_payload.exe”. One thing that may be obvious to some experienced malware researchers or forensics investigators is this snippet of shellcode. The very obvious stub looks like the Reflective Loader Stub for Cobalt Strike.

There may be a way to double confirm whether this is indeed a Cobalt Strike infection. In this case we are going to use YARA. You have the option of using YARA stand alone by itself, but there are also plugins in Volatility to run YARA also. In this case we will use VadYaraScan. The ruleset that we will provide it with is going to be the really great YARA rule set created by Avast Security. Nice! We see that we have detected a CobaltStrike HTTP stager in memory!

If you wish to investigate it further, we recommend that you use the dumpfiles module to isolate the memory of the target process. Another helpful tool is a Beacon parser provided by SentinelOne.

Automating Memory Forensics

Many investigators are familiar with forensic tools like Volatility, which are valuable for learning about memory analysis or security research. But they also bring along challenges as discussed, like a steep learning curve and time-intensive process required for manually analyzing memory.

In a real-life Security Operations Center (SOC), a team could receive thousands of daily alerts and need to respond promptly. Ideally, every alert potentially indicating an in-memory threat would be investigated. However, due to the high volume of alerts and the complexity and time required for memory forensics, this is not always feasible.

Tools like Volatility simplify the analysis, but they do not address all challenges related to manual memory acquisition and analysis. One solution can be automating memory acquisition and forensic processes upon receiving certain alerts.

For instance, imagine if SOC teams could automatically initiate a memory forensics process whenever an alert about “suspicious behavior detected” is received. The acquisition and analysis of memory would occur automatically, and the analyst would receive a final report with the findings, based on which they can decide if the alert should be escalated.

This automated approach would help SOC teams overcome both technical and logistical challenges. At Intezer, this automated approach is how we perform memory forensics for customers using our Endpoint Scanner.

Intezer’s Endpoint Scanner in Action

The Endpoint Scanner efficiently handles the acquisition and analysis of memory, culminating in a detailed report for further action. Let’s look at an example of a memory threat using the Endpoint Scanner manually first: simply double-click on the Scanner executable, enter your API key, and watch the magic happen!

After a few short seconds, the endpoint scanner will scan the running processes, look for injected memory modules and dump any suspicious code. The whole process takes anywhere from 15 seconds up to one minute. Looking at the scan result, we very clearly see that we have identified Cobalt Strike injected into memory (and which offsets that the payload lies) and under which process.

The endpoint scanner will also provide IOCs and check points of persistence, allowing you to understand how the payload might be maintaining its presence on the victim machine.

The endpoint scanner also works for Linux. It works similarly to what we have seen in Windows: download the scanner and run it with your API key. And we can see the result of the scan as can be seen in the screenshot below.

Automating the Endpoint Scanner

Our scanner is designed with automation at its core. Because of the demands of incident response and proactive hunting workflows, analysts often lack the time to execute endpoint scans manually. Since many security teams leverage Endpoint Detection and Response (EDR) or Mobile Device Management (MDM) products to monitor and manage their endpoints, we can integrate the endpoint scanner with these solutions.

With this, we built an easy way to automate the endpoint analysis process. Intezer provides stand-alone executables that can be integrated with MDM solutions, providing the API key either as a command line parameter or as an environment variable. Endpoint protection and XDR products, such as SentinelOne and CrowdStrike, have automation capabilities that enable Intezer’s endpoint scanner to integrate easily.

For added convenience, Intezer provides scripts for both Windows and Linux platforms, which can be easily uploaded as automation within EDR products. This allows security teams to initiate memory forensics processes automatically upon receiving specific alerts, ensuring that in-memory threats are swiftly detected and addressed.

Conclusion: The Power of Memory Forensics

Memory forensics is very important in the ongoing battle against cyber threats. This area helps us find harmful activities that normal checks might miss, especially the sneaky attacks that don’t leave files behind. While manual memory forensics is tricky because it deals with complex data and fast-changing malware, now the cybersecurity community has more advanced, new solutions like Intezer’s endpoint memory scanner for Windows and Linux which make memory forensics more accessible for every analyst and incident investigation.

As an experienced IT specialist, I’ve seen firsthand the critical role that memory forensics plays in defending against evolving digital threats. By delving into the volatile memory of compromised systems, we can uncover invaluable clues and evidence that might otherwise remain hidden. From identifying suspicious processes and network connections to detecting the presence of sophisticated, fileless malware, memory analysis has become an essential tool in the cybersecurity arsenal.

The rise of in-memory threats, which leverage techniques like code injection and DLL side-loading to execute without leaving a trace on the disk, highlights the growing importance of memory forensics. Traditional security solutions simply aren’t equipped to handle these stealthy attacks, making a comprehensive approach that incorporates memory analysis all the more crucial.

While the complexities of manual memory forensics can be daunting, the emergence of automated tools like Intezer’s Endpoint Scanner is a game-changer. By streamlining the process of memory acquisition and analysis, these solutions empower a broader range of IT professionals and security analysts to effectively detect and respond to in-memory threats.

As the cybersecurity landscape continues to evolve, with attackers constantly devising new methods to evade detection, memory forensics will only become more crucial. By staying ahead of the curve and embracing advanced memory analysis techniques, we can better protect our systems and data from the ever-increasing digital menace. After all, the battle against cyber threats is a constant one, and memory forensics is a powerful weapon in our arsenal.

So, if you’re an IT professional or a cybersecurity enthusiast, I encourage you to explore the world of memory forensics and familiarize yourself with the tools and techniques that can help you stay ahead of the curve. Remember, the key to effective cybersecurity lies in our ability to adapt and evolve alongside the threats we face, and memory forensics is a vital part of that equation. Let’s work together to safeguard our digital landscapes and keep the bad actors at bay!

Facebook
Pinterest
Twitter
LinkedIn

Newsletter

Signup our newsletter to get update information, news, insight or promotions.

Latest Post