Bypassing EDR and Antivirus Protection Using Windows API Calls: A Technical Overview of Gaining Shell Access
As attackers continue to evolve their techniques to bypass Endpoint Detection and Response (EDR) and Antivirus (AV) defenses, tools like EDR-Antivirus-Bypass-to-Gain-Shell-Access, created by murat-exp, demonstrate how attackers can use low-level Windows API functions to inject malicious payloads into process memory undetected.This post explores the technical details of how this tool operates, how it leverages Windows APIs like VirtualAlloc, CreateThread, and WaitForSingleObject, and provides specific recommendations on how to detect and mitigate these types of attacks.
How EDR-Antivirus-Bypass-to-Gain-Shell-Access Works
The EDR-Antivirus-Bypass-to-Gain-Shell-Access tool bypasses traditional EDR and AV detection mechanisms by injecting payloads directly into memory using Windows API functions. These functions are widely used in legitimate applications but, when used maliciously, can allow an attacker to bypass security controls and establish a reverse shell on the compromised machine.
1. Using VirtualAlloc to Allocate Memory for Payloads
The tool begins by calling VirtualAlloc, a Windows API function used to allocate memory in a process’s address space. The allocated memory is marked as PAGE_EXECUTE_READWRITE, which allows the attacker to write the payload into memory and execute it later.
Example: VirtualAlloc allocates space in the target process’s memory for the shellcode, bypassing traditional file-based AV detection since no malicious files are written to disk.
2. Creating a Thread to Execute the Malicious Payload
Once the shellcode is written into memory, the tool uses CreateThread, another Windows API function, to create a new thread that executes the payload. The payload is injected directly into the process’s memory, avoiding typical detection techniques like behavior monitoring by EDR solutions.
Example: The tool calls CreateThread to execute the shellcode inside a trusted process (e.g., explorer.exe), making it harder for EDR to flag this as suspicious since the process itself is legitimate.
3. Using WaitForSingleObject to Maintain Process Control
After creating the thread and launching the payload, the tool uses WaitForSingleObject, a synchronization API, to wait for the shellcode execution to complete. This ensures that the thread running the malicious code remains active until the payload has fully executed, at which point it establishes a reverse shell.
Example: WaitForSingleObject keeps the newly created thread active, allowing the attacker’s code to run undetected, opening a reverse shell connection to the attacker’s system.
Offensive Use Cases
- Memory Injection for Shell Access: By leveraging these Windows API calls, the tool avoids writing anything to disk, making it invisible to most signature-based AV solutions. Once the reverse shell is established, the attacker can remotely control the target machine, execute commands, and escalate privileges.
- Evasion through Legitimate APIs: The use of legitimate Windows API functions like VirtualAlloc and CreateThread makes it difficult for EDR solutions to detect the attack since these APIs are commonly used by legitimate software. This enables attackers to hide malicious actions within standard system processes.
Defensive Measures and Detection Techniques
To defend against these types of attacks, security teams must look beyond file-based detection and focus on behavioral analytics and memory-based monitoring:
- Monitor Memory Allocation: Monitoring API calls like VirtualAlloc for unusual activity—such as large memory allocations by processes that don’t normally allocate executable memory—can reveal attacks that bypass traditional disk-based detection methods.
Recommendation: Implement monitoring tools that log and analyze memory allocation patterns, especially in high-risk processes like
explorer.exe
orsvchost.exe
. - Track Thread Creation in Sensitive Processes: By tracking calls to CreateThread and linking them to suspicious activities (e.g., threads created in trusted processes but executing unfamiliar code), defenders can detect malicious injections in real time.
Recommendation: Use Sysmon or other advanced logging tools to monitor thread creation in critical processes, setting up alerts for any abnormal or unexpected behavior.
- Behavioral Analysis and Process Monitoring: Behavioral detection is key. EDR systems should be configured to detect unusual process behavior, such as unexpected network connections or processes creating threads that lead to network-based activities.
Recommendation: Deploy behavior-based detection solutions that can monitor the interactions between processes, memory, and the network.
Final Thoughts
The EDR-Antivirus-Bypass-to-Gain-Shell-Access tool exemplifies how attackers are exploiting legitimate Windows API functions like VirtualAlloc, CreateThread, and WaitForSingleObject to evade detection and gain persistent access to systems. Defenders must strengthen their endpoint monitoring by incorporating memory-based detection techniques and leveraging behavioral analytics to detect such sophisticated attacks.
At Terraeagle, we help organizations stay ahead of evolving threats by building resilient defenses that go beyond traditional detection. Contact us to learn more about securing your endpoints against advanced evasion tactics.