Post

UnPackMe Lab - CyberDefenders

Introduction

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Instructions:

Uncompress the lab (pass: cyberdefenders.org)
Zip sha256: 4934714622f28589e48bfbab2f1a9b29c70eb16b
Zip size: 450 KB
Scenario:

Welcome to the cybersecurity team at CyberSolutions Inc. Recently, our threat intelligence network has uncovered a digital espionage effort targeting organizations worldwide. At the heart of this campaign is a sophisticated and hitherto unknown piece of malware, which we've codenamed "ShadowSteal." This malware is designed with advanced capabilities to infiltrate systems, evade detection, and exfiltrate sensitive information without leaving a trace.

"ShadowSteal" has been identified in a preliminary cybersecurity sweep and flagged due to its anomalous behavior patterns and the potential threat it poses to our operations and confidential data. Initial findings suggest that "ShadowSteal" is not just another piece of malware; it represents a significant threat due to its ability to steal a wide array of sensitive information. Additionally, "ShadowSteal" is designed to self-delete after completing its data exfiltration process, complicating post-incident analysis and forensics.

As a key member of our cybersecurity response team, your task is to analyze the "ShadowSteal" malware sample thoroughly. You must dissect its components, understand its operational mechanics, and uncover its functionalities. Your analysis will directly inform our defensive strategies, helping us to fortify our defenses, develop detection signatures, and ultimately neutralize the threat posed by "ShadowSteal."

Tools:

IDA
Ghidra
x64dbg

CyberDefenders: Blue team CTF Challenges | UnPackMe

Q1

Upon initiating your analysis of ShadowSteal, understanding its obfuscation techniques is critical. One tell-tale sign is the file’s entropy. Can you determine its value, which hints at whether the malware is packed?

PEStudio, DIE, hoặc bất cứ công cụ nào khác có thể phát hiện entropy.

1
7.389

Q2

Before ShadowSteal begins its data theft, it cleverly checks for a mutex to avoid duplicative data collection. This mutex includes a unique string combined with the computer’s name. What is the hardcoded string that ShadowSteal uses for this purpose?

Trước khi phân tích và trả lời các câu hỏi tiếp theo, để dễ dàng hãy tìm kiếm bản đã được unpack trên unpac.me

Chúng ta bắt đầu với hàm đầu tiên sub_432df7.

Pasted image 20241011100111

Trong quá trình phân tích, nhận thấy rằng mã độc thực hiện cùng một cơ chế làm xáo trộn, do đó mình đã viết đoạn python script ngắn để phục vụ mục đích giải quyết nhanh những đoạn bị làm rối này. Về cơ chế thì không quá khó. Lấy đoạn làm rối mutex làm ví dụ. Mã độc đầu tiên khởi tạo 2 chuỗi hex v5[0]v5[1] và để ý chút đến v6. Trong vòng lặp while, bắt đầu với byte thứ 2 (tức v5[0][1]=0xB8, chỗ này là Little-endian), từng byte sẽ được XOR với ~v1 (v1=0x32=0011 0010 => ~v1=1100 1101=0xCD). v2 ở đây là biến đếm, điều kiện thoát vòng lặp là v2>=9 tức có 9 byte sẽ được XOR, ở đây gồm 3 byte ở v5[0] (trừ byte đầu tiên (để ý byte đầu tiên cuối vòng lặp đầu tiên quay lại gán cho v1), 4 byte ở v5[1] và 2 byte còn lại ở v6 (recheck bằng cách quay ngược lên kiểm tra vị trí trong stack so với v5).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def little(value):
    return value.to_bytes(4, byteorder='little')

v5 = [0xACA4B832, 0xBABCABAF]
v6 = 0xB8AB
v1 = 0x32
tmp = bytearray()  

tmp.extend(little(v5[0]))
tmp.extend(little(v5[1]))
tmp.extend(little(v6))

count = 1 
while True:
    tmp[count] ^= ~v1 & 0xFF 
    count += 1
    if count > 9:
        break
    v1 = little(v5[0])[0]

mutex = ''.join(chr(tmp[i]) for i in range(1, len(tmp)))
print(mutex)
1
uiabfqwfu

Tương tự ở các spawn tiến trình explorer mới sub_435B8A, và các đoạn check nhỏ kiểm tra cài đặt ngôn ngữ mặc định và thoát khỏi chương trình nếu nó được đặt thành ngôn ngữ của các quốc gia CIS, bao gồm cả Nga.

Pasted image 20241011100510

Pasted image 20241011100824

Q3

ShadowSteal employs base64 and RC4 algorithms to safeguard the stolen data and its communication with the control server. Dive into its code to find the RC4 encryption key. What is it?

Pasted image 20241011101044

Tìm kiếm trong tab strings, mình bắt gặp một số chuỗi Base64 không thể đọc được khi giải mã, cho thấy rằng chúng đã được mã hóa. Dò theo xRef, ngay phía trên các đoạn này mình gặp phải một loại mã hóa XOR sử dụng giá trị từ xmmword_47D3E0, chứa 9498D7AB8CAEB2808B9A8E9DDCB4CA11 ở dạng thập lục phân. Đầu tiên, số 11 ở cuối giá trị này được thêm vào thanh ghi cl và sau đó bị xóa khỏi giá trị ban đầu. Tiếp theo, BC được thêm vào đầu giá trị, tạo thành BC9498D7AB8CAEB2808B9A8E9DDCB4CA. Sau đó, cl được đảo ngược (NOT) từ 11 thành EE và giá trị được sửa đổi được XOR với CAB4DC9D8E9A8B80B2AE8CABD79894BC, vì nó sử dụng định dạng little-endian. Kết quả mình có được key mã hóa RC4.

Pasted image 20241011101419

1
$Z2s`ten\@bE9vzR

Sử dụng key này để giải mã đoạn mã hóa đầu tiên. Tại thời điểm viết bài domain trên đã không còn tồn tại. Recheck với kết quả trên virustotal cũng sẽ cho ra domain tương tự.

Pasted image 20241011101727

Q4

In its data collection phase, ShadowSteal compiles a report which, among other things, reveals its version to the attacker. This detail is crucial for our threat intelligence. What version of ShadowSteal are you analyzing?

1
1.7.3

Q5

Part of ShadowSteal’s reconnaissance involves scanning for installed software, a task it accomplishes by querying a specific registry key. Identify the registry key it uses for this purpose.

Thời điểm này, có vẻ như tôi chỉ tìm được 2 đoạn mã hóa thú vị trên để chia sẻ, việc tìm kiếm các manh mối còn lại để trả lời có vẻ khá tốn sức. Do đó từ đâu tôi sử dụng các kết quả từ VirusTotal và từ kinh nghiệm của chính mình.

Pasted image 20241011114726

1
SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

Q6

ShadowSteal captures a screenshot of the current operating window as part of its information-gathering process. Which function address is responsible for this action?

Khi không biết phải bắt đầu từ đâu, việc quay lại tab strings có vẻ là một lựa chọn khả dĩ.

Pasted image 20241011114925

Pasted image 20241011115001

1
0042951b

Q7

Once ShadowSteal has fulfilled its mission, it removes all traces of its existence from the infected system. What command does it execute to delete itself?

Pasted image 20241011115911

1
cmd.exe /C timeout /T 10 /NOBREAK > Nul & Del /f /q

Q8

For a comprehensive threat analysis, knowing where ShadowSteal originates from is key. This includes the full path to its build folder on the attacker’s computer. Can you provide this path?

Sử dụng strings tìm kiếm với từ khóa build.

Pasted image 20241011120044

Tìm đến từ khóa này và thử show một chút về xRef Graph. Với việc import json.hpp, có vẻ JSON được sử dụng cho việc định dạng dữ liệu để gửi thông tin nạn nhân về C2.

Pasted image 20241011120247

1
A:\_Work\rc-build-v1-exe\
This post is licensed under CC BY 4.0 by the author.