Skip to content
KitploitKITPLOIT
StrumentiBlog
Invia
StrumentiBlog
Invia

Strumenti di Hacking, PenTest e Cybersecurity per il tuo Arsenale di Sicurezza!

Kitploit è una directory di strumenti di hacking, cybersecurity e pentesting. Scopri gli ultimi aggiornamenti dei progetti per trovare vulnerabilità, analizzare sistemi, automatizzare i test e rafforzare la tua sicurezza.

··Feed·Contatto·Privacy·© 2026 Kitploit

Directory degli strumenti

Categorie

Vedi tutte le categorie
Loading categories
BOF_ExecuteAssembly — File Oggetto Beacon per Cobalt Strike che esegue assembly .NET in beacon con tecniche di evasione. | Kitploit
Strumenti/GitHubGitHub/ntdallas/bof_executeassembly
Escalation di PrivilegiEvasione IDS/IPSShellcodePost-ExploitCommand and ControlRed TeamingBinary Exploitation
GitHubntdallas/bof_executeassembly

BOF_ExecuteAssembly

File Oggetto Beacon per Cobalt Strike che esegue assembly .NET in beacon con tecniche di evasione.

Vedi Repository
195278 mesi faRevisionato da Kitploit

Più Popolari

Vedi tutti →

Scopri gli strumenti più utilizzati dalla nostra community.

Esplora tutti gli strumenti

Sfoglia la nostra collezione di strumenti

Vedi tutti gli strumenti →
Condividi

BOF Execute-Assembly

Beacon Object File per Cobalt Strike che esegue assembly .NET nel beacon con tecniche di evasione.

Panoramica

Architettura Principale

root@kitploit:~
┌──────────────────────────────────────────────────────────────────────────────┐
│                         Cobalt Strike Beacon                                 │
│                         (Parent Process)                                     │
└──────────────────────────────────┬───────────────────────────────────────────┘
                                   │
                                   │ beacon_inline_execute()
                                   │ - Parse packed arguments
                                   │ - Call go()
                                   ▼
┌──────────────────────────────────────────────────────────────────────────────┐
│                      BOF Execute-Assembly Entry (go)                         │
│  ┌────────────────────────────────────────────────────────────────────────┐  │
│  │ Configuration Parsing                                                  │  │
│  │  • ProxyMethod (None/Draugr/Timer/RegWait)                             │  │
│  │  • AmsiEvasion (None/Patch/HWBP)                                       │  │
│  │  • EtwEvasion (None/Patch)                                             │  │
│  │  • PipeName, AppDomainName, Assembly bytes, Arguments                  │  │
│  └────────────────────────────────┬───────────────────────────────────────┘  │
│                                   │                                          │
│  ┌────────────────────────────────▼───────────────────────────────────────┐  │
│  │ Framework Initialization                                               │  │
│  │  • InitVxTable() - Resolve syscall numbers                             │  │
│  │    └─> NtProtectVirtualMemory, NtContinue, NtCreateEvent,              │  │
│  │        NtSetEvent, NtWaitForSingleObject, NtClose                      │  │
│  │  • DraugrInit() - Setup synthetic stack frames                         │  │
│  │    └─> Locate RtlUserThreadStart, BaseThreadInitThunk                  │  │
│  └────────────────────────────────┬───────────────────────────────────────┘  │
│                                   │                                          │
│  ┌────────────────────────────────▼───────────────────────────────────────┐  │
│  │ DLL Loading (ProxyLoadLibraryA)                                        │  │
│  │  • amsi.dll, OleAut32.dll, mscoree.dll, User32.dll                     │  │
│  │                                                                        │  │
│  │  PROXY_NONE:     LoadLibraryA() directly                               │  │
│  │  PROXY_DRAUGR:   DRAUGR_API(LoadLibraryA) - spoofed stack              │  │
│  │  PROXY_TIMER:    CreateTimerQueue → Timer callback                     │  │
│  │  PROXY_REGWAIT:  RegisterWaitForSingleObject → Event callback          │  │
│  └────────────────────────────────┬───────────────────────────────────────┘  │
│                                   │                                          │
│  ┌────────────────────────────────▼───────────────────────────────────────┐  │
│  │ AMSI Evasion Setup                                                     │  │
│  │                                                                        │  │
│  │  AMSI_PATCH:                         AMSI_HWBP:                        │  │
│  │  ┌─────────────────────────┐         ┌──────────────────────────────┐  │  │
│  │  │ 1. Backup 4 bytes       │         │ 1. Add VEH Handler           │  │  │
│  │  │ 2. NtProtectVirtualMem  │         │ 2. RtlCaptureContext         │  │  │
│  │  │    (RW)                 │         │ 3. Set DR0 = AmsiScanBuffer  │  │  │
│  │  │ 3. Write:               │         │ 4. Enable DR7 breakpoint     │  │  │
│  │  │    48 31 C0  xor rax,rax│         │ 5. NtContinue (apply ctx)    │  │  │
│  │  │    C3        ret        │         │                              │  │  │
│  │  │ 4. NtProtectVirtualMem  │         │ On AmsiScanBuffer call:      │  │  │
│  │  │    (restore)            │         │   → #BP Exception            │  │  │
│  │  └─────────────────────────┘         │   → VEH redirects to RET     │  │  │
│  │                                      │   → RAX = 0                  │  │  │
│  │                                      └──────────────────────────────┘  │  │
│  └────────────────────────────────┬───────────────────────────────────────┘  │
│                                   │                                          │
│  ┌────────────────────────────────▼───────────────────────────────────────┐  │
│  │ ETW Evasion (if enabled)                                               │  │
│  │  • NtProtectVirtualMemory(NtTraceEvent, RW)                            │  │
│  │  • Backup 4 bytes                                                      │  │
│  │  • Write: 48 31 C0 C3 (xor rax,rax; ret)                               │  │
│  │  • NtProtectVirtualMemory(restore protection)                          │  │
│  └────────────────────────────────┬───────────────────────────────────────┘  │
│                                   │                                          │
│  ┌────────────────────────────────▼───────────────────────────────────────┐  │
│  │ Output Redirection Setup                                               │  │
│  │  ┌──────────────────────────────────────────────────────────────────┐  │  │
│  │  │ 1. CreateNamedPipeW(\\.\pipe\{CustomName})  → hPipe              │  │  │
│  │  │ 2. CreateFileW(pipe path)                   → hFile              │  │  │
│  │  │ 3. AllocConsole() + ShowWindow(SW_HIDE)     → Hidden console     │  │  │
│  │  │                                                                  │  │  │
│  │  │ 4. PEB Manipulation:                                             │  │  │
│  │  │    • Backup: hCurrentStdOut = PEB->ProcessParameters->StdOut     │  │  │
│  │  │    • Backup: hCurrentStdErr = PEB->ProcessParameters->StdErr     │  │  │
│  │  │    • Redirect: PEB->StdOut = hFile                               │  │  │
│  │  │    • Redirect: PEB->StdErr = hFile                               │  │  │
│  │  └──────────────────────────────────────────────────────────────────┘  │  │
│  └────────────────────────────────┬───────────────────────────────────────┘  │
│                                   │                                          │
│  ┌────────────────────────────────▼───────────────────────────────────────┐  │
│  │ CLR Hosting & Assembly Execution (ExecuteAssembly)                     │  │
│  │  ┌──────────────────────────────────────────────────────────────────┐  │  │
│  │  │ 1. CLR Version Detection                                         │  │  │
│  │  │    • Scan assembly bytes for "v2.0.50727" or "v4.0.30319"        │  │  │
│  │  │                                                                  │  │  │
│  │  │ 2. CLR Initialization                                            │  │  │
│  │  │    • CLRCreateInstance → ICLRMetaHost                            │  │  │
│  │  │    • GetRuntime(v2/v4) → ICLRRuntimeInfo                         │  │  │
│  │  │    • GetInterface → ICorRuntimeHost                              │  │  │
│  │  │    • Start()                                                     │  │  │
│  │  │                                                                  │  │  │
│  │  │ 3. AppDomain Management                                          │  │  │
│  │  │    • GetDefaultDomain() → Default AppDomain                      │  │  │
│  │  │    • CreateDomain(CustomName) → Isolated AppDomain               │  │  │
│  │  │                                                                  │  │  │
│  │  │ 4. Assembly Loading                                              │  │  │
│  │  │    • Create SAFEARRAY (VT_UI1) with assembly bytes               │  │  │
│  │  │    • SafeArrayAccessData → Copy assembly to safe array           │  │  │
│  │  │    • CustomAppDomain->Load_3(safearray) → Load in memory         │  │  │
│  │  │                                                                  │  │  │
│  │  │ 5. Argument Preparation                                          │  │  │
│  │  │    • Parse space-delimited arguments                             │  │  │
│  │  │    • Create SAFEARRAY(VT_BSTR) for each argument                 │  │  │
│  │  │    • Wrap in VARIANT structure                                   │  │  │
│  │  │                                                                  │  │  │
│  │  │ 6. Execution                                                     │  │  │
│  │  │    • Assembly->EntryPoint() → Get Main() MethodInfo              │  │  │
│  │  │    • MethodInfo->Invoke_3(arguments) → Execute                   │  │  │
│  │  │       └─> Assembly writes to Console                             │  │  │
│  │  │           └─> Redirected to hFile → Named Pipe                   │  │  │
│  │  │                                                                  │  │  │
│  │  │ 7. Cleanup                                                       │  │  │
│  │  │    • Release COM interfaces (MethodInfo, Assembly, etc.)         │  │  │
│  │  │    • UnloadDomain(CustomAppDomain) → Full unload                 │  │  │
│  │  │    • FreeLibrary(mscoree.dll)                                    │  │  │
│  │  └──────────────────────────────────────────────────────────────────┘  │  │
│  └────────────────────────────────┬───────────────────────────────────────┘  │
│                                   │                                          │
│  ┌────────────────────────────────▼───────────────────────────────────────┐  │
│  │ Output Capture & Display                                               │  │
│  │  • Restore PEB: StdOut/StdErr = original handles                       │  │
│  │  • Allocate buffer (0x10000 bytes)                                     │  │
│  │  • ReadFile(hPipe) → Capture assembly output                           │  │
│  │  • BeaconPrintf(CALLBACK_OUTPUT, output) → Display to operator         │  │
│  └────────────────────────────────┬───────────────────────────────────────┘  │
│                                   │                                          │
│  ┌────────────────────────────────▼───────────────────────────────────────┐  │
│  │ Cleanup & Restoration                                                  │  │
│  │  • free(pAssemblyStdOut)                                               │  │
│  │  • NtClose(hFile, hPipe)                                               │  │
│  │  • FreeConsole()                                                       │  │
│  │                                                                        │  │
│  │  if (AMSI_PATCH):                                                      │  │
│  │    • RestoreAmsi() - Write original 4 bytes back                       │  │
│  │                                                                        │  │
│  │  if (AMSI_HWBP):                                                       │  │
│  │    • RemoveHwbp() - Clear debug registers                              │  │
│  │    • RemoveVectoredExceptionHandler(VehHandler)                        │  │
│  │                                                                        │  │
│  │  if (ETW_PATCH):                                                       │  │
│  │    • RestoreEtw() - Write original 4 bytes back                        │  │
│  │                                                                        │  │
│  │  • Restore PEB: StdOut/StdErr = original                               │  │
│  └────────────────────────────────────────────────────────────────────────┘  │
└──────────────────────────────────────────────────────────────────────────────┘
                                   │
                                   │ Return to Beacon
                                   ▼
┌──────────────────────────────────────────────────────────────────────────────┐
│                     Beacon continues execution                               │
│                     (BOF memory cleaned up)                                  │
└──────────────────────────────────────────────────────────────────────────────┘

Metodi Proxy

MetodoDescrizione
NoneChiamate API dirette
DraugrChiamate API con stack spoofato tramite Draugr

Metodi di Evasione AMSI

MetodoDescrizione
NoneNessun bypass AMSI
PatchPatch in memoria di AMSI!AmsiScanBuffer (xor rax,rax; ret)
HWBPHook hardware breakpoint su AMSI!AmsiScanBuffer tramite VEH

Metodi di Evasione ETW

MetodoDescrizione
NoneNessun bypass ETW
PatchPatch in memoria di NTDLL!NtTraceEvent (xor rax,rax; ret)

Configurazione Aggiuntiva

ParametroDescrizioneEsempio
PipeNameNome della named pipe per catturare l'output dell'assemblyP1p3N4m3
AppDomainNome personalizzato dell'AppDomain .NET per isolamento dell'assemblyTot4lL3g1t

Dettagli Metodi di Caricamento Proxy

1. Diretto (PROXY_NONE)

root@kitploit:~
LoadLibraryA("amsi.dll") → Chiamata diretta

2. Draugr (PROXY_DRAUGR)

root@kitploit:~
DRAUGR_API(LoadLibraryA, "amsi.dll")
    │
    ├─ Costruzione stack sintetico
    ├─ Spoofing dell'indirizzo di ritorno
    └─ Esecuzione indiretta

3. Timer Queue (PROXY_TIMER)

root@kitploit:~
CreateTimerQueue() → CreateTimerQueueTimer(
    callback = LoadLibraryA,
    parameter = "amsi.dll",
    dueTime = 100ms
) → Wait → DeleteTimerQueueEx()

4. RegisterWait (PROXY_REGWAIT)

root@kitploit:~
CreateEvent() → RegisterWaitForSingleObject(
    event,
    callback = LoadLibraryA,
    context = "amsi.dll"
) → SetEvent() → UnregisterWait()

Dettagli Evasione AMSI

Patch in Memoria (AMSI_PATCH)

root@kitploit:~
Prima della Patch:                Dopo la Patch:
AmsiScanBuffer:                  AmsiScanBuffer:
  4C 8B DC     mov r11, rsp        48 31 C0     xor rax, rax
  49 89 5B 08  mov [r11+8], rbx    C3           ret
  ...                              ...

Risultato: Tutte le scansioni restituiscono S_OK (pulito)

Metodo:

  1. Salva i 4 byte originali
  2. Cambia la protezione di memoria in RW
  3. Scrivi xor rax, rax; ret
  4. Ripristina la protezione di memoria
  5. Ripristina i byte originali alla pulizia

Hardware Breakpoint (AMSI_HWBP)

root@kitploit:~
Setup:
    1. AddVectoredExceptionHandler
    2. RtlCaptureContext
    3. Imposta DR0 = indirizzo di AmsiScanBuffer
    4. Abilita flag breakpoint DR7
    5. NtContinue (applica contesto)

Flusso di esecuzione:
    Chiamata a AmsiScanBuffer
        │
        ▼
    Eccezione #BP (EXCEPTION_SINGLE_STEP)
        │
        ▼
    Intercettata dal gestore VEH
        │
        ├─ Verifica RIP == AmsiScanBuffer
        ├─ Imposta RIP = FindRetInstruction(AmsiScanBuffer)
        ├─ Imposta RAX = 0 (S_OK)
        └─ Imposta TF (Trap Flag)
        │
        ▼
    Ritorna con RAX=0

Dettagli Evasione ETW

Patch NtTraceEvent (ETW_PATCH_NTDLL)

root@kitploit:~
Prima:                           Dopo:
NtTraceEvent:                    NtTraceEvent:
  4C 8B D1     mov r10, rcx        48 31 C0     xor rax, rax
  B8 XX XX     mov eax, syscall    C3           ret

Meccanismo di Cattura Output

root@kitploit:~
Assembly standard (senza BOF):          BOF Execute-Assembly:
    Assembly → Console.WriteLine        1. Crea \\.\pipe\{nome}
        │                                   │
        ▼                                   ▼
    Output perso                         2. Apri pipe come file handle
                                           │
                                           ▼
                                        3. Reindirizza handle PEB:
                                           • StdOut → pipe
                                           • StdErr → pipe
                                           │
                                           ▼
                                        4. Esegui assembly
                                           │
                                           ▼
                                        5. ReadFile(pipe)
                                           │
                                           ▼
                                        6. BeaconPrintf → Operatore

Tecniche di Evasione

Vettori di Rilevamento

Callback ETW-TI (Threat Intelligence)

Modifiche alla Protezione della Memoria:

  • Chiamate NtProtectVirtualMemory registrate tramite EtwTiLogReadWriteVm
  • Patching AMSI crea transizione RW→RX sulla sezione .text di amsi.dll
  • Patching ETW crea transizione RW→RX sulla sezione .text di ntdll.dll

Rilevamento: Le modifiche alla protezione della memoria su moduli caricati sono forti indicatori.

Callback del Kernel

Creazione Named Pipe:

  • NtCreateFile con percorso \\.\pipe\* visibile ai driver minifilter
  • Il reindirizzamento dell'output tramite pipe crea artefatti rilevabili

Caricamento Moduli:

  • Eventi LdrLoadDll registrati dai driver del kernel EDR
  • L'abuso di Timer Queue / RegisterWait potrebbe attivare rilevamenti comportamentali

Manipolazione del Contesto del Thread (metodo HWBP):

  • L'uso di hardware breakpoint senza la presenza di un debugger è sospetto

Indicatori Comportamentali

  • Creazione di console nascosta (AllocConsole + ShowWindow(SW_HIDE))
  • Modifica del PEB (handle StandardOutput/StandardError modificati)
  • CLR caricato nel processo beacon (insolito per eseguibili nativi)
  • Creazione di AppDomain personalizzato (domini non predefiniti sospetti)
  • Registrazione di gestore VEH senza debugger (metodo HWBP)

Utilizzo

Carica Script

root@kitploit:~
Cobalt Strike → Script Manager → Load → BOF_ExecuteAssembly.cna

Configura

root@kitploit:~
Menu: Additionals postex → Execute-Assembly Config

BOF Custom

Esempio

root@kitploit:~
BOF_ExecuteAssembly --assembly /tmp/Ghostpack-CompiledBinaries/Rubeus.exe --args help

Mimikatz

root@kitploit:~
beacon> help BOF_ExecuteAssembl

Help

Compilazione

Con Dockerfile:

root@kitploit:~
sudo docker build -t ubuntu-gcc-13 .
sudo docker run --rm -it -v "$PWD":/work -w /work ubuntu-gcc-13:latest make

Oppure, se hai nasm, make e mingw-w64 (compatibile con gcc-13) sul sistema:

root@kitploit:~
make

Output: Bin/BOF_ExecuteAssembly.o

Vettori di Rilevamento

Crediti

  • anthemtotheego: https://github.com/anthemtotheego/InlineExecute-Assembly/tree/main
  • TheWover: https://github.com/TheWover/donut
Scarica lo strumento
RegwaitEsecuzione tramite callback RegisterWaitForSingleObject
TimerEsecuzione tramite callback Timer Queue
TecnicaCosa Bypassa
Syscall IndiretteHook API in userland (EDR/AV)
Stack Spoofing DraugrStrumenti di ispezione call stack
Patch AMSI / HWBPScansione assembly .NET
Patch ETWMonitoraggio basato su eventi
Caricamento DLL ProxyMonitoraggio stack frame di LoadLibrary
Named Pipe MalleabileMonitoraggio pipe
AppDomain PersonalizzatoMonitoraggio dell'AppDomain predefinito