Skip to content
KitploitKITPLOIT
OutilsBlog
Soumettre
OutilsBlog
Soumettre

Outils de Hacking, PenTest et Cybersécurité pour votre Arsenal de Sécurité !

Kitploit est un répertoire d'outils de hacking, de cybersécurité et de pentesting. Découvrez les dernières mises à jour des projets pour trouver des vulnérabilités, analyser des systèmes, automatiser les tests et renforcer votre sécurité.

··Flux·Contact·Confidentialité·© 2026 Kitploit

Répertoire d'outils

Catégories

Voir toutes les catégories
Loading categories
BOF_ExecuteAssembly — Beacon Object File pour Cobalt Strike qui exécute des assemblys .NET dans le beacon avec des techniques d'évasion. | Kitploit
Outils/GitHubGitHub/ntdallas/bof_executeassembly
Escalade de PrivilègesÉvasion IDS/IPSShellcodePost-ExploitationCommandement et ContrôleRed TeamingExploitation de Binaires
GitHubntdallas/bof_executeassembly

BOF_ExecuteAssembly

Beacon Object File pour Cobalt Strike qui exécute des assemblys .NET dans le beacon avec des techniques d'évasion.

Voir le dépôt
19527il y a 8 moisVérifié par Kitploit

Populaires

Voir tout →

Découvrez les outils les plus utilisés par notre communauté.

Explorer tous les outils

Parcourez notre collection d'outils

Voir tous les outils →
Partager

BOF Execute-Assembly

Beacon Object File pour Cobalt Strike qui exécute des assemblys .NET dans le beacon avec des techniques d'évasion.

Vue d'ensemble

Architecture de base

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)                                  │
└──────────────────────────────────────────────────────────────────────────────┘

Méthodes de proxy

MéthodeDescription
NoneAppels API directs
DraugrAppels API avec spoofing de pile via Draugr

Méthodes d'évasion AMSI

MéthodeDescription
NoneAucun contournement AMSI
PatchPatch mémoire de AMSI!AmsiScanBuffer (xor rax,rax; ret)
HWBPHook par point d'arrêt matériel sur AMSI!AmsiScanBuffer via VEH

Méthodes d'évasion ETW

MéthodeDescription
NoneAucun contournement ETW
PatchPatch mémoire de NTDLL!NtTraceEvent (xor rax,rax; ret)

Configuration supplémentaire

ParamètreDescriptionExemple
PipeNameNom du pipe nommé pour capturer la sortie de l'assemblyP1p3N4m3
AppDomainNom d'AppDomain .NET personnalisé pour l'isolation de l'assemblyTot4lL3g1t

Détails des méthodes de chargement proxy

1. Direct (PROXY_NONE)

root@kitploit:~
LoadLibraryA("amsi.dll") → Direct call

2. Draugr (PROXY_DRAUGR)

root@kitploit:~
DRAUGR_API(LoadLibraryA, "amsi.dll")
    │
    ├─ Synthetic Stack Construction
    ├─ Return Address Spoofing
    └─ Indirect Execution

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()

Détails de l'évasion AMSI

Patch mémoire (AMSI_PATCH)

root@kitploit:~
Before Patch:                    After 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
  ...                              ...

Result: All scans return S_OK (clean)

Méthode :

  1. Enregistrer les 4 octets d'origine
  2. Changer la protection mémoire en RW
  3. Écrire xor rax, rax; ret
  4. Restaurer la protection mémoire
  5. Restaurer les octets d'origine lors du nettoyage

Point d'arrêt matériel (AMSI_HWBP)

root@kitploit:~
Setup:
    1. AddVectoredExceptionHandler
    2. RtlCaptureContext
    3. Set DR0 = AmsiScanBuffer address
    4. Enable DR7 breakpoint flag
    5. NtContinue (apply context)

Execution Flow:
    AmsiScanBuffer called
        │
        ▼
    #BP Exception (EXCEPTION_SINGLE_STEP)
        │
        ▼
    VEH Handler intercepts
        │
        ├─ Verify RIP == AmsiScanBuffer
        ├─ Set RIP = FindRetInstruction(AmsiScanBuffer)
        ├─ Set RAX = 0 (S_OK)
        └─ Set TF (Trap Flag)
        │
        ▼
    Return with RAX=0

Détails de l'évasion ETW

Patch de NtTraceEvent (ETW_PATCH_NTDLL)

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

Mécanisme de capture de la sortie

root@kitploit:~
Standard Assembly (No BOF):         BOF Execute-Assembly:
    Assembly → Console.WriteLine        1. Create \\.\pipe\{name}
        │                                   │
        ▼                                   ▼
    Output lost                         2. Open pipe as file handle
                                           │
                                           ▼
                                        3. Redirect PEB handles:
                                           • StdOut → pipe
                                           • StdErr → pipe
                                           │
                                           ▼
                                        4. Execute assembly
                                           │
                                           ▼
                                        5. ReadFile(pipe)
                                           │
                                           ▼
                                        6. BeaconPrintf → Operator

Techniques d'évasion

Vecteurs de détection

Callbacks ETW-TI (Threat Intelligence)

Changements de protection mémoire :

  • Appels NtProtectVirtualMemory journalisés via EtwTiLogReadWriteVm
  • Le patch AMSI crée une transition RW→RX sur la section .text de amsi.dll
  • Le patch ETW crée une transition RW→RX sur la section .text de ntdll.dll

Détection : Les changements de protection mémoire sur les modules chargés sont de forts indicateurs.

Callbacks noyau

Création de pipe nommé :

  • NtCreateFile avec un chemin \\.\pipe\* visible par les pilotes minifilter
  • La redirection de sortie basée sur un pipe crée des artefacts détectables

Chargement de modules :

  • Événements LdrLoadDll journalisés par les pilotes noyau EDR
  • L'abus de Timer Queue / RegisterWait peut déclencher une détection comportementale

Manipulation du contexte de thread (méthode HWBP) :

  • L'utilisation de points d'arrêt matériels sans présence de débogueur est suspecte

Indicateurs comportementaux

  • Création de console cachée (AllocConsole + ShowWindow(SW_HIDE))
  • Modification du PEB (handles StandardOutput/StandardError modifiés)
  • CLR chargé dans le processus beacon (inhabituel pour des exécutables natifs)
  • Création d'AppDomain personnalisé (les domaines non par défaut sont suspects)
  • Enregistrement d'un gestionnaire VEH sans débogueur (méthode HWBP)

Utilisation

Charger le script

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

Configurer

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

BOF Custom

Exemple

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

Mimikatz

root@kitploit:~
beacon> help BOF_ExecuteAssembl

Help

Compilation

Avec 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

Ou, si vous avez nasm, make et mingw-w64 (compatible avec gcc-13) sur votre système :

root@kitploit:~
make

Sortie : Bin/BOF_ExecuteAssembly.o

Vecteurs de détection

Crédits

  • anthemtotheego: https://github.com/anthemtotheego/InlineExecute-Assembly/tree/main
  • TheWover: https://github.com/TheWover/donut
Télécharger l’outil
RegwaitExécution de callback RegisterWaitForSingleObject
TimerExécution de callback de file de temporisation
TechniqueContournements
Indirect SyscallsHooks API userland (EDR/AV)
Draugr Stack SpoofingOutils d'inspection de la pile d'appels
AMSI Patch/HWBPAnalyse des assemblys .NET
ETW PatchingSurveillance basée sur les événements
Proxy DLL LoadingSurveillance des stackframes LoadLibrary
Named Pipe MalleableSurveillance des pipes
Custom AppDomainSurveillance de l'AppDomain par défaut