CobaltStrike插件开发官方指南 Part4
字数 1361 2025-08-26 22:11:40
CobaltStrike插件开发官方指南 Part4 - 日志/计数器/窗口与自定义报告
0x07 日志/计数器/窗口
事件日志
Cobalt Strike的运算符和脚本将全局事件传递给共享事件日志,AgScripts可以对这些日志进行操作:
-
事件监听:
- 事件日志事件均以
event_开头 - 使用
event_notify列出全局通知:on event_notify { println("I see: $1"); }
- 事件日志事件均以
-
日志输出:
- 使用
say函数输出消息到共享事件日志:say("Hello World"); - 使用
elog函数发布重大事件或通知(服务器会自动添加时间戳并存储):elog("system shutdown initiated");
- 使用
计时器
利用AgScript中的heartbeat_X实现定期执行任务:
on heartbeat_10s {
println("I happen every 10 seconds");
}
支持的时间间隔:1s,5s,10s,15s,30s,1m,5m,10m,15m,20m,30m或60m
对话框
-
基础对话框:
show_message显示信息提示show_error显示错误提示- 示例:
bind Ctrl+M { show_message("show_message!"); show_message("show_error!"); }
-
输入对话框:
prompt_text提示输入框:prompt_text("What is your name?", "Joe Smith", { show_message("Please $1 $+ , pleased to meet you"); });prompt_confirm确认框,用法与prompt_text相似
自定义对话框
AgScript提供API构建自定义对话框:
-
基本流程:
dialog函数创建对话框- 对话框由行和按钮组成
- 行包含标签、名称、GUI组件和可能的帮助程序
- 关闭按钮触发回调函数,参数为字典(行名称映射到输入值)
dialog_show显示对话框
-
示例代码:
sub callback { println("Dialog was actioned. Button: $2 Values: $3"); } $dialog = dialog("Host File", %(uri => "/download/file.ext", port => 80, mimetype => "automatic"), &callback); dialog_description($dialog, "Host a file through Cobalt Strike's web server"); drow_file($dialog, "file", "File:"); drow_text($dialog, "uri", "Local URI:"); drow_text($dialog, "host", "Local Host:", 20); drow_text($dialog, "port", "Local Port:"); drow_combobox($dialog, "mimetype", "Mime Type:", @("automatic", "application/octet-stream", "text/html", "text/plain")); dbutton_action($dialog, "Launch"); dbutton_help($dialog, "https://www.cobaltstrike.com/help-host-file"); dialog_show($dialog); -
组件说明:
dialog_description: 添加窗口描述drow_file: 添加文件选择组件drow_text: 添加输入框(可指定长度)drow_combobox: 添加下拉选择框dbutton_action: 添加动作按钮dbutton_help: 添加帮助链接
0x08 自定义报告
报告处理基础
-
报告语言:
- Cobalt Strike使用特定领域语言定义报告
- 类似AgScript但大多数API不可访问
- 报告生成过程与AgScript脚本引擎无关
-
默认报告:
default.rpt文件定义了默认报告样式
报告加载
-
加载路径:
- Cobalt Strike -> Preferences -> Reports
- 可选择logo文件和.rpt文件
- 保存后在Reporting功能中可见自定义报告
-
错误处理:
- 导出报告时发生错误可在View -> Script Console查看详情
报告示例
# default description of our report [the user can change this].
describe("Hello Report", "This is a test report.");
# define the Hello Report
report "Hello Report" {
# the first page is the cover page of our report.
page "first" {
# title heading
h1($1['long']);
# today's date/time in an italicized format
ts();
# a paragraph [could be the default...
p($1['description']);
}
# this is the rest of the report
page "rest" {
# hello world paragraph
p("Hello World!");
}
}
报告函数:
h1: 输出标题ts: 输出日期/时间戳p: 输出段落
数据聚合API
-
功能:
- 提供当前连接到的所有团队服务器数据的合并视图
- 提供评估活动的综合报告
- 函数以
ag前缀开头(如agTargets)
-
使用方式:
- 报表引擎在生成报表时传递数据聚合模型作为
$3参数
- 报表引擎在生成报表时传递数据聚合模型作为
总结
-
开发要点:
- 掌握AgScript基本语法
- 熟悉函数库中的可用函数
- 函数库参考:https://www.cobaltstrike.com/aggressor-script/functions.html
-
开发流程:
- 确定功能需求
- 查找相关API函数
- 编写脚本逻辑
- 测试和调试
通过以上知识,开发者可以轻松编写出符合需求的Cobalt Strike插件,实现日志处理、定时任务、自定义界面和报告生成等功能。