Chương 3: Basic Dynamic Analysis

Tổng quan

Dynamic analysis là kỹ thuật phân tích malware bằng cách thực thi nó và quan sát hành vi thực tế, trái ngược với static analysis (chỉ đọc code mà không chạy).

Ưu điểm so với static analysis:

  • Quan sát được hành vi thực tế (không phải chỉ chuỗi string tồn tại trong binary mà là liệu nó có thực sự chạy không)
  • Nhanh hơn để xác định chức năng — ví dụ với keylogger: tìm ra log file ở đâu, ghi gì, gửi đi đâu

Hạn chế:

  • Không phải tất cả code path đều được thực thi (malware dạng command-line cần đúng argument mới kích hoạt đủ chức năng)

1. Sandbox — Phân tích nhanh

Sandbox là gì?

Các sandbox phổ biến: Norman SandBox, GFI Sandbox (CWSandbox), Anubis, Joe Sandbox, ThreatExpert, BitBlaze, Comodo Instant Malware Analysis.

GFI Sandbox Report — Cấu trúc

Một báo cáo GFI Sandbox điển hình gồm 6 sections:

SectionNội dung
Analysis SummaryThông tin static + tổng quan kết quả dynamic
File ActivityCác file được mở/tạo/xóa bởi từng process
Created MutexesMutex do malware tạo ra
Registry ActivityThay đổi trong registry
Network ActivityHoạt động mạng: listening port, DNS request
VirusTotal ResultsKết quả scan VirusTotal

Hạn chế của Sandbox


2. Chạy Malware

EXE

Đơn giản: double-click hoặc chạy từ command line.

DLL — Dùng rundll32.exe

Windows không tự chạy DLL, cần dùng rundll32.exe:

rundll32.exe DLLname, Export [arguments]

Ví dụ:

rundll32.exe rip.dll, Install

Gọi bằng ordinal (nếu không có tên export):

rundll32.exe xyzzy.dll, #5

Chuyển DLL thành EXE (cách khác):

Xóa flag IMAGE_FILE_DLL (0x2000) trong Characteristics của IMAGE_FILE_HEADER. Điều này sẽ trigger DLLMain nhưng không gọi imported functions — malware có thể crash nhưng vẫn đủ để thu thập thông tin.

DLL cần cài làm service:

rundll32.exe ipr32x.dll, InstallService ServiceName
net start ServiceName

3. Process Monitor (Procmon)

Giới thiệu

Procmon là công cụ monitor nâng cao, theo dõi: registry, file system, network, process, thread activity. Kế thừa từ FileMonRegMon.

Sử dụng Procmon

1. Mở Procmon → Edit → Clear Display (xóa events cũ)
2. Chạy malware
3. Sau vài phút → File → Capture Events (dừng capture)

Procmon Display

Các cột quan trọng:

CộtÝ nghĩa
SequenceSố thứ tự event
TimeTimestamp
Process NameTên process gây event
OperationLoại thao tác (CreateFile, RegSetValue,…)
PathĐường dẫn
ResultSUCCESS / NAME NOT FOUND / …

Filtering trong Procmon

Cách đặt filter: Filter → Filter → chọn Column → chọn Comparator (is/contains/less than) → Include/Exclude

4 quick-filter buttons trên toolbar:

🗂️ Registry    — xem malware cài persistence thế nào
📁 File System  — xem file nào được tạo/dùng
⚙️ Process      — xem malware spawn process nào
🌐 Network      — xem port nào đang listen

Ví dụ thực tế: Với mm32.exe, filter Process Name = mm32.exe + Operation = RegSetValue → từ 39,351 events còn 11 events → phát hiện malware ghi persistence tại: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\Sys32V2Controller


4. Process Explorer

Giới thiệu

Process Explorer (Sysinternals/Microsoft) là task manager cực mạnh, hiển thị process theo dạng cây cha-con.

Chức năng chính:

  • List active processes, DLLs loaded, process properties, system info
  • Kill process, launch/validate processes, log out users

Display

Màu sắc mặc định:

MàuÝ nghĩa
🩷 PinkServices
🔵 BlueNormal processes
🟢 Green (tạm thời)Process mới khởi động
🔴 Red (tạm thời)Process vừa terminate

Cửa sổ Properties (double-click vào process):

  • Threads tab — active threads
  • TCP/IP tab — active connections / listening ports
  • Image tab — đường dẫn đến file executable trên disk
  • Strings tab — so sánh strings trên disk vs trong memory
  • Handles tab — file handles, mutexes, events,…

Verify Option

So sánh Strings — Phát hiện Process Replacement

Trong Strings tab của Process Properties:

Image (on disk)  ←→  Memory (running)

Nếu hai danh sách khác nhau nhiều → có thể xảy ra process replacement.

Ví dụ: svchost.exe được Verify pass nhưng trong memory có string FAVORITES.DAT không tồn tại trong file trên disk → đây là malware giả dạng svchost.

Dependency Walker (depends.exe)

Từ Process Explorer: chuột phải → Launch Depends → xem DLL dependencies của process đang chạy.

Find DLL option: Tìm xem process nào đang load một DLL malicious cụ thể.

Phân tích Malicious Documents

Mở Process Explorer → mở document nghi ngờ (PDF, Word) → nếu document spawn process → thấy ngay trong Process Explorer → locate malware qua Image tab.


5. Regshot — So sánh Registry Snapshot

Giới thiệu

Regshot là công cụ open-source so sánh 2 registry snapshots.

Quy trình:

1st Shot → [Chạy malware] → 2nd Shot → Compare

Đọc kết quả Regshot

Keys added: 0
Values added: 3
  HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\ckr: C:\WINDOWS\system32\ckr.exe
Values modified: 2
  HKLM\SOFTWARE\Microsoft\Cryptography\RNG\Seed: [hex data]
Total changes: 5

6. Faking a Network — Mô phỏng mạng

Malware thường beacon ra ngoài và liên lạc với C2 server. Mục tiêu: thu thập network indicators (DNS names, IP, packet signatures) mà không cần kết nối Internet thật.

ApateDNS

ApateDNS spoof DNS responses, redirect mọi DNS query về một IP do analyst chỉ định.

Hoạt động: listen trên UDP port 53 → trả về IP bạn cấu hình

Sử dụng:

1. Nhập IP muốn redirect đến
2. Chọn network interface
3. Start Server → DNS tự động chuyển về localhost
4. Chạy malware → xem DNS requests xuất hiện

NXDOMAIN option: Trả về “không tồn tại” cho domain đầu tiên → malware sẽ thử domain tiếp theo → lộ ra thêm domain trong config của nó.

Netcat

Netcat — “TCP/IP Swiss Army knife”, dùng làm fake server để bắt kết nối từ malware.

nc -l -p 80

-l = listen mode, -p = port

Ví dụ thực tế với RShell:

ApateDNS redirect evil.malwar3.com → 127.0.0.1
Netcat lắng nghe port 80
→ RShell kết nối, gửi HTTP POST fake tới www.google.com để ngụy trang
→ Sau đó cung cấp reverse shell

Wireshark

Wireshark — open-source packet sniffer, capture và phân tích toàn bộ network traffic.

4 phần giao diện:

PhầnChức năng
Filter boxLọc packets hiển thị
Packet listingDanh sách packets thỏa filter
Packet detailNội dung packet được chọn
Hex windowHex dump của packet (liên kết với detail)

Follow TCP Stream: Chuột phải vào TCP packet → Follow TCP Stream → xem toàn bộ cuộc hội thoại 2 chiều.

INetSim

INetSim — Linux-based suite mô phỏng toàn bộ Internet services, là công cụ tốt nhất để cung cấp fake services.

Services mặc định được emulate:

dns     53/udp+tcp
http    80/tcp
https   443/tcp
smtp    25/tcp
ftp     21/tcp
pop3    110/tcp
irc     6667/tcp
ntp     123/udp
...và nhiều hơn

Tính năng nổi bật:

  • Trả về đúng format file được yêu cầu (malware hỏi JPEG → trả JPEG → malware tiếp tục chạy)
  • Record toàn bộ inbound requests
  • Cấu hình được response cụ thể (nếu malware cần web page X mới tiếp tục)
  • Dummy service: log tất cả data từ client bất kể port → bắt được mọi kết nối

7. Tổng hợp — Setup phân tích thực tế

Sơ đồ Virtual Network

graph LR A[Windows VM\nMalware Analysis\n192.168.117.170\nDNS: 127.0.0.1] -- DNS request --> B[ApateDNS\nport 53\nlocalhost] B -- redirect --> C[Linux VM\nINetSim\n192.168.117.169] A -- HTTP GET port 80 --> C C -- fake response --> A

Quy trình chuẩn

1. Chạy procmon → set filter theo tên malware → clear events
2. Mở Process Explorer
3. Regshot → 1st Shot
4. Cấu hình INetSim + ApateDNS
5. Bật Wireshark
6. Chạy malware
7. Sau vài phút: dừng procmon capture, Regshot 2nd Shot → Compare

Case Study: msts.exe


Câu hỏi ôn tập