Search
🌋

CALDERA - EMU for Offline Setting

CALDERA Emu Plugin은 CTID의 adversary_emulation_library를 기반으로 CALDERA에 공격 조직을 재현할 수 있게 만들어주는 플러그인이다.
공격을 재현할 때는 아무래도 제한된 네트워크 환경(Without Internet Access)에서 할 경우가 많다. 물론 이를 위한 사전 설정이 어느정도 존재했지만 상당히 부실했고, 그 문제들을 해결하기 위한 과정이다.
해결 이후 라이브러리를 제대로 사용하기 위해서는 라이브러리 별 설정해줘야하는 부분이 상당히 많아 골치아프지만 이건 온라인과 오프라인 공통사항인만큼 아래 사항들을 해결한다면 Emu 플러그인을 오프라인에서도 충분히 활용 가능할 것이다.
아래 주어진 과정들을 모두 온라인 환경에서 세팅한 이후 오프라인으로 가져간다고 가정한다.
아래에서 나오는 스크립트들은 실제 악성행위에 사용되는 툴 및 페이로드를 다운받습니다. 따라서 안전한 환경에서만 사용하셔야하며 악의적 목적의 사용을 금하며, 법적 책임은 본인에게 있습니다.

문제 해결 과정

1. 페이로드 다운로드

문제 - 하드코딩

기존 다운로드 스크립트는 하드 코딩된 curl을 통한 다운로드 adversary_emulation_library 업데이트 시 신규 페이로드 파일을 다운받지 못하는 현상이 발생
Download_payload.sh

해결 - 자동화

yaml 리스트를 전부 스캔 pdf 및 html 확장자를 제외한 모든 URL 추출 및 중복 제거
압축파일 zip의 경우 압축해제 (AdFind.zip 비밀번호 하드코딩)
다운로드 성공 및 실패 로그 생성
Get_All_Payloads.sh (Part 1)
#!/bin/bash # Author : absolroot # This script searches for YAML files in the current directory, extracts URLs excluding PDF and HTML files, and downloads them to the /payloads directory. Successful and failed downloads are recorded in download_list.txt and download_fail_list.txt, respectively. Additionally, if a downloaded file is a .zip file, it is automatically unzipped. # If you're deploying the plugin without interent access, you can copy this script to an internet connected host, run it, and then copy the resulting payloads back to the emu/payloads directory # Initialize files to store the lists of successful and failed downloads. > download_list.txt > download_fail_list.txt # Find all YAML files in the current directory. find . -name "*.yaml" | while read -r file do # Extract URLs from each file, excluding PDF and HTML, and remove duplicates. grep -oP '\bhttps?:\/\/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:\/[-a-zA-Z0-9()@:%_\+.~#?&//=]*\/)[^.\/]+?\.(?!pdf|html\b)[a-zA-Z0-9]{1,10}\b' "$file" | sort | uniq | while read -r url do # Create the /payloads folder if it does not exist. mkdir -p ./payloads # Extract the file name. filename=$(basename "$url") # Download the file from the URL and record the outcome in the respective list. if curl -L -o "./payloads/$filename" "$url"; then echo "$url" >> download_list.txt # If the file is a zip file, attempt to unzip it. if [[ "$filename" == *".zip" ]]; then # For a specific zip file, use a password to unzip. if [[ "$filename" == "AdFind.zip" ]]; then unzip -o -P NotMalware "./payloads/$filename" -d "./payloads/" else unzip -o "./payloads/$filename" -d "./payloads/" fi fi else echo "$url" >> download_fail_list.txt fi done done
Bash
복사

2. 파일명 불일치 해결

문제 - 파일명 불일치

curl을 통해 다운로드 된 페이로드와 yaml에 등록된 페이로드 파일명의 불일치

해결 - 일치 수작업

yaml 확인을 통해 필요한 페이로드 이름 변경 적용 (자동화 제한)
Get_All_Payloads.sh (Part 2)
# For app/emu_svc.py cp payloads/NetSess.exe payloads/netsess.exe cp payloads/psexec_windows.exe payloads/psexec.exe cp payloads/AdFind.exe payloads/adfind.exe cp payloads/secretsdump_windows.exe payloads/secretsdump.exe cp payloads/nbtscan-1.0 payloads/nbtscan.exe cp payloads/psexec.py payloads/psexec_sandworm.py ## name: OilRig Downloads mom64.exe(m64.exe) ## description: OilRig uses the webshell to download Mimikatz as mom64.exe to WATERFALLS cp payloads/mimikatz.exe payloads/m64.exe
Bash
복사

3. 라이브러리 내 페이로드 압축해제

문제 - 압축된 페이로드

일부 Emulation Library는 Resource 폴더에 페이로드를 별도로 보관하고 있어 따로 서버에 요청하지 않고 직접 사용
압축된 상태로 존재하여 Adversary 사용을 위해서는 압축해제가 필요

해결 - 자동 압축해제(비밀번호 포함)

readme 기반 ‘malware’ 디폴트 패스워드 식별, emu 폴더 내 전체 압축해제
Get_All_Payloads.sh (Part 3)
# Find and unzip all .zip files in subdirectories of the current directory, excluding the ./payloads folder. find . -path ./payloads -prune -o -name "*.zip" -print | while read -r zipfile do # Find the directory of the zip file. dir=$(dirname "$zipfile") echo "Attempting to unzip $zipfile in $dir with default password 'malware'" # Try unzipping with the default password if unzip -o -P malware "$zipfile" -d "$dir"; then echo "Successfully unzipped $zipfile with default password." else echo "Default password failed. Please enter the password for $zipfile:" # Ask user for the password read -s user_password unzip -o -P "$user_password" "$zipfile" -d "$dir" fi done echo "All zip files have been processed."
Bash
복사

4. 모든 페이로드 다운로드 URL 변경

문제 - 인터넷 필요

절대다수의 yaml은 온라인을 통한 페이로드 다운로드 또는 파일리스 공격을 수행

해결 - 오프라인/온라인 모드 설정

오프라인 / 온라인 모드 선택 가능
오프라인 모드
기존 yml/yaml 백업 생성
사용자 설정 서버 주소로 모든 URL 변경 (ex. https://www.example.com/test.exe → 192.168.0.1/payloads/test.exe )
apache로 웹서버를 열어 기존 다운받았던 payloads를 모두 복사
192.168을 포함하는 URL의 경우 변경하지 않음
온라인 모드 - 백업 존재 시 복구
Make_Offline_mode.sh
#!/bin/bash echo "Select mode: 1 for Offline, 2 for Online" read mode process_yaml() { file_extension=$1 backup_extension=$2 find . -name "*.$file_extension" | while read -r file do # Check if the file contains URLs excluding PDF and HTML. if grep -qP '\bhttps?:\/\/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:\/[-a-zA-Z0-9()@:%_\+.~#?&//=]*\/)[^.\/]+?\.(?!pdf|html\b)[a-zA-Z0-9]{1,10}\b' "$file"; then # Create a backup of the YAML file. cp "$file" "${file%.*}_$backup_extension" echo "" echo "[*] $file" echo "[+] Backup created: ${file%.*}_$backup_extension" # Replace URLs in the file. grep -oP '\bhttps?:\/\/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:\/[-a-zA-Z0-9()@:%_\+.~#?&//=]*\/)[^.\/]+?\.(?!pdf|html\b)[a-zA-Z0-9]{1,10}\b' "$file" | sort | uniq | while read -r url do # Skip URLs containing "192.168". if [[ ! $url =~ 192\.168 ]]; then # Extract the file name. filename=$(basename "$url") echo "[+] Replacing URL" echo " $url" echo " → $server$filename" # Replace the URL in the YAML file. sed -i "s|$url|$server$filename|g" "$file" else echo "[+] Skipping URL: $url as it contains '192.168'" fi done fi done } restore_backup() { file_extension=$1 backup_extension=$2 find . -name "*_$backup_extension" | while read -r backup_file do original_file="${backup_file%_$backup_extension}.$file_extension" if [ -f "$original_file" ]; then echo "[+] Restoring $original_file from backup." cp "$backup_file" "$original_file" fi done } case $mode in 1) # Offline Mode echo "Offline mode selected. You will be prompted to enter the server address for payload downloads." echo "Enter the server address for downloading payloads (ex. 192.168.0.1/payloads/):" read server echo "Server address set to: $server" process_yaml "yaml" "yaml_backup" process_yaml "yml" "yml_backup" ;; 2) # Online Mode echo "Online mode selected. Restoring original YAML files from backups." restore_backup "yaml" "yaml_backup" restore_backup "yml" "yml_backup" ;; *) echo "Invalid mode selected. Please select either 1 (Offline) or 2 (Online). Exiting." exit 1 ;; esac
Bash
복사

✓ 다른 [정리] 포스트

베트남 환전 왜 한국에서 하면 안될까? (한국 vs 공항 vs 금은방)
Travel
베트남 환전 왜 한국에서 하면 안될까? (한국 vs 공항 vs 금은방)
Travel
Load more
︎ 더 많은 게시물을 보려면
︎ 작성자가 궁금하면?
 2023. Absolroot all rights reserved.