티스토리 뷰
1. Case Overview:
The IMF is hit by a cyber attack compromising sensitive data. Luther sends Ethan to retrieve crucial information from a compromised server. Despite warnings, Ethan downloads the intel, which later becomes unreadable. To recover it, he creates a forensic image and asks Benji for help in decoding the files.
Q1.
What is the MD5 hash of the potentially malicious EXE file the user downloaded?
문제파일을 처음 열고 바탕화면이나 다운로드 등의 폴더들을 확인해본 결과 아래와 같이 바탕화면엔 암호화된 파일과 다운로드 화면엔 여려 PDF 파일들이 있음을 확인 할 수 있었다.
하지만 다운로드를 확인하면 IMF-info.pdf.exe 파일로 pdf로 위장한 실행파일이 있음을 확인했다.
해당 실행파일을 추출 후 virus total에 넣어보았고 악성이 존재함과 동시에 md5 해시를 찾을 수 있었다.
Q2.
What is the URL from which the file was downloaded?
해당 질문엔 google history, edge history를 확인해서 찾을 수 있지만 좀 더 빠르게 ADS의 일종인 zone identifier를 확인해서 찾았다.
FTK Imager에서 해당 악성파일을 클릭해보면 확인할 수 있다.
Zone Identifier을 확인해보면 정답을 알 수 있었다.
Q3.
What application did the user use to download this file?
Zone Identifier로 2번 답을 찾아 여기서 좀 애를 먹었다.
그러다 웹 브라우저의 히스토리 파일을 찾아보니 알 수 있었다.
AppData/Local/Microsoft/Edge/User Data/Default/History
그럼 해당 문제의 정답은 Microsoft Edge 인 것을 알 수 있다.
Q4.
By examining Windows Mail artifacts, we found an email address mentioning three IP addresses of servers that are at risk or compromised. What are the IP addresses?
https://boncaldoforensics.wordpress.com/2018/12/09/microsoft-hxstore-hxd-email-research/
Microsoft HxStore.hxd (email) Research
Possible additional Windows Live Mail message location? Up until Windows 10, you could find email-related files with the extension “.EML”. These files presented the opportunity for ema…
boncaldoforensics.wordpress.com
해당 블로그를 참고해서 문제를 풀 수 있었다.
\Appdata\Local\Packages\microsoft.windowscommunicationsapps_8wekyb3d8bbwe\LocalState\
위 경로에서 HxStore.hxd를 추출하고 Hxd를 열어 확인해주었다.
3개의 IP를 찾을 수 있다.
Q5.
By examining the malicious executable, we found that it uses an obfuscated PowerShell script to decrypt specific files. What predefined password does the script use for encryption?
이 문제가 요구하는 의도를 파악하는데 조금 시간이 걸렸다.
요약하면 아래와 같다.
- 악성파일 안에 난독화된 PowerShell 스크립트가 숨겨져 있다.
- 이때 암호화와 복호화에 사용되는 비밀번호가 있다.
그럼 문제를 풀어보면 strings를 통해 IMF-info.pdf.exe를 출력해주었고 powershell 스크립트가 있다고 하니 powershell을 검색해 찾아주었다.
디코딩을 시도해봤지만 잘 안되었고 코드를 좀 더 확인해보니 Reverse가 된 것을 확인할 수 있었다.
전체 코드는 아래와 같다.
$password = "Imf!nfo#2025Sec$"
$salt = [Byte[]](0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08)
$iterations = 10000
$keySize = 32
$ivSize = 16
$deriveBytes = New-Object System.Security.Cryptography.Rfc2898DeriveBytes($password, $salt, $iterations)
$key = $deriveBytes.GetBytes($keySize)
$iv = $deriveBytes.GetBytes($ivSize)
# List of input files
$inputFiles = @(
"C:\\Users\\ethan\\Desktop\\IMF-Secret.pdf",
"C:\\Users\\ethan\\Desktop\\IMF-Mission.pdf"
)
foreach ($inputFile in $inputFiles) {
$outputFile = $inputFile -replace '\.pdf$', '.enc'
$aes = [System.Security.Cryptography.Aes]::Create()
$aes.Key = $key
$aes.IV = $iv
$aes.Mode = [System.Security.Cryptography.CipherMode]::CBC
$aes.Padding = [System.Security.Cryptography.PaddingMode]::PKCS7
$encryptor = $aes.CreateEncryptor()
$plainBytes = [System.IO.File]::ReadAllBytes($inputFile)
$outStream = New-Object System.IO.FileStream($outputFile, [System.IO.FileMode]::Create)
$cryptoStream = New-Object System.Security.Cryptography.CryptoStream($outStream, $encryptor, [System.Security.Cryptography.CryptoStreamMode]::Write)
$cryptoStream.Write($plainBytes, 0, $plainBytes.Length)
$cryptoStream.FlushFinalBlock()
$cryptoStream.Close()
$outStream.Close()
Remove-Item $inputFile -Force
}
5번의 답은 password를 통해 알 수 있다.
Q6.
After identifying how the script works, decrypt the files and submit the secret string.
아마도 암호화된 파일을 복호화하고 확인해야 할 것 같다.
위 코드를 해석해보면 아래와 같다.
- 비밀번호와 암호화 매개변수로 AES 키와 IV를 생성
- 입력 PDF 파일 2개(IMF-Secret.pdf, IMF-Mission.pdf)를 암호화
- 암호화된 결과를 동일한 이름의 .enc 파일로 저장
- 원본 PDF 파일 삭제
즉 저 코드는 암호화된 코드이기 때문에 복호화 코드를 새로 짰다.
# --- 암호화/복호화에 사용할 주요 파라미터 설정 ---
$password = "Imf!nfo#2025Sec$" # 파일 암호화/복호화에 사용하는 하드코딩된 비밀번호
$salt = [Byte[]](0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08) # PBKDF2(SHA1 기반) 키 파생을 위한 salt, 고정)
$iterations = 10000 # 키 파생 함수 반복 횟수
$keySize = 32 # AES 키 길이(바이트). 32 = 256bit(AES-256)
$ivSize = 16 # AES 초기화 벡터 길이 CBC 모드에 필요(128bit)
# --- 키와 IV(초기화 벡터) 파생 ---
$deriveBytes = New-Object System.Security.Cryptography.Rfc2898DeriveBytes($password, $salt, $iterations)
# 위 비밀번호, salt, 반복횟수를 바탕으로 PBKDF2(Rfc2898) 알고리즘으로 키스트림 객체 생성
$key = $deriveBytes.GetBytes($keySize) # 실제 암호화/복호화에 쓸 AES Key(32바이트 추출)
$iv = $deriveBytes.GetBytes($ivSize) # AES CBC용 IV(16바이트 추출)
# --- 복호화할 대상 파일 목록 ---
$inputFiles = @(
"C:\\Users\\shxod\\Downloads\\enc\\IMF-Secret.enc", # 암호화된 .enc 파일 경로
"C:\\Users\\shxod\\Downloads\\enc\\IMF-Mission.enc"
)
# --- 각 암호화된 파일에 대해 복호화 수행 ---
foreach ($inputFile in $inputFiles) {
# .enc 확장자를 .decrypted.pdf로 바꾼 새 파일명 설정(복호화 결과 저장)
$outputFile = $inputFile -replace '\.enc$', '.decrypted.pdf'
# AES 객체 생성 및 파라미터 지정
$aes = [System.Security.Cryptography.Aes]::Create()
$aes.Key = $key
$aes.IV = $iv
$aes.Mode = [System.Security.Cryptography.CipherMode]::CBC # CBC 모드
$aes.Padding = [System.Security.Cryptography.PaddingMode]::PKCS7 # PKCS7 패딩 사용
# Decryptor 생성
$decryptor = $aes.CreateDecryptor()
# 암호화된 입력 파일을 바이트 배열로 전체 읽기
$cipherBytes = [System.IO.File]::ReadAllBytes($inputFile)
# 복호화용 스트림 생성: 암호화된 데이터를 복호화 필터에 입력
$inStream = New-Object System.IO.MemoryStream($cipherBytes, $false)
$cryptoStream = New-Object System.Security.Cryptography.CryptoStream(
$inStream, $decryptor, [System.Security.Cryptography.CryptoStreamMode]::Read
)
# 복호화 결과를 담을 버퍼를 선언
$buffer = New-Object byte[] ($cipherBytes.Length)
# 복호화 스트림에서 실제로 읽힌 바이트 수를 반환
$count = $cryptoStream.Read($buffer, 0, $buffer.Length)
# 실제 복호화된 PDF 데이터만 파일로 저장(.decrypted.pdf)
[System.IO.File]::WriteAllBytes($outputFile, $buffer[0..($count-1)])
# 스트림 닫기
$cryptoStream.Close()
$inStream.Close()
# 복호화 완료 메시지 출력
Write-Host "복호화 완료: $outputFile"
}
잘 복호화 되었고 내용엔 FLAG가 있음을 알 수 있었다.
'CTF > CyberDefenders' 카테고리의 다른 글
Cyberdefenders - KrakenKeylogger Lab (0) | 2025.05.07 |
---|---|
CorporateSecrets Lab (1) | 2025.04.21 |
Cyberdefenders - Szechuan Sauce Lab (0) | 2025.02.20 |
Sysinternals Lab (2) | 2024.11.15 |
SpottedInTheWild Lab (0) | 2024.11.10 |