Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
BOF_ExecuteAssembly — 用于 Cobalt Strike 的 Beacon Object File,可在 beacon 中执行 .NET 程序集,并采用规避技术。 | Kitploit
工具/GitHubGitHub/ntdallas/bof_executeassembly
权限提升IDS/IPS规避Shellcode后渗透利用命令与控制红队二进制利用
GitHubntdallas/bof_executeassembly

BOF_ExecuteAssembly

用于 Cobalt Strike 的 Beacon Object File,可在 beacon 中执行 .NET 程序集,并采用规避技术。

查看仓库
195278个月前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

BOF Execute-Assembly

用于 Cobalt Strike 的 Beacon 对象文件,可在 beacon 内使用规避技术执行 .NET 程序集。

概述

核心架构

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

代理方法

Method描述
None直接 API 调用
Draugr通过 Draugr 进行栈欺骗的 API 调用
RegwaitRegisterWaitForSingleObject 回调执行

AMSI 规避方法

Method描述
None无 AMSI 绕过
Patch对 AMSI!AmsiScanBuffer 进行内存补丁 (xor rax,rax; ret)
HWBP通过 VEH 对 AMSI!AmsiScanBuffer 设置硬件断点钩子

ETW 规避方法

Method描述
None无 ETW 绕过
Patch对 NTDLL!NtTraceEvent 进行内存补丁 (xor rax,rax; ret)

附加配置

参数描述示例
PipeName用于捕获程序集输出的命名管道名称P1p3N4m3
AppDomain用于程序集隔离的自定义 .NET AppDomain 名称Tot4lL3g1t

代理加载方法详解

1. 直接 (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. 计时器队列 (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()

AMSI 规避详解

内存补丁 (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)

方法:

  1. 保存原始 4 字节
  2. 将内存保护更改为 RW
  3. 写入 xor rax, rax; ret
  4. 恢复内存保护
  5. 清理时恢复原始字节

硬件断点 (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

ETW 规避详解

修补 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

输出捕获机制

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

规避技术

检测途径

ETW-TI(威胁情报)回调

内存保护变更:

  • 通过 EtwTiLogReadWriteVm 记录 NtProtectVirtualMemory 调用
  • AMSI 修补会在 amsi.dll 的 .text 节上产生 RW→RX 转换
  • ETW 修补会在 ntdll.dll 的 .text 节上产生 RW→RX 转换

检测:已加载模块上的内存保护变更是很强的指标。

内核回调

命名管道创建:

  • 使用 \\.\pipe\* 路径的 NtCreateFile 对 minifilter 驱动可见
  • 基于管道的输出重定向会产生可检测的痕迹

模块加载:

  • EDR 内核驱动记录 LdrLoadDll 事件
  • 滥用计时器队列 / RegisterWait 可能触发行为检测

线程上下文操作(HWBP 方法):

  • 在没有调试器的情况下使用硬件断点很可疑

行为指标

  • 隐藏控制台创建(AllocConsole + ShowWindow(SW_HIDE))
  • PEB 修改(StandardOutput/StandardError 句柄被更改)
  • 在 beacon 进程中加载 CLR(对原生可执行文件而言不寻常)
  • 创建自定义 AppDomain(非默认域很可疑)
  • 在没有调试器的情况下注册 VEH 处理器(HWBP 方法)

使用方法

加载脚本

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

配置

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

BOF Custom

示例

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

Mimikatz

root@kitploit:~
beacon> help BOF_ExecuteAssembl

Help

编译

使用 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

或者,如果你的系统上装有 nasm、make 和 mingw-w64(与 gcc-13 兼容):

root@kitploit:~
make

输出:Bin/BOF_ExecuteAssembly.o

检测途径

致谢

  • anthemtotheego: https://github.com/anthemtotheego/InlineExecute-Assembly/tree/main
  • TheWover: https://github.com/TheWover/donut
下载工具
Timer计时器队列回调执行
技术绕过目标
间接系统调用用户态 API 钩子 (EDR/AV)
Draugr 栈欺骗调用栈检查工具
AMSI Patch/HWBP.NET 程序集扫描
ETW 修补基于事件的监控
代理 DLL 加载LoadLibrary 栈帧监控
Malleable 命名管道管道监控
自定义 AppDomain默认 AppDomain 监控