> For the complete documentation index, see [llms.txt](https://book.loliteam.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.loliteam.net/forensic-ctf-co-ban-va-thuc-te.md).

# Forensic CTF Cơ Bản Và Thực Tế

CẨM NANG FORENSICS CTF TOÀN TẬP

## Book này dành cho CTFer Forensic

Forensics CTF không bắt đầu bằng việc chạy thật nhiều công cụ. Nó bắt đầu bằng một câu hỏi đúng: dữ liệu trước mắt thực sự là gì, chi tiết nào đáng chú ý và phép kiểm tra nào có thể giúp mình đi tiếp? Cuốn cẩm nang này dẫn bạn từ những thao tác đầu tiên với một file lạ đến các bài phân tích PCAP, disk image, browser artifact và memory image phức tạp hơn.

*Tác giả: Shiina*

<figure><img src="https://1680260334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fuyv6WKxbnPSm2zlRacJi%2Fuploads%2FwGf5cFJuZA9Sz8tU0KDN%2Fimage.png?alt=media&amp;token=ba1644ff-3afc-4bb7-ba48-aed5bc940581" alt=""><figcaption></figcaption></figure>

### Giới thiệu

Blog này được biên soạn nhằm mang lại cách tiếp cận thân thiện cho những người mới bước chân vào mảng CTF Forensic, đồng thời đóng vai trò như một tài liệu tra cứu nhanh tương tự cuốn cẩm nang <mark style="color:$primary;">HackTricks</mark>. Hy vọng rằng đây sẽ là bước đệm vững chắc cho những người mới bắt đầu, cũng như một công cụ hỗ trợ đắc lực cho các người chơi dày dặn kinh nghiệm.

Nội dung được trình bày theo một nhịp thống nhất: đọc đề → quan sát → tìm dấu hiệu → đặt giả thuyết → kiểm tra → đối chiếu bằng chứng → tìm flag. Các ví dụ ưu tiên Kali Linux và chỉ sử dụng dữ liệu thực hành được cấp hợp pháp.

## Mục lục <a href="#muc-luc" id="muc-luc"></a>

1. [Cách dùng cẩm nang](#id-1-cach-dung-cam-nang)
2. [Tư duy Forensics CTF](#id-2-tu-duy-forensics-ctf)
3. [Chuẩn bị môi trường và tệp tải](#id-3-chuan-bi-moi-truong-va-tep-tai)
4. [Quy trình phân tích chuẩn](#id-4-quy-trinh-phan-tich-chuan)
5. [Encoding, Encryption và dữ liệu dạng chuỗi](#id-5-encoding-encryption-va-du-lieu-dang-chuoi)
6. [Nhận dạng và phân tích tệp](#id-6-nhan-dang-va-phan-tich-tep)
7. [Metadata, carving và polyglot](#id-7-metadata-carving-va-polyglot)
8. [Steganography trong ảnh và âm thanh](#id-8-steganography-trong-anh-va-am-thanh)
9. [Archive, tài liệu Office, PDF, email và database](#id-9-archive-tai-lieu-office-pdf-email-va-database)
10. [Network Forensics với PCAP](#id-10-network-forensics-voi-pcap)
11. [Log, Windows Registry và Windows artifacts](#id-11-log-windows-registry-va-windows-artifacts)
12. [Linux artifacts](#id-12-linux-artifacts)
13. [Browser và Internet artifacts](#id-13-browser-va-internet-artifacts)
14. [Disk và File System Forensics](#id-141-disk-image-la-gi)
15. [Memory Forensics chuyên sâu](#id-15-memory-forensics-chuyen-sau)
16. [Executable và Malware Analysis nhập môn](#id-16-executable-va-malware-analysis-nhap-mon)
17. [Thu thập dữ liệu từ máy nghi nhiễm](#id-17-thu-thap-du-lieu-tu-may-nghi-nhiem)
18. [Cloud, SIEM và OSINT](#id-18-cloud-siem-va-osint)
19. [Từ một file lạ đến một cuộc điều tra hoàn chỉnh](#id-19-tu-mot-file-la-den-mot-cuoc-dieu-tra-hoan-chinh)
20. [Thực hành có hướng dẫn](#id-20-thuc-hanh-co-huong-dan)
21. [Bài tập từ cơ bản đến nâng cao](#id-21-bai-tap-tu-co-ban-den-nang-cao)
22. [Cách viết lời giải và báo cáo](#id-22-cach-viet-loi-giai-va-bao-cao)
23. [Bảng lệnh tra cứu nhanh](#id-23-bang-lenh-tra-cuu-nhanh)
24. [Thuật ngữ](#id-24-thuat-ngu)
25. [Tài liệu tham khảo](#id-25-tai-lieu-tham-khao)

***

## 1. Cách dùng cẩm nang <a href="#id-1-cach-dung-cam-nang" id="id-1-cach-dung-cam-nang"></a>

Không cần đọc tuần tự toàn bộ tài liệu trước khi làm bài. Hãy bắt đầu từ loại dữ liệu được cấp:

| Dữ liệu nhận được              | Đọc trước      | Công cụ mở đầu                                         |
| ------------------------------ | -------------- | ------------------------------------------------------ |
| File không rõ loại hoặc mở lỗi | Chương 4, 6, 7 | `sha256sum`, `file`, `xxd`, `strings`, `exiftool`      |
| Ảnh nghi giấu dữ liệu          | Chương 7, 8    | `exiftool`, `pngcheck`, `binwalk`, `zsteg`, `steghide` |
| PCAP/PCAPNG                    | Chương 10      | Wireshark, `tshark`                                    |
| EVTX, JSONL hoặc log text      | Chương 11, 12  | Event Viewer, `jq`, `grep`, Chainsaw                   |
| Disk image                     | Chương 14      | `mmls`, `fls`, `icat`, Autopsy                         |
| Memory image                   | Chương 15      | Volatility 3, MemProcFS, YARA                          |
| DOCX/XLSX/PPTX/PDF/EML         | Chương 9       | `7z`, `olevba`, `pdfinfo`, `ripmime`                   |
| EXE/DLL/ELF/script             | Chương 16      | `file`, `strings`, FLOSS, Detect It Easy, Ghidra       |
| Browser database/cache         | Chương 13      | `sqlite3`, DB Browser for SQLite, Hindsight            |
| Dữ liệu cloud/SIEM             | Chương 18      | CLI của nền tảng, Splunk, Elastic                      |

### 1.1 Ba cách đọc <a href="#id-11-ba-cach-doc" id="id-11-ba-cach-doc"></a>

**Đọc để học từ đầu:** đi lần lượt từ Chương 2, thực hiện các bài mẫu ở Chương 20 khi gặp đúng loại dữ liệu, sau đó dùng Chương 21 để tự luyện.

**Đọc khi đang thi:** xác định loại artifact, tra đúng chương, chạy một phép thử có mục tiêu rồi quay lại quy trình chuẩn ở Chương 4.

**Đọc để thực hành:** chọn đúng bộ file ở Chương 20, làm theo từng bước rồi chuyển sang các bài không có lời dẫn chi tiết ở Chương 21.

### 1.2 Câu hỏi quan trọng hơn tên công cụ <a href="#id-12-cau-hoi-quan-trong-hon-ten-cong-cu" id="id-12-cau-hoi-quan-trong-hon-ten-cong-cu"></a>

Một lệnh chỉ có ý nghĩa khi nó trả lời một câu hỏi cụ thể:

* `file` trả lời: “Cấu trúc đầu tệp giống định dạng nào?”
* `exiftool` trả lời: “Metadata nào được lưu trong tệp?”
* `binwalk` trả lời: “Trong tệp có chữ ký của dữ liệu nhúng ở offset nào?”
* `tshark -Y ...` trả lời: “Những packet nào thỏa điều kiện đang kiểm tra?”
* `fls -d` trả lời: “Filesystem còn ghi nhận entry đã xóa nào?”
* `windows.pstree` trả lời: “Quan hệ cha–con giữa các process là gì?”

Nếu chưa nói được câu hỏi, đừng chạy thêm tool chỉ để tạo nhiều output.

***

## 2. Tư duy Forensics CTF <a href="#id-2-tu-duy-forensics-ctf" id="id-2-tu-duy-forensics-ctf"></a>

### 2.1 Forensics CTF khác DFIR thực tế <a href="#id-21-forensics-ctf-khac-dfir-thuc-te" id="id-21-forensics-ctf-khac-dfir-thuc-te"></a>

**Digital Forensics and Incident Response (DFIR)** là điều tra số và ứng cứu sự cố. Trong công việc thực tế, người phân tích phải quan tâm phạm vi pháp lý, quy trình thu thập, chain of custody, tính toàn vẹn, dữ liệu cá nhân, mức độ tin cậy và tác động vận hành.

Forensics CTF mượn kỹ thuật của DFIR nhưng dữ liệu được tác giả thiết kế có chủ đích. Thường sẽ có một đường giải hợp lý, một chuỗi dấu hiệu đủ để đi tiếp và một flag xác nhận kết quả. Vì vậy:

* vẫn phải giữ bản gốc và ghi hash;
* vẫn phải dựa vào dữ liệu thay vì đoán;
* nhưng mục tiêu là giải thích đường từ artifact đến flag, không phải kết luận trách nhiệm pháp lý hay khôi phục toàn bộ sự cố.

### 2.2 Artifact, clue, decoy và evidence <a href="#id-22-artifact-clue-decoy-va-evidence" id="id-22-artifact-clue-decoy-va-evidence"></a>

* **Artifact:** vật liệu số được giao để phân tích, chẳng hạn ảnh, PCAP, log, disk image hoặc memory image.
* **Clue:** dấu hiệu có liên quan đến câu chuyện và dẫn tới một phép thử có thể kiểm chứng.
* **Decoy:** dữ liệu đánh lạc hướng được đặt có chủ đích. Decoy có thể trông giống flag hoặc giống hoạt động độc hại.
* **Evidence:** kết quả có nguồn rõ ràng, lặp lại được và đủ sức hỗ trợ hoặc bác bỏ một giả thuyết.

Ví dụ: đề cho `holiday.jpg`, nhưng `file` nhận ra ZIP và bốn byte đầu là `50 4b 03 04`.

* Tên `.jpg` là nhãn.
* Chữ ký `PK` là clue.
* Giả thuyết: file thực sự là ZIP bị đổi tên.
* `7z l holiday.jpg` là phép kiểm chứng.
* Danh sách entry hợp lệ của archive là evidence.

### 2.3 Đừng săn flag ngay từ đầu <a href="#id-23-dung-san-flag-ngay-tu-dau" id="id-23-dung-san-flag-ngay-tu-dau"></a>

`strings artifact | grep -i flag` có thể hữu ích, nhưng kết quả tìm thấy chưa chắc là đáp án. Một chuỗi `FLAG{...}` có thể nằm trong tài liệu hướng dẫn, history, decoy hoặc vùng byte không thuộc intended solve.

Flag đáng tin khi:

1. đến từ đúng artifact hoặc lớp dữ liệu mà chuỗi dấu hiệu dẫn tới;
2. được trích bằng thao tác có thể lặp lại;
3. khớp ngữ cảnh và định dạng đề;
4. không cần sửa, đoán hoặc fuzzy match;
5. có thể giải thích vì sao chọn nó và loại các ứng viên khác.

### 2.4 Baseline và thay đổi một yếu tố <a href="#id-24-baseline-va-thay-doi-mot-yeu-to" id="id-24-baseline-va-thay-doi-mot-yeu-to"></a>

**Baseline** là kết quả gốc dùng để so sánh. Khi thử một giả thuyết, chỉ đổi một yếu tố mỗi lần:

* packet gốc → thêm một display filter;
* danh sách process → chỉ nhìn một PID;
* ảnh gốc → tách riêng một channel;
* log đầy đủ → lọc một provider và một Event ID;
* archive → liệt kê trước, trích sau.

Cách này giúp biết chính xác thay đổi nào tạo ra thông tin mới.

### 2.5 False positive và cách giảm <a href="#id-25-false-positive-va-cach-giam" id="id-25-false-positive-va-cach-giam"></a>

**False positive** là kết luận “có vấn đề” trong khi dữ liệu chưa đủ chứng minh. Những lỗi phổ biến:

* thấy PowerShell rồi kết luận malware;
* thấy vùng nhớ có quyền thực thi rồi kết luận process injection;
* thấy chuỗi `PK` rồi kết luận có ZIP hợp lệ;
* thấy entropy cao rồi kết luận encrypted;
* thấy IP nói nhiều nhất rồi kết luận đó là attacker;
* thấy một hash trên Internet bị gắn nhãn xấu rồi bỏ qua ngữ cảnh của chính artifact.

Cách giảm false positive:

1. kiểm tra nguồn của dữ kiện;
2. tìm ít nhất hai tín hiệu độc lập khi kết luận quan trọng;
3. dùng parser phù hợp để xác nhận cấu trúc;
4. so thời gian, PID, path, session ID, hash hoặc sequence;
5. ghi rõ điều đã biết, điều suy ra và điều chưa biết.

***

## 3. Chuẩn bị môi trường và tệp tải <a href="#id-3-chuan-bi-moi-truong-va-tep-tai" id="id-3-chuan-bi-moi-truong-va-tep-tai"></a>

### 3.1 Máy ảo Kali Linux <a href="#id-31-may-ao-kali-linux" id="id-31-may-ao-kali-linux"></a>

Cấu hình khuyến nghị cho bộ bài nhỏ:

* 2 vCPU;
* 4 GB RAM;
* 40 GB virtual disk;
* tối thiểu 15 GB dung lượng trống trên máy host;
* snapshot sạch sau khi cài tool.

Nếu máy yếu, có thể dùng 2 GB RAM và đóng các ứng dụng không cần thiết. Memory dump thật có thể cần nhiều RAM và disk hơn đáng kể.

Chỉ tải Kali từ trang chính thức và kiểm SHA-256. Với dữ liệu nghi ngờ, không bật shared clipboard, shared folder hoặc network bridge nếu không cần.

### 3.2 Cài bộ công cụ tối thiểu <a href="#id-32-cai-bo-cong-cu-toi-thieu" id="id-32-cai-bo-cong-cu-toi-thieu"></a>

```bash
sudo apt update
sudo apt install -y file xxd binutils 7zip unzip libimage-exiftool-perl \
  binwalk pngcheck wireshark tshark sleuthkit jq python3 ruby-full \
  sqlite3 ripmime libxml2-utils foremost testdisk
sudo gem install zsteg
```

`kali-tools-forensics` là metapackage lớn. Chỉ cài khi cần máy chuyên dụng lâu dài:

```bash
sudo apt install kali-tools-forensics
```

Kiểm tra nhanh:

```bash
command -v file xxd strings 7z exiftool binwalk pngcheck \
  tshark mmls fls icat jq sqlite3 ripmime xmllint zsteg
```

### 3.3 Cài Volatility 3 trong virtual environment <a href="#id-33-cai-volatility-3-trong-virtual-environment" id="id-33-cai-volatility-3-trong-virtual-environment"></a>

```bash
python3 -m venv ~/.venv-volatility
source ~/.venv-volatility/bin/activate
python -m pip install --upgrade pip volatility3
vol -h
```

Nếu dùng bản source có `vol.py`, cú pháp thường là:

```bash
python3 vol.py -f memory.raw windows.info
```

Nếu package tạo lệnh `vol`, dùng:

```bash
vol -f memory.raw windows.info
```

Luôn chạy `vol windows.PLUGIN --help` hoặc `python3 vol.py windows.PLUGIN --help` trước khi thực hành vì option có thể khác theo phiên bản.

### 3.4 Danh sách file tải — thay URL sau <a href="#id-34-danh-sach-file-tai-thay-url-sau" id="id-34-danh-sach-file-tai-thay-url-sau"></a>

Các placeholder dưới đây được cố ý để trống. Thay toàn bộ chuỗi trong ngoặc nhọn bằng URL phát hành chính thức.

| Gói                                  | Mục đích                             | Liên kết                                                                                                        |
| ------------------------------------ | ------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
| `FORENSICS_INTRO_LAB.zip`            | 12 tệp làm quen, không có flag       | [Tải bộ làm quen](https://drive.google.com/file/d/1zuesGvNTYTVs49FdyOLHc4xlxQCWErMz/view?usp=sharing)           |
| `FORENSICS_SESSION02_DEMO.zip`       | PCAP, disk, log và memory output mẫu | [Tải bộ phân tích hệ thống](https://drive.google.com/file/d/1ihhB7AKwLnF01ktCrNZqod-VzYRIxzzE/view?usp=sharing) |
| `FORENSICS_SESSION03_MEMORY_LAB.zip` | Bài thực hành Memory Forensics       | [Tải bộ Memory Forensics](https://drive.google.com/file/d/1dOijnhU75nHt_HR5eqNRfWYyRq_phVa7/view?usp=sharing)   |
| `FORENSICS_CTF_STUDENT_v1.0.zip`     | Bộ 21 bài thực hành                  | [Tải bộ CTF](https://drive.google.com/file/d/1xcoRgJi2n447kel0p6pBHRnrCx_uLoBR/view?usp=sharing)                |
| `check-workstation.sh`               | Kiểm tra các công cụ cần thiết       | [Tải script kiểm tra](https://drive.google.com/file/d/1-qsZBRQxsZtf8Ryb3s8wXqFdcBCwkFJh/view?usp=sharing)       |

Sau khi chèn URL, nên công bố kèm SHA-256:

```bash
sha256sum FORENSICS_INTRO_LAB.zip
sha256sum FORENSICS_SESSION02_DEMO.zip
sha256sum FORENSICS_SESSION03_MEMORY_LAB.zip
sha256sum FORENSICS_CTF_STUDENT_v1.0.zip
```

### 3.5 Quy tắc an toàn trước khi mở file <a href="#id-35-quy-tac-an-toan-truoc-khi-mo-file" id="id-35-quy-tac-an-toan-truoc-khi-mo-file"></a>

1. Giữ archive tải về trong thư mục chỉ đọc hoặc thư mục `original`.
2. Tính hash trước khi giải nén.
3. Dùng `7z l` để xem danh sách entry trước `7z x`.
4. Kiểm tra path lạ như `../../`, symlink hoặc tên tuyệt đối.
5. Không mở executable bằng double-click.
6. Không upload memory image thật lên dịch vụ công khai vì có thể chứa token và dữ liệu cá nhân.
7. Dùng snapshot để quay lại trạng thái sạch.

***

## 4. Quy trình phân tích chuẩn <a href="#id-4-quy-trinh-phan-tich-chuan" id="id-4-quy-trinh-phan-tich-chuan"></a>

### 4.1 Tạo workspace <a href="#id-41-tao-workspace" id="id-41-tao-workspace"></a>

```bash
mkdir -p ~/forensics-lab/{original,working,output,notes}
cp TEN_FILE ~/forensics-lab/original/
cp TEN_FILE ~/forensics-lab/working/
cd ~/forensics-lab
sha256sum original/TEN_FILE | tee notes/initial-sha256.txt
```

Ý nghĩa:

* `original`: giữ nguyên byte tải về;
* `working`: bản sao dùng để repair, carve hoặc extract;
* `output`: file mới sinh ra;
* `notes`: lệnh, hash và nhận xét.

### 4.2 First Five Minutes <a href="#id-42-first-five-minutes" id="id-42-first-five-minutes"></a>

Chạy từ phép thử rẻ đến đắt:

```bash
file working/TEN_FILE
stat working/TEN_FILE
xxd -l 64 working/TEN_FILE
strings -a -n 6 working/TEN_FILE | head -n 40
exiftool working/TEN_FILE
7z l working/TEN_FILE
binwalk working/TEN_FILE
```

Không phải file nào cũng cần đủ bảy lệnh. Dừng khi đã có bằng chứng đủ để chọn nhánh tiếp theo.

### 4.3 Phiếu suy luận <a href="#id-43-phieu-suy-luan" id="id-43-phieu-suy-luan"></a>

| Thời điểm | Quan sát               | Giả thuyết           | Phép kiểm tra | Kết quả              | Quyết định                     |
| --------- | ---------------------- | -------------------- | ------------- | -------------------- | ------------------------------ |
| 09:10     | `.jpg`, header `PK`    | ZIP đổi tên          | `7z l`        | Có 2 entry hợp lệ    | Bỏ nhánh phân tích JPEG        |
| 09:14     | `Comment` giống Base64 | Comment chứa chỉ dẫn | `base64 -d`   | Chuỗi UTF-8 rõ nghĩa | Làm theo chỉ dẫn và lưu output |

Một ghi chú tốt nêu cả lý do. “Chạy binwalk” không phải suy luận; “dung lượng lớn bất thường và parser ảnh kết thúc sớm nên kiểm dữ liệu nối sau EOF bằng binwalk” mới là suy luận.

### 4.4 Vòng lặp sau mỗi lần extract <a href="#id-44-vong-lap-sau-moi-lan-extract" id="id-44-vong-lap-sau-moi-lan-extract"></a>

Mỗi file mới là một artifact mới:

```bash
file output/new-file
sha256sum output/new-file
xxd -l 32 output/new-file
strings -a -n 6 output/new-file | head
```

Không đoán lớp cuối từ lớp đầu. PCAP có thể dẫn tới ảnh; ảnh dẫn tới ZIP; ZIP dẫn tới Base64; output Base64 mới chứa thông tin cần tìm.

### 4.5 Khi nào nên dùng script <a href="#id-45-khi-nao-nen-dung-script" id="id-45-khi-nao-nen-dung-script"></a>

Dùng Python khi cần:

* sắp xếp hàng trăm fragment theo sequence;
* kiểm duplicate hoặc missing sequence;
* parse cấu trúc lặp lại;
* trích LSB theo channel cụ thể;
* chuyển timestamp hàng loạt;
* join nhiều nguồn qua key;
* tạo thao tác có thể chạy lại.

Đừng viết script dài khi một parser chuẩn đã trả lời chính xác. Script tự viết làm tăng nguy cơ hiểu sai format.

### 4.6 Timebox khi thi <a href="#id-46-timebox-khi-thi" id="id-46-timebox-khi-thi"></a>

* 5 phút đầu: đọc đề, hash, nhận dạng.
* Sau 15–20 phút không có evidence mới: dừng và xem lại assumption.
* Trước khi xin hint: ghi một câu “đã biết gì” và “đang thiếu gì”.
* Trước khi nộp: loại newline, chỉ trim khoảng trắng hai đầu, không tự sửa ký tự ở giữa.

***

## 5. Encoding, Encryption và dữ liệu dạng chuỗi <a href="#id-5-encoding-encryption-va-du-lieu-dang-chuoi" id="id-5-encoding-encryption-va-du-lieu-dang-chuoi"></a>

### 5.1 Encoding không phải Encryption <a href="#id-51-encoding-khong-phai-encryption" id="id-51-encoding-khong-phai-encryption"></a>

* **Encoding:** đổi cách biểu diễn để dữ liệu phù hợp kênh truyền hoặc định dạng. Không cần secret key để đảo.
* **Encryption:** biến plaintext thành ciphertext bằng thuật toán và key nhằm bảo mật.
* **Hashing:** ánh xạ một chiều thành digest, thường dùng kiểm toàn vẹn hoặc so khớp.
* **Compression:** giảm kích thước hoặc đóng gói dữ liệu; entropy cao không tự chứng minh encryption.

### 5.2 Nhận dạng các encoding thường gặp <a href="#id-52-nhan-dang-cac-encoding-thuong-gap" id="id-52-nhan-dang-cac-encoding-thuong-gap"></a>

| Kiểu            | Dấu hiệu                              | Ví dụ                |
| --------------- | ------------------------------------- | -------------------- |
| Base64          | `A-Z a-z 0-9 + /`, thường có `=` cuối | `aGVsbG8=`           |
| Base64 URL-safe | dùng `-` và `_` thay `+` và `/`       | JWT segment          |
| Hexadecimal     | chỉ `0-9a-f`, thường có độ dài chẵn   | `68656c6c6f`         |
| URL encoding    | nhiều `%NN`, `+` có thể là space      | `hello%20world`      |
| Binary          | nhóm `0` và `1`                       | `01000001`           |
| Decimal ASCII   | dãy số 0–255                          | `72 101 108 108 111` |
| ROT13           | chữ cái đổi theo vòng 13              | `synt` → `flag`      |
| Unicode escape  | `\uNNNN`                              | `\u0041`             |

### 5.3 Lệnh decode cơ bản <a href="#id-53-lenh-decode-co-ban" id="id-53-lenh-decode-co-ban"></a>

```bash
printf '%s' 'aGVsbG8=' | base64 -d; echo
printf '%s' '68656c6c6f' | xxd -r -p; echo
printf '%s' 'synt' | tr 'A-Za-z' 'N-ZA-Mn-za-m'; echo
python3 -c "import urllib.parse; print(urllib.parse.unquote('hello%20world'))"
python3 -c "print(bytes([72,101,108,108,111]).decode())"
```

![Ví dụ decode dữ liệu ngay trên Linux](https://user-images.githubusercontent.com/50979196/229380187-b3c34620-e19a-470f-a13f-f8c1d8eeb253.png)

Sau decode phải kiểm output:

```bash
file decoded.bin
xxd -l 32 decoded.bin
strings -a -n 6 decoded.bin | head
```

Nếu output tiếp tục giống Base64, có thể có nhiều lớp. Ghi lại từng lớp thay vì bấm “Magic” rồi không giải thích được.

### 5.4 CyberChef và dCode <a href="#id-54-cyberchef-va-dcode" id="id-54-cyberchef-va-dcode"></a>

* CyberChef phù hợp xây recipe có thể nhìn thấy từng bước: From Base64, Gunzip, XOR, URL Decode…
* dCode hữu ích với cipher cổ điển, puzzle và nhận dạng encoding.
* Không đưa dữ liệu nhạy cảm hoặc artifact thật lên bản web công khai. Khi cần, dùng CyberChef offline.

CyberChef: <https://gchq.github.io/CyberChef/>

dCode: <https://www.dcode.fr/en>

### 5.5 XOR <a href="#id-55-xor" id="id-55-xor"></a>

XOR có tính đảo ngược:

```
plaintext XOR key = ciphertext
ciphertext XOR key = plaintext
```

Ví dụ `A = 0x41`, `K = 0x4b`:

```
0x41 XOR 0x4b = 0x0a
0x0a XOR 0x4b = 0x41
```

Python cho single-byte XOR:

```python
data = bytes.fromhex("0a0e1f")
key = 0x4B
plain = bytes(b ^ key for b in data)
print(plain)
```

Với repeating-key XOR, dùng vị trí modulo chiều dài key. Không kết luận XOR chỉ vì byte nhìn ngẫu nhiên; cần clue về key, known plaintext hoặc pattern có thể kiểm chứng.

### 5.6 Symmetric và Asymmetric Encryption <a href="#id-56-symmetric-va-asymmetric-encryption" id="id-56-symmetric-va-asymmetric-encryption"></a>

* **Symmetric encryption:** cùng một secret key dùng để encrypt và decrypt. Ví dụ AES, ChaCha20.
* **Asymmetric encryption:** dùng cặp public key/private key. Ví dụ RSA, ECC.

Các thuật toán cũ như DES không còn phù hợp để bảo vệ dữ liệu hiện đại. Trong CTF, chúng có thể xuất hiện vì mục tiêu học tập.

### 5.7 OpenSSL cơ bản <a href="#id-57-openssl-co-ban" id="id-57-openssl-co-ban"></a>

Xem certificate:

```bash
openssl x509 -in certificate.pem -text -noout
```

Xem public key:

```bash
openssl pkey -pubin -in public.pem -text -noout
```

Giải mã RSA chỉ khi có private key hợp lệ và padding đúng:

```bash
openssl pkeyutl -decrypt -inkey private.pem -in cipher.bin -out plain.bin
```

Với AES, phải biết mode, key derivation, IV/nonce, salt và authentication tag nếu có. “AES” một mình chưa đủ để decrypt.

### 5.8 Password clue thay cho brute force <a href="#id-58-password-clue-thay-cho-brute-force" id="id-58-password-clue-thay-cho-brute-force"></a>

Trước khi dùng wordlist, tìm:

* metadata Comment/Description/Author;
* tên bài và story;
* header email tùy biến;
* file README hoặc note bên cạnh;
* password hint trong EXIF;
* chuỗi decode có cú pháp `archive-password:...`;
* key được nối qua session ID hoặc hash.

Brute force chỉ hợp lý khi đề cho không gian tìm kiếm hữu hạn và có chủ đích. Không tạo “độ khó” bằng cách thử vô hạn.

***

## 6. Nhận dạng và phân tích tệp <a href="#id-6-nhan-dang-va-phan-tich-tep" id="id-6-nhan-dang-va-phan-tich-tep"></a>

### 6.1 Phần mở rộng chỉ là nhãn <a href="#id-61-phan-mo-rong-chi-la-nhan" id="id-61-phan-mo-rong-chi-la-nhan"></a>

Hệ điều hành thường chọn ứng dụng bằng extension, nhưng parser đọc byte và cấu trúc. Vì vậy cần so ba lớp:

1. tên và extension;
2. magic bytes hoặc file signature;
3. cấu trúc mà parser chuyên dụng xác nhận.

```bash
file suspicious.jpg
xxd -l 32 suspicious.jpg
7z l suspicious.jpg
```

Một số signature phổ biến:

| Định dạng         | Hex đầu tệp                  | ASCII             |
| ----------------- | ---------------------------- | ----------------- |
| ZIP/OOXML/JAR/APK | `50 4b 03 04`                | `PK..`            |
| PNG               | `89 50 4e 47 0d 0a 1a 0a`    | `.PNG....`        |
| JPEG              | `ff d8 ff`                   | —                 |
| PDF               | `25 50 44 46`                | `%PDF`            |
| ELF               | `7f 45 4c 46`                | `.ELF`            |
| PE/EXE/DLL        | `4d 5a`                      | `MZ`              |
| GZIP              | `1f 8b`                      | —                 |
| 7z                | `37 7a bc af 27 1c`          | `7z..'.`          |
| RAR               | `52 61 72 21`                | `Rar!`            |
| SQLite            | `53 51 4c 69 74 65 20 66...` | `SQLite format 3` |

Signature đúng chưa đủ chứng minh toàn bộ file hợp lệ. Parser chuyên dụng vẫn phải xác nhận kích thước, offset, checksum và cấu trúc.

### 6.2 `strings` đúng cách <a href="#id-62-strings-dung-cach" id="id-62-strings-dung-cach"></a>

```bash
strings -a -n 6 artifact.bin | less
strings -a -n 8 -t x artifact.bin | less
strings -el artifact.bin | less
```

* `-a`: quét toàn bộ file;
* `-n 6`: chỉ in chuỗi dài tối thiểu 6;
* `-t x`: thêm offset hexadecimal;
* `-el`: tìm chuỗi UTF-16LE thường gặp trên Windows.

`strings` chỉ tìm dãy byte có vẻ in được; nó không hiểu cấu trúc. Dùng output như lead, không dùng như kết luận.

### 6.3 Hex viewer <a href="#id-63-hex-viewer" id="id-63-hex-viewer"></a>

```bash
xxd -g 1 -l 256 artifact.bin
xxd -g 1 -s 0x100 -l 128 artifact.bin
hexedit artifact-copy.bin
```

* `-g 1`: nhóm từng byte;
* `-l`: giới hạn số byte;
* `-s`: bắt đầu tại offset;
* chỉ sửa trên bản sao và ghi lại byte cũ/mới.

Hex editor thường chia thành ba phần: offset ở bên trái, byte hexadecimal ở giữa và ký tự đọc được ở bên phải. Khi một byte không in được, cột ký tự thường hiển thị dấu chấm.

![Cách đọc dữ liệu trong hex editor](https://github.com/dbissell6/DFIR/assets/50979196/f4ffc9ff-0954-4d19-b8a6-75b87fe0244c)

### 6.4 Hash <a href="#id-64-hash" id="id-64-hash"></a>

```bash
md5sum artifact.bin
sha1sum artifact.bin
sha256sum artifact.bin
```

SHA-256 là lựa chọn mặc định để kiểm toàn vẹn. MD5/SHA-1 vẫn có thể dùng làm identifier tương thích với hệ thống cũ, nhưng không nên dùng làm bằng chứng chống giả mạo độc lập.

Hash giống nhau chứng minh hai dãy byte giống nhau với mức tin cậy rất cao; hash khác nhau chỉ chứng minh có ít nhất một byte khác, không nói file nào đúng.

### 6.5 Entropy <a href="#id-65-entropy" id="id-65-entropy"></a>

Entropy cao có thể do compression, encryption hoặc dữ liệu media. Vì vậy:

* kết hợp entropy với signature và cấu trúc;
* so từng section thay vì toàn file;
* không gắn nhãn “encrypted” chỉ từ một con số.

### 6.6 Detect It Easy và FLOSS <a href="#id-66-detect-it-easy-va-floss" id="id-66-detect-it-easy-va-floss"></a>

Detect It Easy (DIE) giúp nhận dạng compiler, packer và file type của executable. FLOSS trích chuỗi tĩnh, stack strings và chuỗi được giải mã trong nhiều mẫu malware.

```bash
diec suspicious.exe
floss suspicious.exe | less
```

Nếu file không phải executable, hai công cụ này không phải bước mở đầu phù hợp.

***

## 7. Metadata, carving và polyglot <a href="#id-7-metadata-carving-va-polyglot" id="id-7-metadata-carving-va-polyglot"></a>

### 7.1 Metadata <a href="#id-71-metadata" id="id-71-metadata"></a>

Metadata là dữ liệu mô tả dữ liệu: thời gian, tác giả, phần mềm tạo, GPS, comment, kích thước ảnh, model thiết bị hoặc custom property.

```bash
exiftool artifact
exiftool -G1 -a -s artifact
exiftool -Comment -b image.png
```

* `-G1`: hiện group;
* `-a`: cho phép field trùng;
* `-s`: tên field ngắn;
* `-b`: xuất giá trị raw của field được chọn.

Metadata có thể bị sửa. Nó là clue mạnh khi khớp với cấu trúc khác, nhưng không tự chứng minh nguồn gốc file.

### 7.2 EOF và dữ liệu nối sau <a href="#id-72-eof-va-du-lieu-noi-sau" id="id-72-eof-va-du-lieu-noi-sau"></a>

Parser ảnh có thể dừng ở marker kết thúc dù file còn byte:

* PNG kết thúc logic ở chunk `IEND`;
* JPEG kết thúc ở marker `FF D9`;
* PDF thường có `%%EOF`, nhưng có thể có incremental update hợp lệ.

Vì thế một ảnh mở bình thường vẫn có thể mang archive nối phía sau.

```bash
binwalk image.png
```

Nếu `binwalk` báo ZIP ở offset `193`, kiểm tra trước khi trích:

```bash
xxd -g 1 -s 193 -l 16 image.png
dd if=image.png of=payload.zip bs=1 skip=193 status=none
file payload.zip
7z t payload.zip
```

`7z t` kiểm archive. Chỉ thấy `PK` chưa đủ vì dãy byte đó có thể xuất hiện ngẫu nhiên.

### 7.3 Carving <a href="#id-73-carving" id="id-73-carving"></a>

**File carving** là phục hồi dữ liệu dựa vào signature và cấu trúc thay vì tên/path trong filesystem.

```bash
binwalk -eM artifact.bin
foremost -i disk.img -o foremost-output
scalpel disk.img -o scalpel-output
```

Nhược điểm:

* có thể tạo nhiều false positive;
* file fragmented có thể không phục hồi đúng;
* mất tên gốc và metadata filesystem;
* output cần triage lại.

![Binwalk nhận diện các cấu trúc nằm bên trong một file](https://github.com/dbissell6/DFIR/assets/50979196/34c98f59-bb60-465e-b80e-b26d627b1986)

### 7.4 Polyglot file <a href="#id-74-polyglot-file" id="id-74-polyglot-file"></a>

Polyglot là một dãy byte được nhiều parser đọc theo các định dạng khác nhau. Ví dụ JPEG parser đọc phần ảnh và comment, còn ZIP parser tìm central directory ở cuối.

Quy trình kiểm tra:

```bash
file 08_polyglot.jpg
exiftool -Comment -b 08_polyglot.jpg; echo
7z l 08_polyglot.jpg
7z x 08_polyglot.jpg -ooutput-polyglot
```

Chỉ ghép các phần dữ liệu khi có nhãn, sequence hoặc cấu trúc chứng minh thứ tự. Hai chuỗi xuất hiện gần nhau không phải lý do đủ để nối.

### 7.5 Repair file hỏng <a href="#id-75-repair-file-hong" id="id-75-repair-file-hong"></a>

Quy tắc sửa tối thiểu:

1. chạy parser để lấy lỗi cụ thể;
2. đối chiếu specification hoặc file mẫu cùng định dạng;
3. xác định chính xác byte sai;
4. sửa trên bản sao;
5. chạy parser lại và so hash;
6. ghi lại offset, byte cũ và byte mới.

PNG:

```bash
pngcheck -v broken.png
xxd -g 1 -l 64 broken.png
```

Không chép cả header từ một ảnh khác nếu chỉ có một byte signature sai. Với CRC lỗi, cần hiểu chunk nào được bảo vệ trước khi sửa.

***

## 8. Steganography trong ảnh và âm thanh <a href="#id-8-steganography-trong-anh-va-am-thanh" id="id-8-steganography-trong-anh-va-am-thanh"></a>

### 8.1 Steganography là gì? <a href="#id-81-steganography-la-gi" id="id-81-steganography-la-gi"></a>

Steganography giấu sự tồn tại của thông điệp trong một vật mang. Encryption che nội dung; steganography cố che việc thông điệp tồn tại. Một challenge có thể kết hợp cả hai.

### 8.2 Checklist ảnh <a href="#id-82-checklist-anh" id="id-82-checklist-anh"></a>

```bash
file image
exiftool image
identify image
pngcheck -v image.png
binwalk image
strings -a -n 6 image | head -n 50
```

Sau đó mới chọn tool theo format:

* PNG/BMP: `zsteg`, channel/bit plane;
* JPEG/BMP/WAV/AU: `steghide`, `stegseek`;
* nhiều kiểm tra tự động: StegVeritas;
* xem channel/bit plane bằng GUI: StegSolve.

### 8.3 LSB <a href="#id-83-lsb" id="id-83-lsb"></a>

**Least Significant Bit (LSB)** là bit có trọng số thấp nhất. Thay bit cuối của một giá trị màu thường làm hình thay đổi rất ít.

Ví dụ giá trị đỏ `100` có binary `01100100`; đổi LSB thành `1` tạo `101`, mắt gần như không nhận ra. Nếu lấy LSB của hàng nghìn pixel theo thứ tự, ta có thể dựng lại một bitstream.

```bash
zsteg image.png
zsteg -E 'b1,r,lsb,xy' image.png > extracted.bin
```

`b1,r,lsb,xy` nghĩa là:

* `b1`: lấy một bit;
* `r`: channel đỏ;
* `lsb`: bit thấp nhất;
* `xy`: duyệt pixel theo trục x rồi y.

Đừng thử mọi cấu hình rồi chọn output “có vẻ đúng” nếu đề không có clue. Tên bài, metadata, palette hoặc cấu trúc payload nên thu hẹp lựa chọn.

### 8.4 Steghide và Stegseek <a href="#id-84-steghide-va-stegseek" id="id-84-steghide-va-stegseek"></a>

```bash
steghide info cover.jpg
steghide extract -sf cover.jpg
stegseek cover.jpg wordlist.txt
```

Ưu tiên tìm passphrase có nguồn trước. Chỉ dùng `stegseek` khi challenge thật sự thiết kế cho wordlist attack.

![Ví dụ kiểm tra dữ liệu ẩn bằng Steghide](https://user-images.githubusercontent.com/50979196/221450510-6200f7e2-45b7-4669-afb4-430cad7c25f7.png)

### 8.5 StegVeritas <a href="#id-85-stegveritas" id="id-85-stegveritas"></a>

```bash
stegveritas image.png
```

Tool có thể tách channel, frame, metadata và nhiều biến thể. Output lớn không đồng nghĩa có nhiều evidence; hãy đối chiếu từng kết quả với giả thuyết.

### 8.6 Âm thanh và spectrogram <a href="#id-86-am-thanh-va-spectrogram" id="id-86-am-thanh-va-spectrogram"></a>

Với WAV/MP3:

1. nghe ở âm lượng an toàn;
2. xem metadata;
3. mở waveform;
4. chuyển sang spectrogram;
5. thử đảo chiều, đổi tốc độ hoặc tách channel nếu có clue;
6. kiểm Morse, DTMF, SSTV hoặc dữ liệu LSB theo ngữ cảnh.

Công cụ thường dùng: Audacity, Sonic Visualiser, `ffmpeg`, `sox`.

```bash
ffprobe suspicious.wav
sox suspicious.wav -n spectrogram -o spectrogram.png
ffmpeg -i stereo.wav -map_channel 0.0.0 left.wav -map_channel 0.0.1 right.wav
```

Không nhìn mọi vệt trong spectrogram như ký tự. So với baseline và kiểm bằng phép biến đổi có lý do.

***

## 9. Archive, tài liệu Office, PDF, email và database <a href="#id-9-archive-tai-lieu-office-pdf-email-va-database" id="id-9-archive-tai-lieu-office-pdf-email-va-database"></a>

### 9.1 Archive <a href="#id-91-archive" id="id-91-archive"></a>

Luôn liệt kê trước khi giải nén:

```bash
7z l sample.zip
7z t sample.zip
7z x sample.zip -ooutput
```

Kiểm:

* số entry;
* encrypted hay không;
* path traversal;
* file lồng nhau;
* comment;
* dung lượng sau giải nén;
* symlink.

Archive bomb có thể nở rất lớn. Dùng VM, quota và kiểm danh sách trước.

### 9.2 OOXML: DOCX, XLSX, PPTX <a href="#id-92-ooxml-docx-xlsx-pptx" id="id-92-ooxml-docx-xlsx-pptx"></a>

OOXML là ZIP package chứa XML và resource:

```bash
7z l document.docx
7z x document.docx -ooutput-docx
find output-docx -maxdepth 3 -type f | sort
xmllint --format output-docx/word/document.xml | less
```

Vị trí đáng xem:

* `[Content_Types].xml`: loại nội dung;
* `_rels/.rels` và `word/_rels/document.xml.rels`: relationship;
* `word/document.xml`: nội dung chính;
* `word/comments.xml`: comment;
* `word/header*.xml`, `footer*.xml`: header/footer;
* `customXml/`: custom XML;
* `docProps/`: metadata;
* `word/media/`: ảnh và object;
* `vbaProject.bin`: macro nếu có.

Macro:

```bash
olevba document.docm
oledump.py document.docm
```

Không mở tài liệu có macro trên máy thật chỉ để “xem thử”.

### 9.3 PDF <a href="#id-93-pdf" id="id-93-pdf"></a>

```bash
pdfinfo sample.pdf
exiftool sample.pdf
pdftotext sample.pdf - | less
pdfimages -list sample.pdf
qpdf --check sample.pdf
```

Điểm cần quan sát:

* metadata và thời gian;
* số trang;
* embedded file;
* JavaScript/action;
* incremental update;
* object stream;
* text ẩn hoặc ảnh chứa chữ.

### 9.4 Email EML và MIME <a href="#id-94-email-eml-va-mime" id="id-94-email-eml-va-mime"></a>

Email thô gồm header và body. MIME cho phép nhiều phần, attachment, encoding và boundary.

Header quan trọng:

* `From`, `To`, `Date`, `Subject`;
* `Message-ID`;
* chuỗi `Received`;
* `Reply-To`, `Return-Path`;
* `Content-Type`, `Content-Transfer-Encoding`;
* DKIM/SPF/DMARC result nếu có;
* custom header do challenge cung cấp.

```bash
sed -n '1,/^$/p' mail.eml
ripmime -i mail.eml -d output-mail
find output-mail -maxdepth 1 -type f -printf '%f\n'
file output-mail/*
```

Python chuẩn để parse:

```python
from email import policy
from email.parser import BytesParser

with open("mail.eml", "rb") as f:
    msg = BytesParser(policy=policy.default).parse(f)

print(msg["From"], msg["To"], msg["Subject"], msg["Message-ID"])
for part in msg.walk():
    print(part.get_content_type(), part.get_filename())
```

Không tin `From` hiển thị. Chuỗi `Received` phải đọc từ dưới lên và vẫn cần xét nguồn log tin cậy.

### 9.5 SQLite <a href="#id-95-sqlite" id="id-95-sqlite"></a>

Nhiều browser/app lưu dữ liệu trong SQLite.

```bash
file history.db
sqlite3 history.db '.tables'
sqlite3 history.db '.schema'
sqlite3 -header -column history.db 'SELECT * FROM urls LIMIT 10;'
```

Workflow:

1. sao chép database cùng sidecar `-wal` và `-shm`;
2. mở bản sao;
3. đọc schema;
4. tạo query baseline có `LIMIT`;
5. lọc đúng case/key;
6. sắp thứ tự bằng field sequence hoặc timestamp;
7. decode payload sau khi kiểm duplicate/missing.

**Write-Ahead Log (WAL)** có thể chứa transaction chưa merge vào database chính. Nếu bỏ `History-wal`, kết quả có thể thiếu record mới.

### 9.6 Các database khác <a href="#id-96-cac-database-khac" id="id-96-cac-database-khac"></a>

* MySQL/MariaDB: xem dump SQL, binlog và data directory chỉ khi version tương thích.
* KeePass: database `.kdbx` là encrypted; cần master password/key file hợp pháp.
* LevelDB: Chromium/Electron app thường dùng `.log`, `.ldb`, `MANIFEST`.
* JSONL: mỗi dòng là một JSON object; dùng `jq` theo từng dòng.

***

## 10. Network Forensics với PCAP <a href="#id-10-network-forensics-voi-pcap" id="id-10-network-forensics-voi-pcap"></a>

### 10.1 Bắt đầu từ bức tranh tổng thể <a href="#id-101-bat-dau-tu-buc-tranh-tong-the" id="id-101-bat-dau-tu-buc-tranh-tong-the"></a>

PCAP là bản ghi packet đi qua một điểm capture. Nó không mặc định chứa mọi traffic của hệ thống, không luôn có payload plaintext và không tự cho biết bên nào độc hại.

Trước khi đọc từng packet, trả lời:

1. capture bắt đầu/kết thúc lúc nào?
2. có bao nhiêu packet, byte và protocol?
3. endpoint nào xuất hiện?
4. conversation nào chiếm lưu lượng lớn?
5. giao thức hoặc port nào không khớp câu chuyện?
6. có packet loss, retransmission hay capture truncated không?

Trong Wireshark:

* **Statistics → Capture File Properties**;
* **Statistics → Protocol Hierarchy**;
* **Statistics → Endpoints**;
* **Statistics → Conversations**;
* **Statistics → I/O Graphs**.

Hình dưới minh họa **I/O Graph**. Các đỉnh cao cho biết thời điểm số packet hoặc lượng dữ liệu tăng mạnh; đây là điểm tốt để quay lại packet list và kiểm tra điều gì vừa xảy ra.

![I/O Graph trong Wireshark](https://github.com/dbissell6/DFIR/assets/50979196/006d18e6-e023-417f-9011-100e0cc3143c)

**Conversations** gom traffic theo từng cặp endpoint. Thay vì đọc từ packet số 1, hãy nhìn số byte, số packet, thời lượng và port để tìm cuộc hội thoại cần ưu tiên.

![Danh sách Conversations trong Wireshark](https://github.com/dbissell6/DFIR/assets/50979196/66593d3e-146b-48a4-aa63-58974bfe6af2)

CLI tương ứng:

```bash
capinfos capture.pcap
tshark -r capture.pcap -q -z io,phs
tshark -r capture.pcap -q -z endpoints,ip
tshark -r capture.pcap -q -z conv,tcp
```

### 10.2 Nền tảng mạng cần nhớ <a href="#id-102-nen-tang-mang-can-nho" id="id-102-nen-tang-mang-can-nho"></a>

#### OSI và TCP/IP <a href="#osi-va-tcpip" id="osi-va-tcpip"></a>

Không cần học thuộc bảy lớp để giải CTF, nhưng phải biết dữ liệu đang ở đâu:

| Vùng phân tích | Ví dụ               | Câu hỏi                                            |
| -------------- | ------------------- | -------------------------------------------------- |
| Link           | Ethernet, ARP       | MAC nào giao tiếp, gateway nào được hỏi?           |
| Network        | IPv4, IPv6, ICMP    | IP nguồn/đích, fragmentation, tunnel?              |
| Transport      | TCP, UDP            | port, stream, retransmission, handshake?           |
| Application    | DNS, HTTP, SMB, TLS | request, object, hostname, credential hay payload? |

#### TCP <a href="#tcp" id="tcp"></a>

TCP dùng sequence number, acknowledgment và stream. Một TCP stream có thể bị chia thành nhiều packet; tìm payload theo từng packet dễ bỏ sót hoặc đọc sai thứ tự.

Display filter:

```
tcp.stream eq 4
tcp.flags.syn == 1 && tcp.flags.ack == 0
tcp.analysis.retransmission
tcp.len > 0
```

Trong GUI dùng **Follow → TCP Stream** để dựng hội thoại. “Follow Stream” khác “Export Objects”: một bên ghép luồng byte; một bên yêu cầu dissector hiểu object ứng dụng.

![Cửa sổ Follow TCP Stream](https://user-images.githubusercontent.com/50979196/221450162-f3187e94-1e3a-4ec7-8611-5e05f4fadd4c.png)

#### UDP <a href="#udp" id="udp"></a>

UDP không có stream/retransmission như TCP. DNS, DHCP, QUIC và nhiều protocol tùy biến dùng UDP. Thứ tự ứng dụng phải dựa vào field riêng hoặc timestamp, không suy từ `udp.stream` một cách mù quáng.

#### Port không phải protocol <a href="#port-khong-phai-protocol" id="port-khong-phai-protocol"></a>

Port 80 thường là HTTP nhưng payload trên port 80 không bắt buộc là HTTP. Wireshark có thể **Decode As** khi protocol chạy trên port lạ. Luôn xem cấu trúc và payload.

### 10.3 Display filter và capture filter <a href="#id-103-display-filter-va-capture-filter" id="id-103-display-filter-va-capture-filter"></a>

* **Capture filter** dùng khi đang bắt packet, cú pháp BPF, quyết định packet nào được ghi.
* **Display filter** dùng sau khi capture, cú pháp Wireshark, không làm mất packet trong file gốc.

Ví dụ display filter:

```
ip.addr == 10.0.0.5
ip.src == 10.0.0.5 && ip.dst == 10.0.0.10
tcp.port == 443
dns
dns.qry.name contains "example"
http.request
http.response.code == 200
frame contains "keyword"
```

`contains` trên toàn frame dễ nhiễu. Ưu tiên field cụ thể như `dns.qry.name`, `http.host`, `http.request.uri`.

Hình minh họa dưới đây cho thấy vị trí nhập display filter. Khi filter hợp lệ, Wireshark đổi màu ô nhập và chỉ ẩn những packet không khớp; file PCAP gốc không bị sửa.

![Thanh display filter và ví dụ truy vấn trong Wireshark](https://user-images.githubusercontent.com/50979196/221450082-f592ae4c-daef-4035-a0f5-aed4e3c256b4.png)

### 10.4 DNS Forensics <a href="#id-104-dns-forensics" id="id-104-dns-forensics"></a>

DNS có thể cho biết:

* hostname được truy vấn;
* client và DNS server;
* record type;
* NXDOMAIN hoặc response;
* pattern beacon;
* fragment dữ liệu trong subdomain;
* DNS tunneling/exfiltration.

```bash
tshark -r capture.pcap \
  -Y 'dns.flags.response == 0' \
  -T fields -e frame.time_epoch -e ip.src -e dns.qry.name
```

Dấu hiệu đáng xem:

* label dài, entropy cao;
* nhiều subdomain duy nhất dưới cùng suffix;
* sequence như `p01`, `p02`;
* query đều theo nhịp;
* record type bất thường;
* volume lệch baseline.

Không kết luận exfiltration chỉ vì domain dài. CDN, tracking và DKIM cũng tạo tên dài.

Ví dụ dưới đây là một nhóm DNS query có cấu trúc lặp lại. Điều đáng chú ý không phải chỉ vì tên dài, mà vì nhiều subdomain cùng dùng một suffix và mang các đoạn dữ liệu có hình thức giống nhau.

![Các DNS subdomain bất thường trong Wireshark](https://github.com/user-attachments/assets/3d1ff9c0-961c-4d39-99db-d2b84190f3c1)

#### Dựng payload có sequence <a href="#dung-payload-co-sequence" id="dung-payload-co-sequence"></a>

Giả sử tên query có dạng `p12-68656c6c6f.demo.lab`:

```bash
tshark -r capture.pcap \
  -Y 'dns.qry.name contains "demo.lab"' \
  -T fields -e dns.qry.name
```

Sau đó parse bằng Python để tránh pipeline khó đọc:

```python
import re
import subprocess

pcap = "capture.pcap"
cmd = [
    "tshark", "-r", pcap,
    "-Y", 'dns.qry.name contains "demo.lab"',
    "-T", "fields", "-e", "dns.qry.name",
]
text = subprocess.check_output(cmd, text=True)

parts = {}
for name in text.splitlines():
    match = re.fullmatch(r"p(\d+)-([0-9a-fA-F]+)\.demo\.lab", name)
    if match:
        sequence = int(match.group(1))
        fragment = match.group(2)
        if sequence in parts and parts[sequence] != fragment:
            raise ValueError(f"Sequence {sequence} có hai giá trị")
        parts[sequence] = fragment

expected = range(min(parts), max(parts) + 1)
missing = [n for n in expected if n not in parts]
if missing:
    raise ValueError(f"Thiếu sequence: {missing}")

payload = bytes.fromhex("".join(parts[n] for n in sorted(parts)))
print(payload)
```

Script kiểm duplicate và missing trước khi ghép, giảm false positive so với nối mọi label nhìn giống hex.

### 10.5 HTTP <a href="#id-105-http" id="id-105-http"></a>

Field hữu ích:

```
http.request
http.request.method == "POST"
http.host == "example.test"
http.request.uri contains "/download"
http.response.code >= 400
http.content_type
```

Xuất object trong GUI: **File → Export Objects → HTTP**.

![Cửa sổ Export Objects của Wireshark](https://user-images.githubusercontent.com/50979196/221450122-e1115a06-7d90-453e-9e30-bad69b92ea8d.png)

Cửa sổ này hiển thị các object mà HTTP dissector dựng lại được. Chọn đúng request/response dựa trên hostname, URI, content type và kích thước; đừng chỉ chọn file có tên bắt mắt.

CLI:

```bash
mkdir -p output-http
tshark -r capture.pcap --export-objects http,output-http
find output-http -maxdepth 1 -type f -printf '%f\n' | sort
file output-http/*
```

Tên `download.dat` không nói loại thật. File xuất ra phải quay lại First Five Minutes.

### 10.6 TLS <a href="#id-106-tls" id="id-106-tls"></a>

TLS mã hóa application payload nhưng metadata vẫn có thể hiện:

* IP/port;
* thời gian, kích thước, hướng traffic;
* TLS version/cipher suite;
* certificate;
* SNI nếu không được bảo vệ;
* ALPN;
* JA3/JA4-like fingerprint tùy công cụ và bối cảnh.

Để decrypt hợp pháp, thường cần key log từ chính client:

```bash
export SSLKEYLOGFILE="$PWD/sslkeys.log"
```

Trong Wireshark cấu hình `(Pre)-Master-Secret log filename`. Private key server không giải được mọi TLS hiện đại, nhất là khi dùng ephemeral key exchange.

![Ví dụ TLS key log được tạo bởi trình duyệt](https://github.com/dbissell6/DFIR/assets/50979196/a85c4fbf-5cd9-4f90-8e56-718c9539f54c)

![Traffic TLS sau khi Wireshark đọc đúng key log](https://github.com/dbissell6/DFIR/assets/50979196/e0ae5cd0-5493-4a1f-8136-2789269a7ae0)

Nếu cấu hình đúng mà traffic vẫn không được giải mã, kiểm tra key log có được tạo trong đúng phiên trình duyệt, capture có chứa handshake và cipher suite có được hỗ trợ hay không.

### 10.7 SMB, NTLM, Kerberos và WinRM <a href="#id-107-smb-ntlm-kerberos-va-winrm" id="id-107-smb-ntlm-kerberos-va-winrm"></a>

SMB có thể để lại:

* file share/path;
* filename và thao tác đọc/ghi;
* NTLM authentication exchange;
* named pipe;
* remote service artifact.

Kerberos thường liên quan AS-REQ/AS-REP, TGS-REQ/TGS-REP và service principal. Đừng trích hash/crack credential nếu bài không yêu cầu hoặc không có quyền.

WinRM/PowerShell Remoting thường đi qua HTTP(S) và WSMan. Kết luận remote execution cần kết hợp network với host log như 4624, 4688, PowerShell 4104 hoặc Sysmon.

### 10.8 ICMP/TCP/DNS/HTTP exfiltration <a href="#id-108-icmptcpdnshttp-exfiltration" id="id-108-icmptcpdnshttp-exfiltration"></a>

Các kênh có thể mang dữ liệu trong:

* ICMP echo payload;
* TCP options hoặc payload;
* DNS labels/TXT;
* HTTP query, cookie, header hoặc body;
* request timing.

Phương pháp chung:

1. xác định conversation/suffix/path;
2. xuất timestamp, sequence và payload;
3. loại duplicate/retransmission;
4. sắp theo sequence logic;
5. ghép;
6. decode;
7. kiểm cấu trúc output.

### 10.9 Protocol đặc biệt <a href="#id-109-protocol-dac-biet" id="id-109-protocol-dac-biet"></a>

* **USB HID:** capture có thể chứa keycode; cần map usage code, modifier và layout bàn phím.
* **Bluetooth:** xem advertisement, address, GATT và protocol cụ thể.
* **802.11:** cần key/handshake hợp pháp để decrypt; Aircrack-ng hỗ trợ bài lab Wi-Fi.
* **VoIP/RTP:** Wireshark có thể phân tích RTP stream và audio nếu codec được hỗ trợ.

### 10.10 Công cụ ngoài Wireshark <a href="#id-1010-cong-cu-ngoai-wireshark" id="id-1010-cong-cu-ngoai-wireshark"></a>

* `tshark`: query lặp lại và xuất field.
* Zeek: tạo log kết nối, DNS, HTTP, SSL, file.
* Suricata/Snort: áp rule IDS, cần xem alert như lead.
* NetworkMiner: dựng host/session/object bằng GUI.
* Zui/Brim: truy vấn Zeek log ở quy mô vừa/lớn.
* Aircrack-ng: Wi-Fi lab hợp pháp.
* Scapy: parse hoặc tạo packet bằng Python.
* `ngrep`: tìm pattern trong traffic plaintext.

Suricata phù hợp khi muốn chạy rule IDS trên toàn bộ PCAP và lấy danh sách alert để ưu tiên điều tra:

![Suricata phân tích PCAP](https://github.com/dbissell6/DFIR/assets/50979196/ba264e57-bcac-4868-9090-b0f69ff961d0)

NetworkMiner giúp xem host, session và file truyền qua mạng bằng giao diện đồ họa:

![NetworkMiner hiển thị file được truyền](https://github.com/dbissell6/DFIR/assets/50979196/ad029d04-3e6c-46c1-8e73-340c97f2c01b)

Zeek chuyển packet thành các bảng log như `conn.log`, `dns.log`, `http.log` và `files.log`. Cách nhìn này đặc biệt hữu ích khi PCAP lớn và bạn muốn truy vấn theo sự kiện thay vì mở từng packet:

![Zeek tạo log từ lưu lượng mạng](https://github.com/dbissell6/DFIR/assets/50979196/32b3af92-cb32-4e1d-a12b-7dff2aa98f48)

Ví dụ Zeek:

```bash
mkdir zeek-output && cd zeek-output
zeek -r ../capture.pcap
ls -1 *.log
```

Alert từ IDS là giả thuyết ưu tiên, không phải phán quyết cuối cùng.

***

## 11. Log, Windows Registry và Windows artifacts <a href="#id-11-log-windows-registry-va-windows-artifacts" id="id-11-log-windows-registry-va-windows-artifacts"></a>

### 11.1 Tư duy phân tích log <a href="#id-111-tu-duy-phan-tich-log" id="id-111-tu-duy-phan-tich-log"></a>

Log dài không khó vì số dòng; khó vì nhiều event hợp lệ nhưng không liên quan. Dùng câu chuyện để chọn:

* nguồn/provider;
* Event ID;
* host/user;
* time range;
* process ID, Logon ID, session ID;
* path/hash/remote IP;
* sequence.

Luôn chuẩn hóa timezone trước khi dựng timeline.

### 11.2 Windows Event Log <a href="#id-112-windows-event-log" id="id-112-windows-event-log"></a>

EVTX thường nằm tại:

```
C:\Windows\System32\winevt\Logs\
```

Event ID thường gặp:

| Log                     | Event ID  | Ý nghĩa khái quát                  |
| ----------------------- | --------- | ---------------------------------- |
| Security                | 4624      | đăng nhập thành công               |
| Security                | 4625      | đăng nhập thất bại                 |
| Security                | 4634/4647 | logoff                             |
| Security                | 4648      | dùng explicit credential           |
| Security                | 4672      | quyền đặc biệt cho logon           |
| Security                | 4688      | process được tạo nếu audit bật     |
| Security                | 4697      | service được cài                   |
| Security                | 4698      | scheduled task được tạo            |
| System                  | 7045      | service mới                        |
| PowerShell              | 4103      | module logging                     |
| PowerShell              | 4104      | script block logging               |
| RDP LocalSessionManager | 21/24/25  | session logon/disconnect/reconnect |

Event ID không có ý nghĩa tách rời provider và channel.

### 11.3 Sysmon <a href="#id-113-sysmon" id="id-113-sysmon"></a>

Sysmon cung cấp telemetry chi tiết nếu đã cài và cấu hình:

| Event ID | Nội dung                   |
| -------- | -------------------------- |
| 1        | Process Create             |
| 2        | File creation time changed |
| 3        | Network connection         |
| 5        | Process terminated         |
| 6        | Driver loaded              |
| 7        | Image loaded               |
| 8        | CreateRemoteThread         |
| 10       | Process access             |
| 11       | File create                |
| 12–14    | Registry events            |
| 15       | FileCreateStreamHash       |
| 17–18    | Named pipe                 |
| 22       | DNS query                  |
| 23/26    | File delete                |

Sysmon Event 1 mạnh khi có command line, parent, hashes và user. Một process name giống hệ thống nhưng chạy từ path lạ là clue, chưa phải verdict.

### 11.4 Công cụ đọc EVTX <a href="#id-114-cong-cu-doc-evtx" id="id-114-cong-cu-doc-evtx"></a>

Trên Windows:

* Event Viewer;
* PowerShell `Get-WinEvent`;
* EvtxECmd;
* Timeline Explorer;
* Log Parser/Log Parser Studio.

![Windows Event Viewer hiển thị danh sách sự kiện](https://github.com/dbissell6/DFIR/assets/50979196/e4afe9ed-8fca-4171-b88c-6a7d17f43bfd)

Trong Event Viewer, **Filter Current Log** giúp giới hạn theo thời gian, Event ID, level và source. Hãy bắt đầu từ câu chuyện cần kiểm tra thay vì chọn mọi mức cảnh báo.

![Chức năng lọc sự kiện trong Windows Event Viewer](https://github.com/dbissell6/DFIR/assets/50979196/8f0e2554-91f2-4210-a9dc-a9c20826673b)

Ví dụ PowerShell:

```powershell
Get-WinEvent -Path .\Security.evtx |
  Where-Object Id -eq 4624 |
  Select-Object TimeCreated, Id, ProviderName, Message
```

Trên Linux:

* `python-evtx`/`evtx_dump`;
* Chainsaw;
* Hayabusa;
* Sigma rule qua tool tương thích.

```bash
chainsaw hunt evtx/ -s sigma/ --mapping mappings/sigma-event-logs-all.yml
```

Rule match là lead. Kiểm event gốc, field mapping và môi trường trước khi kết luận.

### 11.5 JSONL log <a href="#id-115-jsonl-log" id="id-115-jsonl-log"></a>

```bash
head -n 3 events.jsonl | jq .
jq -r 'select(.event_id == 4104) | [.sequence,.fragment] | @tsv' events.jsonl
```

* `jq -r`: bỏ dấu quote JSON ở output string;
* `select`: giữ record thỏa điều kiện;
* `@tsv`: xuất các field dạng cột tab.

Khi mới làm quen, Python thường dễ đọc hơn một pipeline dài:

```python
import json

records = []
with open("events.jsonl", encoding="utf-8") as f:
    for line_number, line in enumerate(f, 1):
        event = json.loads(line)
        if event.get("event_id") == 4104:
            records.append((int(event["sequence"]), event["fragment"]))

records.sort(key=lambda row: row[0])
print("".join(fragment for _, fragment in records))
```

### 11.6 Windows Registry <a href="#id-116-windows-registry" id="id-116-windows-registry"></a>

Registry hive quan trọng:

| Hive           | Thường chứa                                  |
| -------------- | -------------------------------------------- |
| `SYSTEM`       | ControlSet, service, timezone, network       |
| `SOFTWARE`     | phần mềm, OS info, persistence hệ thống      |
| `SAM`          | local account metadata                       |
| `SECURITY`     | policy và secret được bảo vệ                 |
| `NTUSER.DAT`   | hoạt động theo user                          |
| `UsrClass.dat` | Shellbags và shell data theo user            |
| `Amcache.hve`  | application/file execution-related inventory |

Tool: Registry Explorer, RECmd, RegRipper, `reged`, Python libraries.

Các key thường được xem:

* `...\CurrentVersion\Run` và `RunOnce`;
* service trong `SYSTEM\CurrentControlSet\Services`;
* USB device history;
* network profile;
* typed paths/RunMRU;
* UserAssist;
* Shellbags;
* mounted devices;
* recent documents.

Timestamp của Registry key thường áp dụng cho key chứ không cho từng value. Tránh gán timestamp quá mức chi tiết.

### 11.7 MFT và USN Journal <a href="#id-117-mft-va-usn-journal" id="id-117-mft-va-usn-journal"></a>

**Master File Table (MFT)** là cấu trúc trung tâm của NTFS, chứa record về file/directory, attribute, timestamp, tên và mapping data.

**USN Journal** ghi thay đổi đối với file/directory, giúp thấy create, rename, delete và close theo chuỗi sự kiện.

Tool thường dùng:

* MFTECmd;
* UsnJrnl2Csv;
* `fls`/Sleuth Kit;
* Plaso/log2timeline.

So sánh `$STANDARD_INFORMATION` và `$FILE_NAME` timestamp có thể tạo clue về timestomping, nhưng cần hiểu cơ chế cập nhật và copy/move.

### 11.8 Prefetch <a href="#id-118-prefetch" id="id-118-prefetch"></a>

Windows Prefetch `.pf` có thể cho biết executable đã chạy, run count gần đúng, last run times và file/resource liên quan. Vị trí thường là:

```
C:\Windows\Prefetch\
```

Tool: PECmd, WinPrefetchView. Prefetch không có nghĩa mọi Windows edition/config đều bật, và thiếu Prefetch không chứng minh chương trình chưa chạy.

### 11.9 LNK và Jump Lists <a href="#id-119-lnk-va-jump-lists" id="id-119-lnk-va-jump-lists"></a>

* `.lnk` lưu target path, volume, timestamps và thông tin shortcut.
* Jump Lists ghi tài liệu gần đây hoặc destination theo ứng dụng.

Tool: LECmd, JLECmd. Chúng hữu ích khi file gốc đã xóa hoặc removable media không còn gắn.

### 11.10 Shellbags, UserAssist, RunMRU <a href="#id-1110-shellbags-userassist-runmru" id="id-1110-shellbags-userassist-runmru"></a>

* **Shellbags:** dấu vết thư mục từng được duyệt trong Explorer, kể cả thư mục không còn tồn tại.
* **UserAssist:** thông tin GUI program execution theo user, thường ROT13 cho tên value.
* **RunMRU:** lệnh đã gõ trong hộp Run.

Mỗi artifact có giới hạn riêng. Không biến “được hiển thị” thành “đã thực thi” nếu cấu trúc chỉ chứng minh điều đầu.

### 11.11 Shimcache, Amcache và SRUM <a href="#id-1111-shimcache-amcache-va-srum" id="id-1111-shimcache-amcache-va-srum"></a>

* **Shimcache/AppCompatCache:** dấu vết tương thích ứng dụng; cách diễn giải execution phụ thuộc phiên bản Windows.
* **Amcache:** inventory liên quan executable/application và metadata file.
* **SRUM:** mức sử dụng tài nguyên/mạng theo application/user trong khoảng thời gian.

Kết hợp với Prefetch, Event Log và process telemetry để tăng độ tin cậy.

### 11.12 PowerShell artifacts <a href="#id-1112-powershell-artifacts" id="id-1112-powershell-artifacts"></a>

Nguồn thường gặp:

* Event ID 4103/4104;
* console history của PSReadLine;
* process creation 4688/Sysmon 1;
* AMSI/Defender log tùy cấu hình;
* transcript nếu bật.

History thường ở:

```
%APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
```

EncodedCommand thường dùng UTF-16LE Base64:

```bash
printf '%s' 'BASE64_HERE' | base64 -d | iconv -f UTF-16LE -t UTF-8
```

PowerShell là công cụ quản trị hợp lệ; phải xem parent, command line, user, path, network và thời gian.

### 11.13 Browser, Defender, Scheduled Tasks và WMI <a href="#id-1113-browser-defender-scheduled-tasks-va-wmi" id="id-1113-browser-defender-scheduled-tasks-va-wmi"></a>

* Windows Defender log/quarantine có thể cho detection name, path, action và thời gian.
* Scheduled Tasks có XML trong filesystem và Registry artifacts.
* WMI repository/subscription có thể liên quan persistence.
* RDP bitmap cache có thể giữ mảnh hình ảnh từ desktop từ xa.
* `ActivitiesCache.db` hỗ trợ Windows Timeline trên phiên bản có tính năng này.

Không chạy executable trích từ quarantine. Phân tích trong môi trường cô lập.

***

## 12. Linux artifacts <a href="#id-12-linux-artifacts" id="id-12-linux-artifacts"></a>

### 12.1 Vị trí log phổ biến <a href="#id-121-vi-tri-log-pho-bien" id="id-121-vi-tri-log-pho-bien"></a>

Tùy distribution và cấu hình:

```
/var/log/auth.log
/var/log/secure
/var/log/syslog
/var/log/messages
/var/log/kern.log
/var/log/audit/audit.log
/var/log/nginx/
/var/log/apache2/
/var/log/wtmp
/var/log/btmp
```

Log có thể rotate thành `.1`, `.gz`. Tìm trên tất cả generation liên quan.

```bash
zgrep -h 'pattern' /var/log/auth.log* | less
```

### 12.2 Authentication <a href="#id-122-authentication" id="id-122-authentication"></a>

```bash
grep -E 'Accepted|Failed password|Invalid user|sudo:' /var/log/auth.log
last -Fai
lastb -Fai
lastlog
```

* `last` đọc `wtmp`;
* `lastb` đọc `btmp` và thường cần quyền phù hợp;
* IP trong auth log cần nối với user, thời gian và session.

### 12.3 Shell history <a href="#id-123-shell-history" id="id-123-shell-history"></a>

```
~/.bash_history
~/.zsh_history
~/.local/share/fish/fish_history
/root/.bash_history
```

History có thể thiếu timestamp, bị tắt, chưa flush hoặc bị sửa. Kết hợp với auditd, process accounting, filesystem timestamp và application log.

### 12.4 systemd journal <a href="#id-124-systemd-journal" id="id-124-systemd-journal"></a>

```bash
journalctl --list-boots
journalctl -b -1
journalctl --since '2026-09-20 08:00:00' --until '2026-09-20 10:00:00'
journalctl -u ssh.service
journalctl _PID=1234
```

Nếu phân tích journal offline, dùng `--directory` hoặc `--file` theo dạng dữ liệu được cấp.

### 12.5 Web access log <a href="#id-125-web-access-log" id="id-125-web-access-log"></a>

Các field thường có client IP, timestamp, method, URI, status, size, referrer và User-Agent.

```bash
head access.log
grep ' 404 ' access.log | head
cut -d' ' -f1 access.log | sort | uniq -c | sort -nr | head
```

Khi format có quote hoặc field tùy biến, dùng parser thay vì `cut`. Cần phân biệt scan tự động, traffic người dùng và exploit thành công.

### 12.6 Persistence <a href="#id-126-persistence" id="id-126-persistence"></a>

Kiểm tra:

* cron: `/etc/crontab`, `/etc/cron.*`, user crontab;
* systemd service/timer;
* shell profile: `.bashrc`, `.profile`, `/etc/profile.d/`;
* SSH `authorized_keys`;
* `LD_PRELOAD` và `/etc/ld.so.preload`;
* init script;
* package manager hook;
* container unit hoặc startup config.

```bash
systemctl list-unit-files --state=enabled
systemctl list-timers --all
find /etc/cron* -maxdepth 2 -type f -ls
find /home /root -name authorized_keys -type f -ls 2>/dev/null
```

### 12.7 Auditd <a href="#id-127-auditd" id="id-127-auditd"></a>

```bash
ausearch -m EXECVE -ts recent
ausearch -ua 1000
aureport -x --summary
```

Audit log chỉ có dữ liệu nếu rule đã bật. Biết nguồn telemetry nào không tồn tại giúp tránh tìm vô hạn.

***

## 13. Browser và Internet artifacts <a href="#id-13-browser-va-internet-artifacts" id="id-13-browser-va-internet-artifacts"></a>

### 13.1 Browser profile <a href="#id-131-browser-profile" id="id-131-browser-profile"></a>

Chromium-based browser thường có:

* `History` (SQLite);
* `Cookies`;
* `Login Data`;
* `Web Data`;
* `Bookmarks`;
* `Preferences`;
* `Cache`;
* `Sessions`;
* `Local Storage`/LevelDB;
* `Extensions`.

Firefox thường có:

* `places.sqlite`;
* `cookies.sqlite`;
* `formhistory.sqlite`;
* `logins.json` + key database;
* `sessionstore`;
* cache.

Luôn sao chép cả profile hoặc ít nhất database cùng WAL/SHM. Không truy cập credential thật ngoài phạm vi được phép.

### 13.2 Timestamp trình duyệt <a href="#id-132-timestamp-trinh-duyet" id="id-132-timestamp-trinh-duyet"></a>

Chrome WebKit timestamp thường là microsecond từ `1601-01-01 UTC`. Firefox có thể dùng Unix microsecond. SQLite expression cho Chrome:

```sql
SELECT
  url,
  title,
  datetime((last_visit_time/1000000)-11644473600, 'unixepoch') AS utc_time
FROM urls
ORDER BY last_visit_time DESC
LIMIT 20;
```

Xác minh đơn vị timestamp bằng sample đã biết; sai epoch có thể tạo timeline sai hàng thế kỷ.

### 13.3 History với WAL/SHM <a href="#id-133-history-voi-walshm" id="id-133-history-voi-walshm"></a>

Cấu trúc cần giữ cạnh nhau:

```
History
History-wal
History-shm
```

Mở bản sao thư mục:

```bash
cp -a browser-profile browser-working
sqlite3 browser-working/History '.tables'
sqlite3 browser-working/History 'PRAGMA journal_mode;'
```

SQLite tự đọc WAL khi sidecar đúng tên và đúng vị trí.

### 13.4 Cache <a href="#id-134-cache" id="id-134-cache"></a>

Browser cache có thể lưu response body tách khỏi index. Cần nối:

```
URL/key → index entry → object/hash → compression → content type → payload
```

Đừng quét mọi object rồi chọn chuỗi “đẹp”. Hash trong index hoặc key là bằng chứng để chọn đúng object.

### 13.5 Zone.Identifier <a href="#id-135-zoneidentifier" id="id-135-zoneidentifier"></a>

Windows có thể gắn Mark-of-the-Web trong Alternate Data Stream:

```powershell
Get-Item .\downloaded.exe -Stream *
Get-Content .\downloaded.exe -Stream Zone.Identifier
```

Field có thể cho biết zone và referrer/host URL tùy ứng dụng. Khi copy qua filesystem không hỗ trợ ADS, artifact có thể mất.

### 13.6 `.git` <a href="#id-136-git" id="id-136-git"></a>

Repository có thể giữ lịch sử đã xóa khỏi working tree:

```bash
git status
git log --all --decorate --oneline --graph
git show COMMIT
git reflog
git fsck --lost-found
```

Không chạy hook/script lạ từ repository không tin cậy. Đọc object và diff trước.

***

## 14. Disk và File System Forensics <a href="#id-14-disk-va-file-system-forensics" id="id-14-disk-va-file-system-forensics"></a>

### 14.1 Disk image là gì? <a href="#id-141-disk-image-la-gi" id="id-141-disk-image-la-gi"></a>

Disk image có thể là:

* raw/DD image;
* E01/EWF forensic image;
* VHD/VHDX;
* VMDK/QCOW2;
* AFF;
* logical image như AD1;
* filesystem image không có partition table.

Trước khi mount, dùng `file`, `ewfinfo`, `qemu-img info` hoặc tool phù hợp để xác định loại.

### 14.2 Partition và filesystem <a href="#id-142-partition-va-filesystem" id="id-142-partition-va-filesystem"></a>

Một disk image thường có partition table ở đầu; filesystem bắt đầu ở một sector khác. Tool đọc filesystem cần offset đúng.

```bash
mmls disk.img
```

Ví dụ output nói partition bắt đầu sector `2048`, sector size `512`. Byte offset là:

```
2048 × 512 = 1,048,576 bytes
```

Sleuth Kit dùng `-o 2048` theo sector, trong khi `mount -o offset=` nhận byte.

Hình dưới minh họa output của một công cụ liệt kê partition. Con số quan trọng là sector bắt đầu và kích thước sector; phải đọc từ chính image đang phân tích, không sao chép offset của ví dụ.

![Ví dụ bảng phân vùng của disk image](https://user-images.githubusercontent.com/50979196/221450652-341c6db0-16a0-4fec-bafc-094d9a3f56d1.png)

### 14.3 `fls`: liệt kê tên và metadata address <a href="#id-143-fls-liet-ke-ten-va-metadata-address" id="id-143-fls-liet-ke-ten-va-metadata-address"></a>

```bash
fls -o 2048 disk.img
fls -r -o 2048 disk.img
fls -r -d -o 2048 disk.img
```

* `-o 2048`: filesystem bắt đầu ở sector 2048;
* `-r`: đệ quy;
* `-d`: chỉ entry đã xóa.

Output có metadata address/inode-like identifier. Đây không phải số dòng.

### 14.4 `icat`: lấy nội dung theo metadata address <a href="#id-144-icat-lay-noi-dung-theo-metadata-address" id="id-144-icat-lay-noi-dung-theo-metadata-address"></a>

Giả sử `fls` cho địa chỉ `128`:

```bash
icat -o 2048 disk.img 128 > recovered.bin
file recovered.bin
sha256sum recovered.bin
```

Với entry đã xóa:

```bash
icat -r -o 2048 disk.img 128 > recovered.bin
```

`-r` yêu cầu recovery mode. Nội dung có thể bị ghi đè một phần; parser và hash/structure check vẫn cần thiết.

### 14.5 `istat` và timeline <a href="#id-145-istat-va-timeline" id="id-145-istat-va-timeline"></a>

```bash
istat -o 2048 disk.img 128
fls -r -m / -o 2048 disk.img > bodyfile.txt
mactime -b bodyfile.txt -d > timeline.csv
```

Timeline MACB:

* Modified;
* Accessed;
* Changed (metadata);
* Birth/Created nếu filesystem hỗ trợ.

Tên MACB không đồng nghĩa mọi filesystem có đủ bốn timestamp hoặc chúng cập nhật giống nhau.

### 14.6 Mount read-only <a href="#id-146-mount-read-only" id="id-146-mount-read-only"></a>

```bash
sudo mkdir -p /mnt/evidence
sudo mount -o ro,noload,loop,offset=1048576 disk.img /mnt/evidence
```

`noload` hữu ích với filesystem có journal để hạn chế replay; option phụ thuộc filesystem. Với evidence thật, ưu tiên tool forensic và write blocker thay vì mount tùy tiện.

### 14.7 EWF/E01 <a href="#id-147-ewfe01" id="id-147-ewfe01"></a>

```bash
mkdir -p ewf-mount
ewfmount evidence.E01 ewf-mount
file ewf-mount/ewf1
mmls ewf-mount/ewf1
```

`ewf1` là view logic của image, sau đó phân tích như raw. Dùng `ewfverify` để xác minh integrity.

### 14.8 VHDX và image máy ảo <a href="#id-148-vhdx-va-image-may-ao" id="id-148-vhdx-va-image-may-ao"></a>

```bash
qemu-img info disk.vhdx
guestmount --add disk.vhdx --inspector --ro /mnt/guest
```

Không boot image gốc để xem nội dung: hệ điều hành sẽ tự thay đổi log, journal và timestamp. Nếu buộc phải boot trong lab, tạo bản sao và cô lập mạng.

### 14.9 AD1, WIM và công cụ GUI <a href="#id-149-ad1-wim-va-cong-cu-gui" id="id-149-ad1-wim-va-cong-cu-gui"></a>

* **AD1** là logical evidence container thường mở bằng FTK Imager; nó không nhất thiết là bản sao toàn bộ disk.
* **WIM** là Windows Imaging Format, có thể chứa nhiều image index.
* **Autopsy** cung cấp giao diện trên The Sleuth Kit để duyệt filesystem, keyword, timeline và module ingest.

```bash
wiminfo image.wim
mkdir -p /mnt/wim
sudo wimmount image.wim 1 /mnt/wim --readonly
```

Trong FTK Imager, kiểm properties/hash trước khi export file. File export vẫn cần hash riêng và ghi rõ đường dẫn nguồn trong container.

### 14.10 Ổ đĩa mã hóa <a href="#id-1410-o-dia-ma-hoa" id="id-1410-o-dia-ma-hoa"></a>

Các dạng thường gặp:

* BitLocker;
* VeraCrypt;
* LUKS;
* FileVault;
* TrueCrypt trong challenge hoặc hệ thống cũ.

TrueCrypt đã ngừng phát triển và chỉ nên xem là **legacy**. Trong CTF, password/keyfile thường đến từ clue, memory artifact hoặc cấu hình khác. Không brute force nếu chưa kiểm các nguồn rẻ hơn.

Với LUKS trong lab hợp pháp:

```bash
cryptsetup luksDump encrypted.img
sudo cryptsetup open encrypted.img lab-volume
sudo mount -o ro /dev/mapper/lab-volume /mnt/evidence
```

Không gõ passphrase nhạy cảm vào command line nếu shell history hoặc process list có thể ghi lại. Việc mở/mount phải thực hiện trên bản sao và ở chế độ read-only khi có thể.

### 14.11 File đã xóa <a href="#id-1411-file-da-xoa" id="id-1411-file-da-xoa"></a>

Xóa file thường loại hoặc đánh dấu entry, còn data block có thể tồn tại đến khi bị ghi đè. Khả năng phục hồi phụ thuộc:

* filesystem;
* fragmentation;
* thời gian và hoạt động ghi sau xóa;
* SSD TRIM;
* encryption;
* snapshot/journal.

`testdisk` hỗ trợ partition/filesystem recovery. `photorec`, `foremost`, `scalpel` carve theo signature nhưng thường mất filename/path.

![Giao diện PhotoRec khi chọn nguồn và loại filesystem](https://github.com/dbissell6/DFIR/assets/50979196/037aae50-8f97-4d71-b785-30852c960d54)

### 14.12 NTFS Alternate Data Streams <a href="#id-1412-ntfs-alternate-data-streams" id="id-1412-ntfs-alternate-data-streams"></a>

NTFS có thể lưu nhiều data stream dưới một file:

```
normal.txt
normal.txt:hidden
```

Trên Windows:

```powershell
Get-Item .\normal.txt -Stream *
Get-Content .\normal.txt -Stream hidden
```

Trên image, dùng tool hiểu NTFS attributes. Không giả định ADS độc hại; Zone.Identifier là ví dụ hợp lệ.

### 14.13 RAID <a href="#id-1413-raid" id="id-1413-raid"></a>

Để dựng RAID phải biết:

* level;
* disk order;
* stripe/chunk size;
* parity rotation;
* offset/superblock;
* disk thiếu hoặc hỏng.

RAID 5 dùng parity XOR để chịu mất một disk. Không thử order ngẫu nhiên trên evidence gốc; tạo mapping, dùng bản sao và xác minh filesystem/output.

### 14.14 Android <a href="#id-1414-android" id="id-1414-android"></a>

Artifact có thể đến từ backup, filesystem, app database, ADB acquisition hoặc image thiết bị. ALEAPP giúp parse nhiều Android artifacts. Quyền truy cập, encryption và phiên bản Android ảnh hưởng mạnh đến dữ liệu thu được.

***

## 15. Memory Forensics chuyên sâu <a href="#id-15-memory-forensics-chuyen-sau" id="id-15-memory-forensics-chuyen-sau"></a>

### 15.1 Memory image cho ta gì? <a href="#id-151-memory-image-cho-ta-gi" id="id-151-memory-image-cho-ta-gi"></a>

Memory image là bản chụp RAM tại một thời điểm. Nó có thể còn:

* process và thread;
* command line;
* loaded module/DLL;
* network endpoint;
* handle;
* file object;
* Registry data;
* vùng nhớ executable;
* plaintext vừa được chương trình sử dụng;
* credential/token nhạy cảm;
* malware hoặc shellcode.

Nó không phải bản sao hoàn chỉnh của disk và không đảm bảo mọi dữ liệu còn tồn tại.

### 15.2 Ranh giới an toàn <a href="#id-152-ranh-gioi-an-toan" id="id-152-ranh-gioi-an-toan"></a>

Memory dump thật có thể chứa mật khẩu, token, nội dung chat, tài liệu và malware. Chỉ dùng dump từ nguồn được phép hoặc tự tạo trong VM. Không upload lên dịch vụ công khai.

### 15.3 Quy trình tổng quát <a href="#id-153-quy-trinh-tong-quat" id="id-153-quy-trinh-tong-quat"></a>

```
Xác minh file và hash
        ↓
Nhận diện OS/kernel/thời điểm chụp
        ↓
Lập danh sách process và so nhiều nguồn
        ↓
Đọc cây cha–con và command line
        ↓
Khoanh PID/case
        ↓
Nối network, handle, file, DLL, vùng nhớ
        ↓
Dump đúng object/vùng nhớ
        ↓
Hash và phân tích file đã dump
        ↓
Dựng timeline và kết luận có mức tin cậy
```

### 15.4 Volatility 3: nhận diện ảnh <a href="#id-154-volatility-3-nhan-dien-anh" id="id-154-volatility-3-nhan-dien-anh"></a>

```bash
vol -f memory.raw windows.info
```

Ghi lại:

* OS/kernel;
* architecture;
* layer/symbol;
* thời điểm chụp;
* DTB/KDBG-like context nếu tool hiển thị;
* phiên bản Volatility.

Nếu plugin lỗi, kiểm file/hash/symbol trước khi đổi mọi option.

### 15.5 `pslist`, `psscan` và `pstree` <a href="#id-155-pslist-psscan-va-pstree" id="id-155-pslist-psscan-va-pstree"></a>

```bash
vol -f memory.raw windows.pslist
vol -f memory.raw windows.psscan
vol -f memory.raw windows.pstree
```

* `pslist`: process trong danh sách liên kết mà kernel quản lý;
* `psscan`: quét signature/structure trong physical memory, có thể thấy process đã thoát hoặc hidden artifact;
* `pstree`: trình bày quan hệ PID/PPID.

So sánh:

* process có trong `psscan` nhưng không có `pslist`;
* thời gian create/exit;
* PID reuse;
* parent đã thoát;
* tên gần giống system process;
* path/session/user.

Chênh lệch không tự chứng minh rootkit; process đã thoát có thể để structure còn sót.

### 15.6 Cây process và điều bình thường <a href="#id-156-cay-process-va-dieu-binh-thuong" id="id-156-cay-process-va-dieu-binh-thuong"></a>

Một số kỳ vọng trên Windows:

* `System` là process đặc biệt;
* `smss.exe`, `csrss.exe`, `wininit.exe`, `services.exe`, `lsass.exe`, `winlogon.exe` có vai trò hệ thống;
* browser có nhiều child process;
* Office có thể sinh helper/update process;
* PowerShell có thể do quản trị hợp lệ.

Clue mạnh hơn tên:

* path sai;
* parent bất thường;
* command line mã hóa;
* user/session không khớp;
* network endpoint đáng ngờ;
* unsigned/unexpected module;
* vùng private executable kèm code/pattern;
* timeline khớp sự kiện khác.

### 15.7 Command line <a href="#id-157-command-line" id="id-157-command-line"></a>

```bash
vol -f memory.raw windows.cmdline
```

Nếu plugin hỗ trợ lọc PID:

```bash
vol -f memory.raw windows.cmdline --pid 4320
```

Đọc từng thành phần:

* executable/path;
* option;
* URL/IP;
* file đầu vào/đầu ra;
* encoding;
* environment/working directory nếu có nguồn khác.

Không decode chuỗi ngay mà quên lưu nguyên bản và PID nguồn.

### 15.8 Network endpoint <a href="#id-158-network-endpoint" id="id-158-network-endpoint"></a>

```bash
vol -f memory.raw windows.netscan
```

Nối PID với:

* local/remote address;
* state;
* thời gian nếu có;
* process tree;
* command line;
* PCAP/DNS/proxy log.

`LISTENING` không đồng nghĩa backdoor; kết nối `CLOSED` hoặc structure cũ có thể vẫn được scan thấy.

### 15.9 Handle và file object <a href="#id-159-handle-va-file-object" id="id-159-handle-va-file-object"></a>

```bash
vol -f memory.raw windows.handles --pid 4320
vol -f memory.raw windows.filescan
```

Handle cho biết process tham chiếu object nào tại thời điểm phù hợp. `filescan` quét file object trong RAM, không khẳng định file còn nguyên trên disk.

Tìm path cụ thể:

```bash
vol -f memory.raw windows.filescan | grep -i 'note.b64'
```

Dùng `grep` sau khi đã có path/keyword từ evidence trước, không quét `flag` toàn dump.

### 15.10 Dump file <a href="#id-1510-dump-file" id="id-1510-dump-file"></a>

```bash
vol -f memory.raw windows.dumpfiles --virtaddr 0xADDR
```

`0xADDR` phải đến từ output của chính memory image. Sau dump:

```bash
file file-dumped
sha256sum file-dumped
xxd -l 32 file-dumped
```

Dump có thể thiếu page hoặc có padding. Parser báo hỏng không có nghĩa địa chỉ sai ngay lập tức.

### 15.11 `malfind` và vùng nhớ khả nghi <a href="#id-1511-malfind-va-vung-nho-kha-nghi" id="id-1511-malfind-va-vung-nho-kha-nghi"></a>

```bash
vol -f memory.raw windows.malfind --pid 4320 --dump
```

`malfind` ưu tiên vùng có thuộc tính và nội dung đáng xem, thường private executable memory. False positive có thể đến từ JIT compiler, browser, .NET, security product hoặc ứng dụng tự sinh code.

Muốn tăng độ tin cậy, kiểm:

* quyền page;
* private/mapped/image;
* bytes đầu vùng;
* disassembly;
* YARA match;
* thread start address;
* module list;
* process behavior;
* network/file correlation.

### 15.12 YARA <a href="#id-1512-yara" id="id-1512-yara"></a>

YARA mô tả pattern bằng string, byte pattern và condition.

Ví dụ rule dùng cho lab:

```yara
rule Demo_Suspicious_Marker
{
    strings:
        $marker = "CASE-DEMO" ascii wide
        $mz = { 4D 5A }
    condition:
        $marker and $mz
}
```

Quét file:

```bash
yara demo.yar dumped.bin
```

Trong Volatility:

```bash
vol -f memory.raw windows.vadyarascan --yara-file demo.yar
```

YARA match chỉ nói condition khớp. Rule quá ngắn hoặc quá rộng dễ false positive.

### 15.13 DLL/module <a href="#id-1513-dllmodule" id="id-1513-dllmodule"></a>

Các plugin tùy phiên bản có thể liệt kê DLL hoặc module. Xem:

* module path;
* signed/unsigned nếu trích được;
* load order;
* module không có backing file;
* mismatch giữa PEB list và scan;
* module nằm ở user-writable path.

### 15.14 Registry trong memory <a href="#id-1514-registry-trong-memory" id="id-1514-registry-trong-memory"></a>

Volatility có plugin liệt kê hive, key/value hoặc hash-related artifacts tùy version. Đọc `--help` và chỉ trích dữ liệu thuộc phạm vi. Không xuất credential material nếu bài chỉ cần timeline.

### 15.15 Strings trong memory <a href="#id-1515-strings-trong-memory" id="id-1515-strings-trong-memory"></a>

Quét strings toàn dump thường cho hàng triệu dòng và mất context. Nếu phải dùng:

```bash
strings -a -n 8 -t d memory.raw > memory.ascii.txt
strings -el -n 8 -t d memory.raw > memory.utf16le.txt
```

Offset vật lý của `strings` không tự ánh xạ sang PID. Ưu tiên dump process/vùng/file trước rồi chạy strings trên phạm vi nhỏ.

### 15.16 VolShell và MemProcFS <a href="#id-1516-volshell-va-memprocfs" id="id-1516-volshell-va-memprocfs"></a>

* **VolShell:** môi trường tương tác để khám phá object/memory khi plugin chuẩn chưa đủ.
* **MemProcFS:** trình bày memory artifacts qua virtual filesystem, thuận tiện duyệt bằng file explorer và script.

Đây là công cụ nâng cao. Kết quả vẫn cần ghi nguồn, offset/PID và cách tái tạo.

MemProcFS mount dữ liệu bộ nhớ thành một filesystem ảo, nhờ vậy có thể duyệt process, module, network và artifact bằng file explorer hoặc script:

![MemProcFS trình bày dữ liệu bộ nhớ dưới dạng filesystem](https://github.com/user-attachments/assets/de9224a5-c659-4d1d-a9ed-e32654d599dd)

### 15.17 Volatility 2 — legacy <a href="#id-1517-volatility-2--legacy" id="id-1517-volatility-2--legacy"></a>

Volatility 2 dùng profile và plugin syntax khác. Chỉ dùng khi challenge cũ yêu cầu hoặc plugin chưa được port. Không lấy lệnh `--profile=...` của Volatility 2 áp vào Volatility 3.

Ví dụ tài liệu cũ:

```bash
vol.py -f memory.raw imageinfo
vol.py -f memory.raw --profile=Win7SP1x64 pslist
```

Trong tài liệu này, Volatility 3 được ưu tiên.

### 15.18 Hiberfil và crash dump <a href="#id-1518-hiberfil-va-crash-dump" id="id-1518-hiberfil-va-crash-dump"></a>

* `hiberfil.sys`: trạng thái hibernate, format phụ thuộc phiên bản Windows;
* crash dump: dump khi hệ thống lỗi, có thể là full/kernel/minidump;
* LSASS dump: cực kỳ nhạy cảm, có credential material.

Không xử lý LSASS dump ngoài môi trường được ủy quyền. Với CTF, chỉ lấy đúng artifact đề yêu cầu.

### 15.19 Timeline nhiều nguồn <a href="#id-1519-timeline-nhieu-nguon" id="id-1519-timeline-nhieu-nguon"></a>

Một kết luận mạnh có thể nối:

```
10:02:14  Outlook mở attachment
10:02:16  Child process PowerShell xuất hiện
10:02:18  Command line đọc file ở Downloads
10:02:20  PID tạo kết nối tới remote IP
10:02:22  File object trong Temp được ghi
10:02:25  YARA khớp vùng private executable
```

Mỗi dòng cần nguồn riêng. Đừng biến thứ tự gần nhau thành quan hệ nhân quả nếu thiếu PID/path/session/hash để nối.

***

## 16. Executable và Malware Analysis nhập môn <a href="#id-16-executable-va-malware-analysis-nhap-mon" id="id-16-executable-va-malware-analysis-nhap-mon"></a>

### 16.1 Phân tích tĩnh và động <a href="#id-161-phan-tich-tinh-va-dong" id="id-161-phan-tich-tinh-va-dong"></a>

* **Static analysis:** đọc file mà không chạy; xem hash, header, section, string, import, resource, disassembly/decompile.
* **Dynamic analysis:** chạy trong sandbox/VM cô lập; quan sát process, file, Registry, network, memory.

Luôn bắt đầu tĩnh. Không chạy file không tin cậy trên máy host.

### 16.2 Triage executable <a href="#id-162-triage-executable" id="id-162-triage-executable"></a>

```bash
sha256sum suspicious.exe
file suspicious.exe
xxd -l 64 suspicious.exe
strings -a -n 6 suspicious.exe | head -n 100
strings -el -n 6 suspicious.exe | head -n 100
diec suspicious.exe
floss suspicious.exe | less
```

Ghi:

* type/architecture;
* compiler/packer clue;
* compile timestamp chỉ như clue;
* import đáng chú ý;
* URL/domain/path;
* embedded config/resource;
* signature;
* hash.

### 16.3 PE trên Windows <a href="#id-163-pe-tren-windows" id="id-163-pe-tren-windows"></a>

Portable Executable (PE) thường gồm DOS header, PE header, optional header, data directory và section.

Section phổ biến:

* `.text`: code;
* `.rdata`: read-only data/import-related;
* `.data`: initialized data;
* `.rsrc`: resource;
* `.reloc`: relocation.

Tên section có thể bị đổi. Entropy cao và kích thước raw/virtual bất thường có thể là packer clue nhưng cần kiểm thêm.

Công cụ:

* PEStudio;
* Detect It Easy;
* `pefile` Python;
* `objdump`;
* `sigcheck`;
* Ghidra/IDA/Cutter.

```bash
objdump -x suspicious.exe | less
```

Trên Windows với Sysinternals:

```powershell
sigcheck.exe -a -h -i suspicious.exe
```

### 16.4 ELF trên Linux <a href="#id-164-elf-tren-linux" id="id-164-elf-tren-linux"></a>

```bash
file suspicious
readelf -h -S -l suspicious
readelf -d -s suspicious
objdump -d suspicious | less
ldd suspicious
```

Không dùng `ldd` trên binary không tin cậy trên máy thật; một số tình huống có thể dẫn đến thực thi code. Ưu tiên `readelf -d` trong môi trường an toàn.

### 16.5 Import và API <a href="#id-165-import-va-api" id="id-165-import-va-api"></a>

Import gợi ý capability:

* process creation;
* network;
* Registry;
* crypto;
* service/task;
* memory allocation và thread;
* anti-debug.

Một API không chứng minh hành vi xấu. Trình duyệt, EDR và phần mềm hợp lệ cũng dùng nhiều API nhạy cảm.

### 16.6 Ghidra và decompiler <a href="#id-166-ghidra-va-decompiler" id="id-166-ghidra-va-decompiler"></a>

Quy trình:

1. import đúng architecture;
2. chạy auto-analysis;
3. xem entry point và function references;
4. đổi tên function/variable theo evidence;
5. theo string/reference;
6. đối chiếu decompiler với disassembly khi logic quan trọng;
7. ghi address và điều kiện rẽ nhánh.

Decompiler tạo mã gần giống C, không phục hồi source gốc và có thể suy sai type.

### 16.7 Debugger <a href="#id-167-debugger" id="id-167-debugger"></a>

* Linux: GDB, radare2/Cutter;
* Windows: x64dbg, WinDbg;
* .NET: dnSpyEx, ILSpy/dotPeek.

Dynamic analysis cần snapshot, network mô phỏng và giám sát:

* Procmon;
* Process Explorer;
* Regshot;
* Wireshark/FakeNet-NG/INetSim;
* `strace`, `ltrace`, auditd, sysdig.

### 16.8 Packing và obfuscation <a href="#id-168-packing-va-obfuscation" id="id-168-packing-va-obfuscation"></a>

Dấu hiệu packer:

* entropy cao;
* import ít;
* section bất thường;
* entry point ở section lạ;
* self-modifying/unpack stub;
* string nghèo nhưng runtime tạo nhiều API call.

UPX hợp lệ có thể giải:

```bash
upx -t packed.exe
upx -d packed.exe -o unpacked.exe
```

Không phải file có chữ `UPX` đều unpack được; header có thể bị sửa.

### 16.9 PowerShell obfuscation <a href="#id-169-powershell-obfuscation" id="id-169-powershell-obfuscation"></a>

Các lớp thường gặp:

* `-EncodedCommand`;
* string concat;
* format operator;
* char code;
* gzip/deflate;
* download cradle;
* reflection.

Giải từng lớp trên text, không execute script:

```bash
printf '%s' "$ENCODED" | base64 -d | iconv -f UTF-16LE -t UTF-8
```

Lưu output mỗi lớp và kiểm xem lớp tiếp theo là encoding, compression hay code.

### 16.10 Sandbox công khai <a href="#id-1610-sandbox-cong-khai" id="id-1610-sandbox-cong-khai"></a>

Sandbox có thể hữu ích nhưng không upload file bí mật, tài liệu nội bộ hoặc sample bị ràng buộc. Malware có thể nhận biết sandbox; kết quả “không thấy gì” không chứng minh an toàn.

***

## 17. Thu thập dữ liệu từ máy nghi nhiễm <a href="#id-17-thu-thap-du-lieu-tu-may-nghi-nhiem" id="id-17-thu-thap-du-lieu-tu-may-nghi-nhiem"></a>

### 17.1 Nguyên tắc <a href="#id-171-nguyen-tac" id="id-171-nguyen-tac"></a>

Phần này dành cho lab hoặc môi trường được ủy quyền. Trong sự cố thật, acquisition phải theo playbook của tổ chức và yêu cầu pháp lý.

Trước khi thu thập:

* xác nhận phạm vi và người phê duyệt;
* ghi thời gian/timezone;
* ghi hostname/user/network;
* chuẩn bị storage sạch;
* dùng tool/version đã xác minh;
* tính hash;
* hạn chế làm thay đổi nguồn.

### 17.2 Thứ tự volatility <a href="#id-172-thu-tu-volatility" id="id-172-thu-tu-volatility"></a>

Dữ liệu dễ mất trước:

1. network connection/process/runtime state;
2. RAM;
3. temporary filesystem;
4. persistent disk/log;
5. backup/cloud copy.

Không áp dụng máy móc nếu hành động thu thập làm tăng rủi ro vận hành.

### 17.3 Windows <a href="#id-173-windows" id="id-173-windows"></a>

Công cụ thường dùng:

* FTK Imager;
* Magnet RAM Capture/WinPmem theo chính sách;
* KAPE để thu artifact mục tiêu;
* Velociraptor cho collection/triage có kiểm soát;
* Sysinternals cho live triage.

KAPE tập trung thu file và chạy module parser. Cấu hình target/module phải được review trước khi dùng diện rộng.

### 17.4 Linux <a href="#id-174-linux" id="id-174-linux"></a>

Disk image bằng `dd` chỉ dùng khi xác định đúng device:

```bash
sudo lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,MODEL,SERIAL
sudo dd if=/dev/sdX of=/evidence/host.img bs=4M conv=noerror,sync status=progress
sha256sum /evidence/host.img
```

`/dev/sdX` là placeholder, không copy lệnh khi chưa xác nhận thiết bị. Chọn sai có thể đọc nhầm; đảo `if`/`of` có thể phá dữ liệu.

Catscale có thể hỗ trợ triage Linux artifacts. Xem script/config trước khi chạy trên hệ thống thật.

### 17.5 Network capture <a href="#id-175-network-capture" id="id-175-network-capture"></a>

```bash
sudo tcpdump -i eth0 -s 0 -w capture.pcap
```

* `-i`: interface;
* `-s 0`: snap length đầy đủ;
* `-w`: ghi raw packet.

Capture có thể chứa credential và dữ liệu cá nhân. Bảo vệ như evidence nhạy cảm.

### 17.6 Live analysis và tác động <a href="#id-176-live-analysis-va-tac-dong" id="id-176-live-analysis-va-tac-dong"></a>

Mọi command tạo process, đọc file, cập nhật access time hoặc ghi log. Ghi lại lệnh đã chạy. Khi cần bảo toàn cao, thu image trước rồi phân tích offline.

***

## 18. Cloud, SIEM và OSINT <a href="#id-18-cloud-siem-va-osint" id="id-18-cloud-siem-va-osint"></a>

### 18.1 Cloud Forensics <a href="#id-181-cloud-forensics" id="id-181-cloud-forensics"></a>

Cloud artifact phụ thuộc provider nhưng thường gồm:

* control-plane audit log;
* identity/sign-in log;
* object storage access log;
* network flow log;
* snapshot/image;
* serverless log;
* key/secret access;
* container/orchestrator audit log.

#### AWS <a href="#aws" id="aws"></a>

Nguồn thường gặp: CloudTrail, VPC Flow Logs, S3 access log, GuardDuty finding, CloudWatch, IAM policy/history.

```bash
aws cloudtrail lookup-events --max-results 20
aws sts get-caller-identity
```

Ghi account, region, profile và time range. Event có thể nằm ở region hoặc trail khác.

#### Azure <a href="#azure" id="azure"></a>

Nguồn thường gặp: Activity Log, Entra ID sign-in/audit log, NSG Flow Logs, Defender alerts, resource logs.

```bash
az account show
az monitor activity-log list --max-events 20
```

Không thay đổi resource khi chỉ được phép điều tra. Ưu tiên query read-only và export có hash.

### 18.2 Splunk <a href="#id-182-splunk" id="id-182-splunk"></a>

Workflow SPL:

```
index=lab earliest=-24h
| stats count by sourcetype
```

Thu hẹp:

```
index=lab sourcetype=windows EventCode=4104
| table _time host user ProcessId ScriptBlockText
| sort 0 _time
```

Lệnh hữu ích:

* `stats`: tổng hợp;
* `timechart`: xu hướng theo thời gian;
* `table`: chọn field;
* `eval`: tạo field;
* `rex`: trích bằng regex;
* `transaction`: có thể tốn tài nguyên, chỉ dùng khi hiểu giới hạn;
* `tstats`: nhanh với accelerated data model phù hợp.

### 18.3 Elastic/ELK <a href="#id-183-elasticelk" id="id-183-elasticelk"></a>

Elastic gồm Elasticsearch, Logstash/ingest và Kibana. Dùng KQL hoặc ES|QL tùy hệ thống. Xác nhận field mapping và timestamp; `message` text không thay thế field chuẩn hóa.

### 18.4 OSINT trong Forensics CTF <a href="#id-184-osint-trong-forensics-ctf" id="id-184-osint-trong-forensics-ctf"></a>

OSINT có thể hỗ trợ:

* tra domain/IP/certificate;
* tìm repository/public paste;
* reverse image search;
* xác định địa điểm từ ảnh;
* username/email correlation;
* tra hash công khai.

Nguyên tắc:

* ghi URL và thời gian truy cập;
* phân biệt nguồn gốc với nguồn sao chép;
* không đăng nhập/tiếp cận trái phép;
* không doxxing;
* nội dung Internet có thể thay đổi hoặc sai;
* kết quả OSINT phải được nối lại với artifact nội bộ.

***

## 19. Từ một file lạ đến một cuộc điều tra hoàn chỉnh <a href="#id-19-tu-mot-file-la-den-mot-cuoc-dieu-tra-hoan-chinh" id="id-19-tu-mot-file-la-den-mot-cuoc-dieu-tra-hoan-chinh"></a>

Các chương trước trình bày từng loại dữ liệu riêng. Phần này nối chúng lại thành một con đường duy nhất để bạn có thể bắt đầu với một artifact chưa từng thấy và lần lượt đi đến kết luận mà không phải đoán công cụ.

### 19.1 Chặng đầu tiên: xác định thứ đang nằm trước mặt <a href="#id-191-chang-dau-tien-xac-dinh-thu-dang-nam-truoc-mat" id="id-191-chang-dau-tien-xac-dinh-thu-dang-nam-truoc-mat"></a>

Giả sử bạn nhận được `vacation_photo.jpg`. Đừng mở hàng loạt tool steganography chỉ vì tên file có chữ “photo”. Việc đầu tiên vẫn là giữ bản gốc, tính SHA-256 và hỏi ba câu:

1. Tên file nói đây là gì?
2. Byte và cấu trúc nói đây là gì?
3. Parser nào có thể xác nhận hai thông tin trên?

Nếu `file` nhận ra ZIP, `xxd` cho thấy chữ ký `50 4b 03 04` và `7z l` đọc được danh sách entry hợp lệ, bạn đã có đủ bằng chứng để bỏ nhánh phân tích JPEG. Đây là kỹ năng nền tảng: thay đổi hướng đi ngay khi dữ liệu bác bỏ giả định ban đầu.

Sau khi extract, đừng lao thẳng vào file bên trong. Tệp vừa được tạo là một artifact mới; hãy chạy lại `file`, `sha256sum`, xem vài byte đầu và đọc metadata. Vòng lặp này được giữ nguyên dù bạn phải mở một hay mười lớp dữ liệu.

### 19.2 Khi file mở bình thường nhưng vẫn còn điều bất thường <a href="#id-192-khi-file-mo-binh-thuong-nhung-van-con-dieu-bat-thuong" id="id-192-khi-file-mo-binh-thuong-nhung-van-con-dieu-bat-thuong"></a>

Một ảnh hiển thị được không có nghĩa toàn bộ file chỉ chứa ảnh. Chương trình đọc PNG có thể dừng tại `IEND`, còn disk vẫn lưu thêm byte phía sau. Khi kích thước, metadata hoặc kết quả `binwalk` cho thấy có dữ liệu nối tiếp, hãy xem offset, carve phần đó ra một file riêng rồi dùng parser phù hợp để xác nhận.

Với polyglot, cùng một dãy byte có thể được JPEG parser và ZIP parser hiểu theo hai cách. Với LSB, thay đổi rất nhỏ ở bit cuối của màu có thể tạo thành một bitstream. Điểm chung không phải tên kỹ thuật; điểm chung là bạn luôn cần một dấu hiệu để chọn đúng parser, channel và thứ tự đọc.

Encoding cũng vậy. Một chuỗi giống Base64 mới chỉ là giả thuyết về cách biểu diễn. Chỉ sau khi decode ra text có nghĩa hoặc một file có cấu trúc hợp lệ, bạn mới có lý do để dùng kết quả cho bước tiếp theo.

### 19.3 Từ một file chuyển sang lưu lượng mạng <a href="#id-193-tu-mot-file-chuyen-sang-luu-luong-mang" id="id-193-tu-mot-file-chuyen-sang-luu-luong-mang"></a>

Khi artifact là PCAP, “file thật là gì?” không còn là câu hỏi chính. Câu hỏi đổi thành “trong hàng nghìn packet, cuộc hội thoại nào liên quan đến câu chuyện?”. Vì vậy hãy bắt đầu bằng Protocol Hierarchy, Endpoints, Conversations và I/O Graph trước khi viết filter.

Sau khi khoanh vùng được DNS suffix, HTTP path, IP hoặc stream đáng chú ý, hãy giữ đúng những field cần thiết. Nếu payload bị chia thành fragment, dùng sequence của ứng dụng để sắp xếp; packet number và thời gian đến chưa chắc là thứ tự nội dung. Nếu HTTP tải một object, export bytes rồi quay lại quy trình phân tích file từ đầu.

Đây là điểm nối quan trọng: PCAP không phải một thế giới tách biệt. Nó thường chỉ là chiếc hộp vận chuyển một ảnh, archive, executable hoặc tài liệu mà bạn sẽ tiếp tục phân tích bằng các kỹ thuật ở chương trước.

### 19.4 Khi dữ liệu đã bị xóa hoặc nằm giữa rất nhiều log <a href="#id-194-khi-du-lieu-da-bi-xoa-hoac-nam-giua-rat-nhieu-log" id="id-194-khi-du-lieu-da-bi-xoa-hoac-nam-giua-rat-nhieu-log"></a>

Với disk image, trước khi tìm file phải tìm đúng filesystem. `mmls` cho biết partition bắt đầu ở sector nào; `fls` đọc danh sách file và entry đã xóa trong filesystem đó; `icat` lấy nội dung theo metadata address. Nếu quên offset, bạn đang đưa tool tới sai vị trí và thông báo lỗi lúc này không chứng minh image bị hỏng.

Với log, vấn đề ngược lại: dữ liệu thường không mất mà quá nhiều. Hãy xác định ba thứ riêng biệt:

* field dùng để chọn đúng record;
* field dùng để sắp thứ tự;
* field chứa payload hoặc chi tiết cần đọc.

Ví dụ một chuỗi PowerShell trong JSONL có thể cần lọc theo Event ID 4104, sắp theo `sequence`, nối `fragment` rồi mới Base64 decode. Grep từ “flag” không tái dựng được câu chuyện và dễ chọn nhầm decoy.

### 19.5 Khi bằng chứng nằm trong ứng dụng <a href="#id-195-khi-bang-chung-nam-trong-ung-dung" id="id-195-khi-bang-chung-nam-trong-ung-dung"></a>

Browser history, email và tài liệu Office đều có cấu trúc riêng:

* SQLite cần đọc schema trước khi query và phải giữ WAL/SHM bên cạnh database;
* email cần đọc header, MIME boundary và attachment;
* DOCX cần được nhìn như một OOXML ZIP package có relationship và custom XML;
* browser cache cần index hoặc hash để nối URL với đúng object.

Đừng ép các nguồn thành một câu chuyện chỉ vì timestamp gần nhau. Muốn nối browser, email, proxy và endpoint log, hãy tìm khóa rõ ràng như session ID, Message-ID, device ID, path hoặc SHA-256. Mỗi bước nối phải trả lời được: giá trị này lấy từ đâu và dùng để tìm gì ở nguồn tiếp theo?

### 19.6 Khi phải đi vào bộ nhớ <a href="#id-196-khi-phai-di-vao-bo-nho" id="id-196-khi-phai-di-vao-bo-nho"></a>

Memory Forensics bắt đầu từ bối cảnh của ảnh nhớ, không bắt đầu bằng `strings | grep flag`. Xác định hệ điều hành và thời điểm chụp, so `pslist` với `psscan`, đọc cây process rồi mới chọn PID đáng xem. Từ PID đó, lần lượt kiểm command line, network endpoint, handle, file object và vùng nhớ.

Một vùng nhớ có quyền thực thi chỉ là dấu hiệu ưu tiên. Để nói process injection hoặc hành vi đáng ngờ, cần thêm ngữ cảnh: parent-child bất thường, command line, kết nối mạng, YARA match, thread hoặc file liên quan. Đây là nơi nguyên tắc giảm false positive trở nên quan trọng nhất.

### 19.7 Kết thúc bằng một lời giải có thể kiểm tra lại <a href="#id-197-ket-thuc-bang-mot-loi-giai-co-the-kiem-tra-lai" id="id-197-ket-thuc-bang-mot-loi-giai-co-the-kiem-tra-lai"></a>

Một bài chỉ thật sự hoàn thành khi người khác có thể đi lại con đường của bạn. Trước khi nộp flag, hãy chắc rằng ghi chú đã có:

1. hash của artifact gốc;
2. quan sát tạo ra giả thuyết;
3. lệnh kiểm chứng và ý nghĩa option;
4. dòng output quyết định;
5. hash hoặc nguồn của file trung gian;
6. cách loại decoy hoặc false positive;
7. vị trí chính xác nơi flag được trích ra.

Ba bộ file ở chương tiếp theo cho phép luyện toàn bộ hành trình này theo thứ tự tăng dần. Hãy làm từng thao tác, dừng ở output quan trọng và chỉ chuyển bước khi bạn giải thích được vì sao dữ liệu vừa thấy cho phép mình đi tiếp.

***

## 20. Thực hành có hướng dẫn <a href="#id-20-thuc-hanh-co-huong-dan" id="id-20-thuc-hanh-co-huong-dan"></a>

### 20.1 Làm quen với file và dữ liệu ẩn — `FORENSICS_INTRO_LAB.zip` <a href="#id-201-lam-quen-voi-file-va-du-lieu-an-forensics_intro_labzip" id="id-201-lam-quen-voi-file-va-du-lieu-an-forensics_intro_labzip"></a>

[Tải bộ file làm quen](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_FORENSICS_INTRO_LAB%7D%7D)

Gói có 12 tệp, không có flag và không tính điểm. Tên file dùng tiếng Anh để giống môi trường thi.

#### Chuẩn bị <a href="#chuan-bi" id="chuan-bi"></a>

```bash
mkdir -p ~/forensics-demo/{original,working,output}
unzip FORENSICS_INTRO_LAB.zip -d ~/forensics-demo/original
cp ~/forensics-demo/original/* ~/forensics-demo/working/
cd ~/forensics-demo/working
sha256sum * | tee ../output/initial-hashes.txt
```

#### Bài mẫu 1 — File bị gắn nhãn sai <a href="#bai-mau-1-file-bi-gan-nhan-sai" id="bai-mau-1-file-bi-gan-nhan-sai"></a>

```bash
file 01_mislabeled_image.jpg
xxd -l 16 01_mislabeled_image.jpg
7z l 01_mislabeled_image.jpg
7z x 01_mislabeled_image.jpg -o../output/01
```

Giải thích:

1. `file` nhận diện ZIP dù tên là JPEG.
2. `xxd` cho thấy `50 4b 03 04`, signature ZIP.
3. `7z l` xác nhận archive có cấu trúc đọc được.
4. `7z x` chỉ chạy sau khi đã biết entry sẽ được tạo.

Kết luận: extension là nhãn; signature cộng với parser hợp lệ mới là evidence.

#### Bài mẫu 2 — Metadata hint <a href="#bai-mau-2-metadata-hint" id="bai-mau-2-metadata-hint"></a>

```bash
file 02_metadata_hint.png
exiftool 02_metadata_hint.png
exiftool -Comment -b 02_metadata_hint.png | base64 -d; echo
```

Output chỉ dẫn chuyển sang `03_appended_data.png`. Đây là chỉ dẫn, không phải flag.

#### Bài mẫu 3 — Dữ liệu sau EOF <a href="#bai-mau-3-du-lieu-sau-eof" id="bai-mau-3-du-lieu-sau-eof"></a>

```bash
file 03_appended_data.png
binwalk 03_appended_data.png
```

Lấy offset ZIP từ output `binwalk`, thay `OFFSET`:

```bash
dd if=03_appended_data.png of=../output/03_payload.zip \
  bs=1 skip=OFFSET status=none
file ../output/03_payload.zip
7z t ../output/03_payload.zip
7z x ../output/03_payload.zip -o../output/03
```

Giải thích từng option:

* `if`: input file;
* `of`: output file;
* `bs=1`: offset tính theo byte;
* `skip=OFFSET`: bỏ đúng số byte trước payload;
* `status=none`: không in thống kê làm lẫn output.

#### Bài mẫu 4 — Encoding <a href="#bai-mau-4-encoding" id="bai-mau-4-encoding"></a>

```bash
sed -n '1,20p' 04_encodings.txt
printf '%s' 'SG9jIHR1IGR1IGxpZXUgdHJ1b2M=' | base64 -d; echo
printf '%s' '4b69656d207472612062797465' | xxd -r -p; echo
python3 -c "import urllib.parse; print(urllib.parse.unquote('tep%20demo%20da%20san%20sang'))"
```

Mỗi dòng đã có nhãn. Mục tiêu là nhận ra alphabet/pattern và kiểm output, không dùng tool đoán hàng loạt.

#### Bài mẫu 5 — Hash <a href="#bai-mau-5-hash" id="bai-mau-5-hash"></a>

```bash
sha256sum 05_original.txt 05_modified.txt
diff -u 05_original.txt 05_modified.txt
```

Hash khác nói byte khác. `diff` cho biết khác ở đâu trong text.

#### Bài mẫu 6 — PNG structure <a href="#bai-mau-6-png-structure" id="bai-mau-6-png-structure"></a>

```bash
file 06_png_structure.png
pngcheck -v 06_png_structure.png
```

Theo dõi `IHDR`, `tEXt`, `IDAT`, `IEND`. Parser xác nhận cấu trúc và CRC.

#### Bài mẫu 7 — Red-channel LSB <a href="#bai-mau-7-red-channel-lsb" id="bai-mau-7-red-channel-lsb"></a>

```bash
zsteg 07_red_channel_lsb.png
zsteg -E 'b1,r,lsb,xy' 07_red_channel_lsb
```

Output checkpoint là `DEMO_LSB_OK`, không phải flag.

#### Bài mẫu 8 — Polyglot <a href="#bai-mau-8-polyglot" id="bai-mau-8-polyglot"></a>

```bash
file 08_polyglot.jpg
exiftool -Comment -b 08_polyglot.jpg; echo
7z l 08_polyglot.jpg
7z x 08_polyglot.jpg -o../output/08
cat ../output/08/part-2.txt
```

Ghép `PART-1` và `part-2` vì label/tên chỉ rõ thứ tự, không phải vì hai chuỗi trông có vẻ khớp.

### 20.2 Phân tích PCAP, disk, log và memory output — `FORENSICS_SESSION02_DEMO.zip` <a href="#id-202-phan-tich-pcap-disk-log-va-memory-output-forensics_session02_demozip" id="id-202-phan-tich-pcap-disk-log-va-memory-output-forensics_session02_demozip"></a>

[Tải bộ file phân tích hệ thống](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_FORENSICS_SESSION02_DEMO%7D%7D)

#### Chuẩn bị <a href="#chuan-bi-1" id="chuan-bi-1"></a>

```bash
mkdir -p ~/forensics-session02/{original,working,output}
unzip FORENSICS_SESSION02_DEMO.zip -d ~/forensics-session02/original
cp ~/forensics-session02/original/* ~/forensics-session02/working/
cd ~/forensics-session02/working
sha256sum * | tee ../output/initial-sha256.txt
```

#### Bài mẫu 1 — DNS sequence <a href="#bai-mau-1-dns-sequence" id="bai-mau-1-dns-sequence"></a>

Mở `01_dns_sequence.pcap`, xem Protocol Hierarchy, Endpoints, Conversations. Sau đó:

```bash
tshark -r 01_dns_sequence.pcap \
  -Y 'dns.qry.name contains "demo02.lab"' \
  -T fields -e frame.number -e dns.qry.name
```

* `-r`: đọc file có sẵn;
* `-Y`: display filter;
* `-T fields`: output theo field;
* `-e`: field cần in.

Dùng script ở mục 10.4 để tách sequence, kiểm phần bị thiếu rồi ghép payload. Output checkpoint: `DEMO_NETWORK_ORDER_OK`.

#### Bài mẫu 2 — HTTP object <a href="#bai-mau-2-http-object" id="bai-mau-2-http-object"></a>

```bash
mkdir -p ../output/http
tshark -r 02_http_download.pcap --export-objects http,../output/http
find ../output/http -maxdepth 1 -type f -printf '%f\n' | sort
file ../output/http/*
7z l ../output/http/case02_download.dat
7z x ../output/http/case02_download.dat -o../output/http/extracted
cat ../output/http/extracted/case02/export_note.txt
```

Checkpoint: `DEMO_HTTP_EXPORT_OK`.

#### Bài mẫu 3 — Disk image <a href="#bai-mau-3-disk-image" id="bai-mau-3-disk-image"></a>

```bash
mmls 03_deleted_note.img
fls -f fat12 -o 1 -d 03_deleted_note.img
icat -f fat12 -o 1 -r 03_deleted_note.img 3 \
  > ../output/recovered-note.txt
file ../output/recovered-note.txt
cat ../output/recovered-note.txt
```

Không học thuộc `-o 1` hay metadata address `3`: chúng là giá trị lấy từ chính image mẫu. Với image khác phải đọc output lại.

Checkpoint sau decode: `DEMO_DISK_RECOVERY_OK`.

#### Bài mẫu 4 — JSONL <a href="#bai-mau-4-jsonl" id="bai-mau-4-jsonl"></a>

```bash
head -n 3 04_event_sequence.jsonl | jq .
jq -r 'select(.event_id == 4104) | [.sequence,.fragment] | @tsv' \
  04_event_sequence.jsonl
```

Lọc `event_id`, sắp `sequence` theo số, nối `fragment`, rồi Base64 decode. Checkpoint: `DEMO_LOG_SEQUENCE_OK`.

#### Bài mẫu 5 — Memory output <a href="#bai-mau-5-memory-output" id="bai-mau-5-memory-output"></a>

```bash
7z x 05_memory_outputs.zip -o../output/memory
sed -n '1,20p' ../output/memory/windows.pstree.txt
grep -n '2448' ../output/memory/windows.cmdline.txt
grep -n '2448' ../output/memory/windows.netscan.txt
grep -n 'note.b64' ../output/memory/windows.filescan.txt
base64 -d ../output/memory/dumped/note.b64; echo
```

PID `2448` đến từ cây process của bộ mẫu. Checkpoint: `DEMO_MEMORY_PATH_OK`.

### 20.3 Đi sâu vào Memory Forensics — `FORENSICS_SESSION03_MEMORY_LAB.zip` <a href="#id-203-di-sau-vao-memory-forensics-forensics_session03_memory_labzip" id="id-203-di-sau-vao-memory-forensics-forensics_session03_memory_labzip"></a>

[Tải bộ Memory Forensics](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_FORENSICS_SESSION03_MEMORY_LAB%7D%7D)

#### Chuẩn bị một thư mục duy nhất <a href="#chuan-bi-mot-thu-muc-duy-nhat" id="chuan-bi-mot-thu-muc-duy-nhat"></a>

```bash
mkdir -p ~/forensic-3
unzip FORENSICS_SESSION03_MEMORY_LAB.zip -d ~/forensic-3
cd ~/forensic-3
sha256sum -c MANIFEST.sha256
less CASE_BRIEF.md
```

Gói chứa output plugin mô phỏng theo Volatility 3, không phải raw dump.

#### Lab A — Process triage <a href="#lab-a--process-triage" id="lab-a--process-triage"></a>

Mục tiêu: tìm process cần ưu tiên mà không gắn nhãn độc hại chỉ từ tên.

```bash
less windows.info.txt
less windows.pslist.txt
less windows.psscan.txt
less windows.pstree.txt
grep -n '4320' windows.cmdline.txt
```

Đọc theo thứ tự:

1. context của image;
2. process list từ kernel;
3. structure process được scan;
4. quan hệ cha–con;
5. command line của PID đã chọn.

#### Lab B — Memory regions <a href="#lab-b--memory-regions" id="lab-b--memory-regions"></a>

```bash
grep -n '4320' windows.malfind.txt
less powershell_4320_0x0000021ab4700000.strings.txt
grep -n '4320' windows.vadyarascan.txt
```

Ba nguồn trả lời ba câu khác nhau: vùng nào đáng xem, trong vùng có chuỗi gì, rule nào khớp. Chỉ kết luận khi chúng khớp với process context.

#### Lab C — Process, network và file correlation <a href="#lab-c-process-network-va-file-correlation" id="lab-c-process-network-va-file-correlation"></a>

```bash
grep -n '4320' windows.netscan.txt
grep -n '4320' windows.handles.txt
grep -n 'cache_note.b64' windows.filescan.txt
grep -n 'cache_note.b64' windows.dumpfiles.txt
sha256sum cache_note.b64
cat timeline.csv
```

Mục tiêu là nối cùng PID/path/timestamp, không ghép các dòng chỉ vì đứng gần nhau.

#### Khi dùng raw memory dump <a href="#khi-dung-raw-memory-dump" id="khi-dung-raw-memory-dump"></a>

```bash
vol -f memory.raw windows.info
vol -f memory.raw windows.pslist
vol -f memory.raw windows.psscan
vol -f memory.raw windows.pstree
vol -f memory.raw windows.cmdline
vol -f memory.raw windows.netscan
vol -f memory.raw windows.handles --pid 4320
vol -f memory.raw windows.filescan
vol -f memory.raw windows.malfind --pid 4320 --dump
```

PID và address trong sách chỉ là ví dụ; với dump khác phải lấy từ output thực tế.

***

## 21. Bài tập từ cơ bản đến nâng cao <a href="#id-21-bai-tap-tu-co-ban-den-nang-cao" id="id-21-bai-tap-tu-co-ban-den-nang-cao"></a>

### 21.1 Cách dùng bảng bài tập <a href="#id-211-cach-dung-bang-bai-tap" id="id-211-cach-dung-bang-bai-tap"></a>

Mỗi bài bên dưới ghi mục tiêu kỹ thuật và đường suy luận dự kiến nhưng không công bố flag. Đường dẫn tải là placeholder để thay sau. Nếu phát hành một gói chung, có thể thay toàn bộ link riêng bằng URL của `FORENSICS_CTF_STUDENT_v1.0.zip`.

#### Phần 1 — File và Steganography <a href="#phan-1-file-va-steganography" id="phan-1-file-va-steganography"></a>

| Bài                       | Độ khó      | Artifact             | Trọng tâm                                  | Liên kết                                                                                                |
| ------------------------- | ----------- | -------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| F1-01 · Wrong Label       | Easy        | `vacation_photo.jpg` | extension khác signature; ZIP bị đổi tên   | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F1_01%7D%7D) |
| F1-02 · Comment Says More | Easy–Medium | `office_board.png`   | EXIF Comment, Base64, password có nguồn    | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F1_02%7D%7D) |
| F1-03 · After the End     | Medium      | `camera_export.png`  | byte sau `IEND`, offset, carve ZIP         | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F1_03%7D%7D) |
| F1-04 · Two Faces         | Medium      | `two_faces.jpg`      | polyglot JPEG/ZIP, ghép phần theo nhãn     | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F1_04%7D%7D) |
| F1-05 · Red Channel       | Medium      | `red_channel.png`    | LSB kênh đỏ, length prefix                 | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F1_05%7D%7D) |
| F1-06 · Broken Picture    | Medium+     | `broken_picture.png` | repair tối thiểu, signature, CRC, metadata | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F1_06%7D%7D) |

**F1-01 · Wrong Label**

**Câu hỏi:** Tệp thực sự thuộc định dạng nào?

**Đường làm:** hash → `file` → `xxd -l 16` → so signature → `7z l` → extract → triage file bên trong.

**Điều cần nhớ:** `file` đưa giả thuyết; `7z l` xác nhận archive có cấu trúc. Không cần tool stego chỉ vì tên có `.jpg`.

**F1-02 · Comment Says More**

**Câu hỏi:** Metadata bất thường hướng tới bước nào?

**Đường làm:** `exiftool` → lấy đúng `Comment` raw → nhận dạng Base64 → decode → dùng password có nguồn → liệt kê/mở archive.

**Điều cần nhớ:** chuỗi Base64 chưa phải password. Output decode có cấu trúc rõ mới là evidence.

**F1-03 · After the End**

**Câu hỏi:** Vì sao ảnh mở được nhưng kích thước lớn bất thường?

**Đường làm:** kiểm PNG → `binwalk` → xem bytes tại offset → `dd` carve → `7z t` → extract.

**Điều cần nhớ:** parser ảnh dừng ở `IEND`; file trên disk vẫn còn byte sau đó.

**F1-04 · Two Faces**

**Câu hỏi:** Hai parser đọc được hai phần gì trong cùng một file?

**Đường làm:** đọc JPEG Comment → `7z l` cùng file → extract `part-2` → ghép theo nhãn.

**Điều cần nhớ:** polyglot không có nghĩa mọi phần tự động liên quan; label chứng minh thứ tự.

**F1-05 · Red Channel**

**Câu hỏi:** Bitstream nằm ở channel và thứ tự nào?

**Đường làm:** metadata/PNG check → dùng clue từ title → `zsteg` → xác nhận cấu hình `b1,r,lsb,xy` → đọc length prefix → decode payload.

**Điều cần nhớ:** tránh thử mọi channel rồi chọn output trông giống flag.

**F1-06 · Broken Picture**

**Câu hỏi:** Byte nào hỏng và bằng chứng nào cho phép sửa?

**Đường làm:** `file`/`pngcheck` → so signature/chunk → sửa đúng byte trên bản sao → chạy parser lại → đọc metadata.

**Điều cần nhớ:** repair tối thiểu và có log; không thay nguyên header từ file khác.

#### Phần 2 — PCAP, Disk, Log và Memory <a href="#phan-2-pcap-disk-log-va-memory" id="phan-2-pcap-disk-log-va-memory"></a>

| Bài                        | Độ khó  | Artifact                 | Trọng tâm                                    | Liên kết                                                                                                |
| -------------------------- | ------- | ------------------------ | -------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| F2-01 · Out of Order       | Medium  | `out_of_order.pcap`      | DNS fragment, numeric sequence, Base64       | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F2_01%7D%7D) |
| F2-02 · Download Complete  | Medium  | `download_complete.pcap` | HTTP Export Objects, nhận dạng lại file      | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F2_02%7D%7D) |
| F2-03 · Deleted Note       | Medium  | `deleted_note.img`       | partition offset, deleted entry, `icat`      | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F2_03%7D%7D) |
| F2-04 · Event Trail        | Medium  | `event_trail.jsonl`      | Event ID, sequence, fragment                 | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F2_04%7D%7D) |
| F2-05 · Memory Breadcrumbs | Medium+ | `memory_breadcrumbs.zip` | process tree, cmdline, filescan, dumped file | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F2_05%7D%7D) |
| F2-06 · Matryoshka         | Medium+ | `matryoshka.pcap`        | PCAP → image → metadata/ZIP → Base64         | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F2_06%7D%7D) |

**F2-01 · Out of Order**

**Câu hỏi:** Query nào thuộc case và thứ tự ứng dụng là gì?

**Đường làm:** PCAP overview → lọc suffix → tách `pNN` và fragment → sort numeric → kiểm thiếu/trùng → nối → Base64 decode.

**Điều cần nhớ:** `p1, p10, p2` là thứ tự lexical sai; phải đổi sequence thành số.

**F2-02 · Download Complete**

**Câu hỏi:** HTTP response nào chứa object cần phân tích?

**Đường làm:** filter HTTP → xem URI/response → Export Objects → `file` object `.dat` → `7z l` → extract.

**Điều cần nhớ:** Export Objects giữ bytes; copy text từ Follow Stream có thể làm sai binary.

**F2-03 · Deleted Note**

**Câu hỏi:** File đã xóa nằm ở filesystem nào và metadata address nào?

**Đường làm:** `mmls` lấy start sector → `fls -d -o OFFSET` tìm entry → `icat -r` lấy content → file/hash/decode.

**Điều cần nhớ:** offset và address phải lấy từ output, không học thuộc số của bộ mẫu.

**F2-04 · Event Trail**

**Câu hỏi:** Event nào mang fragment và thứ tự nào là thật?

**Đường làm:** đọc schema → lọc provider/Event ID 4104 → lấy `sequence`, `fragment` → sort numeric → join → Base64 decode.

**Điều cần nhớ:** thứ tự dòng file không bắt buộc là thứ tự sự kiện.

**F2-05 · Memory Breadcrumbs**

**Câu hỏi:** Chuỗi artifact nào nối một process tới file nội dung?

**Đường làm:** giải ZIP output → `pstree` → PID → `cmdline`/`netscan` → `filescan` → dumped file → decode.

**Điều cần nhớ:** bundle là output mô phỏng, không phải raw memory dump; không grep flag toàn bộ.

**F2-06 · Matryoshka**

**Câu hỏi:** Mỗi lớp dữ liệu chỉ sang lớp nào tiếp theo?

**Đường làm:** export HTTP image → triage image → metadata và bytes sau EOF → password có nguồn → ZIP → Base64.

**Điều cần nhớ:** sau mỗi extract quay lại `file`, hash và câu hỏi mới.

#### Phần 3 — Application artifacts, Correlation và bài khó <a href="#phan-3-application-artifacts-correlation-va-bai-kho" id="phan-3-application-artifacts-correlation-va-bai-kho"></a>

| Bài                              | Độ khó   | Artifact               | Trọng tâm                                        | Liên kết                                                                                                |
| -------------------------------- | -------- | ---------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| F3-01 · Dấu vết trình duyệt      | Medium   | `browser_history.db`   | SQLite schema, URL filter, sequence              | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F3_01%7D%7D) |
| F3-02 · Thư có đính kèm          | Medium   | `mail_room.eml`        | MIME, custom header, attachment                  | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F3_02%7D%7D) |
| F3-03 · Bên trong tài liệu       | Medium+  | `document_review.docx` | OOXML relationship, custom XML                   | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F3_03%7D%7D) |
| F3-04 · Ba nguồn, một phiên      | Medium+  | `three_sources.zip`    | auth → session → device → endpoint               | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F3_04%7D%7D) |
| F3-05 · Nhịp beacon              | Advanced | `beacon_jitter.pcap`   | HTTP POST, case header, X-Sequence, hex          | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F3_05%7D%7D) |
| F3-06 · Hồ sơ IR-314             | Nâng cao | `incident_ir314.zip`   | PCAP + endpoint + hash + encrypted archive       | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F3_06%7D%7D) |
| F3-07 · Phần còn lại của History | Khó      | `history_with_wal.zip` | SQLite WAL/SHM                                   | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F3_07%7D%7D) |
| F3-08 · Bộ nhớ đệm không có tên  | Khó      | `browser_cache.zip`    | cache index, SHA-256, gzip, JSON                 | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F3_08%7D%7D) |
| F3-09 · Hồ sơ Raven              | Rất khó  | `case_raven.zip`       | history → Message-ID → email → hash/key → object | [Tải](https://file+.vscode-resource.vscode-cdn.net/g%3A/ispace/CTF-Web/Book/%7B%7BDOWNLOAD_F3_09%7D%7D) |

**F3-01 · Dấu vết trình duyệt**

**Câu hỏi:** Record nào thuộc case `BR-42` và field nào xác định thứ tự?

**Đường làm:** `file` → `.tables`/`.schema` → query baseline → lọc URL/case → sort `seq` → URL decode/payload decode.

**F3-02 · Thư có đính kèm**

**Câu hỏi:** Header nào cung cấp key và MIME part nào là attachment?

**Đường làm:** đọc header → decode custom key header → `ripmime`/Python email parser → kiểm ZIP → mở bằng key.

**F3-03 · Bên trong tài liệu**

**Câu hỏi:** Package OOXML nối relationship và custom XML ra sao?

**Đường làm:** `7z l` DOCX → đọc `.rels` → theo target → đọc `customXml` → sắp phần theo `order` → decode.

**F3-04 · Ba nguồn, một phiên**

**Câu hỏi:** Khóa nào nối auth, proxy và endpoint log?

**Đường làm:** bắt đầu từ user `svc-report` → lấy session ID → tìm device/request → tìm event `evidence_write` → decode đúng payload.

**Điều cần nhớ:** timestamp gần nhau chưa đủ; dùng key rõ ràng ở mỗi bước.

**F3-05 · Nhịp beacon**

**Câu hỏi:** POST nào thuộc case và thứ tự body là gì?

**Đường làm:** lọc `/sync` → giữ custom header case `IR-731` → lấy `X-Sequence` và body → sort numeric → join hex → decode.

**Điều cần nhớ:** packet order không bắt buộc là application order; jitter được tạo để đánh lạc hướng thứ tự thời gian.

**F3-06 · Hồ sơ IR-314**

**Câu hỏi:** Làm sao xác minh object trước khi dùng key mở archive?

**Đường làm:** PCAP cho case/artifact → endpoint event cho expected hash/key → tính SHA-256 object → chỉ mở `quarantine.dat` khi hash khớp.

**F3-07 · Phần còn lại của History**

**Câu hỏi:** Vì sao mở một mình file `History` làm thiếu record?

**Đường làm:** giữ `History`, `History-wal`, `History-shm` cùng thư mục → mở SQLite → lọc `WAL-77` → sort sequence → decode.

**F3-08 · Bộ nhớ đệm không có tên**

**Câu hỏi:** Index nối URL tới cache object nào?

**Đường làm:** đọc `index.jsonl` → lọc `CACHE-90` → lấy object hash/path/compression → kiểm SHA-256 → gunzip → parse JSON → decode payload.

**F3-09 · Hồ sơ Raven**

**Câu hỏi:** Mỗi nguồn đóng vai trò gì trong chuỗi correlation?

**Đường làm:** browser history lọc `RAVEN-204` → lấy Message-ID → tìm email tương ứng → lấy expected SHA-256 và encoded key → xác minh object → mở archive → kiểm output.

**Điều cần nhớ:** ghi nguồn của từng giá trị; không trộn key/hash từ email khác.

### 21.2 Mẫu bảng theo dõi khi làm bài <a href="#id-212-mau-bang-theo-doi-khi-lam-bai" id="id-212-mau-bang-theo-doi-khi-lam-bai"></a>

| Bước | Nguồn        | Dữ kiện      | Key/offset/PID | Lệnh kiểm chứng | File output   |
| ---- | ------------ | ------------ | -------------- | --------------- | ------------- |
| 1    | Artifact gốc | Loại file    | SHA-256        | `file`, `xxd`   | —             |
| 2    | Metadata/log | Clue         | field/value    | parser phù hợp  | `step-02.txt` |
| 3    | Container    | Entry/object | path/hash      | `7z l`, export  | `step-03.bin` |
| 4    | Payload      | Encoding     | sequence       | decode          | `result.txt`  |

***

## 22. Cách viết lời giải và báo cáo <a href="#id-22-cach-viet-loi-giai-va-bao-cao" id="id-22-cach-viet-loi-giai-va-bao-cao"></a>

### 22.1 Một lời giải tốt phải trả lời gì? <a href="#id-221-mot-loi-giai-tot-phai-tra-loi-gi" id="id-221-mot-loi-giai-tot-phai-tra-loi-gi"></a>

1. Đề cho artifact gì và hash là gì?
2. Quan sát đầu tiên nào quan trọng?
3. Vì sao quan sát đó tạo ra giả thuyết?
4. Lệnh nào kiểm chứng giả thuyết?
5. Option trong lệnh có nghĩa gì?
6. Dòng output nào quyết định bước tiếp theo?
7. File trung gian được tạo như thế nào và hash gì?
8. Đã loại false positive nào?
9. Flag đến từ đúng vị trí nào?
10. Người khác có chạy lại được không?

### 22.2 Mẫu write-up <a href="#id-222-mau-write-up" id="id-222-mau-write-up"></a>

Sao chép cấu trúc dưới đây cho từng bài:

````markdown
## ID · Tên bài

### Mục tiêu

Nêu câu hỏi kỹ thuật, không tiết lộ kết quả ngay.

### Artifact

- Tên file:
- SHA-256:
- Loại file theo `file`:

### Quan sát ban đầu

Mô tả dữ kiện, không chỉ chép output.

### Giả thuyết 1

Vì sao giả thuyết này hợp lý?

#### Phép kiểm tra

```bash
LENH
```

Giải thích từng option và dòng output quyết định.

### Artifact trung gian

- Tên:
- Cách tạo:
- SHA-256:

### Kiểm tra false positive

Ứng viên nào đã bị loại, vì sao?

### Kết quả

Ghi vị trí lấy flag; không chỉ ghi flag.

### Bài học

Tóm tắt clue → tool → evidence.
````

### 22.3 Timeline <a href="#id-223-timeline" id="id-223-timeline"></a>

| Thời gian UTC       | Nguồn          | Host/User/PID       | Sự kiện        | Mức tin cậy | Ghi chú                 |
| ------------------- | -------------- | ------------------- | -------------- | ----------- | ----------------------- |
| 2026-09-20 03:02:14 | EVTX 4688      | WS-23 / user / 4320 | Process tạo    | Cao         | Event gốc               |
| 2026-09-20 03:02:18 | Memory netscan | WS-23 / PID 4320    | Kết nối remote | Trung bình  | Structure còn trong RAM |

Luôn ghi timezone. Nếu timestamp được suy ra, nêu cách chuyển đổi.

### 22.4 Ngôn ngữ kết luận <a href="#id-224-ngon-ngu-ket-luan" id="id-224-ngon-ngu-ket-luan"></a>

Chọn từ phù hợp mức evidence:

* **Quan sát:** “Output `filescan` có file object với path…”
* **Hỗ trợ giả thuyết:** “Path và PID khớp command line, hỗ trợ giả thuyết process đã truy cập file.”
* **Chưa đủ:** “Vùng RWX đáng kiểm tra nhưng chưa đủ kết luận injection.”
* **Xác nhận trong phạm vi bài:** “SHA-256 khớp expected hash và archive parse hợp lệ.”

Tránh từ tuyệt đối như “chắc chắn” khi nguồn chỉ là artifact không đầy đủ.

***

## 23. Bảng lệnh tra cứu nhanh <a href="#id-23-bang-lenh-tra-cuu-nhanh" id="id-23-bang-lenh-tra-cuu-nhanh"></a>

### 23.1 File và hash <a href="#id-231-file-va-hash" id="id-231-file-va-hash"></a>

| Mục đích         | Lệnh                      |
| ---------------- | ------------------------- |
| Nhận dạng        | `file FILE`               |
| Xem 64 byte đầu  | `xxd -g 1 -l 64 FILE`     |
| Strings ASCII    | `strings -a -n 6 FILE`    |
| Strings UTF-16LE | `strings -el -n 6 FILE`   |
| SHA-256          | `sha256sum FILE`          |
| Metadata         | `exiftool -G1 -a -s FILE` |
| Signature nhúng  | `binwalk FILE`            |

### 23.2 Archive và carving <a href="#id-232-archive-va-carving" id="id-232-archive-va-carving"></a>

| Mục đích        | Lệnh                                             |
| --------------- | ------------------------------------------------ |
| Liệt kê         | `7z l ARCHIVE`                                   |
| Kiểm            | `7z t ARCHIVE`                                   |
| Extract         | `7z x ARCHIVE -oOUTPUT`                          |
| Carve từ offset | `dd if=FILE of=OUT bs=1 skip=OFFSET status=none` |
| Carve tự động   | `foremost -i IMAGE -o OUTPUT`                    |

### 23.3 PCAP <a href="#id-233-pcap" id="id-233-pcap"></a>

| Mục đích           | Lệnh                                            |
| ------------------ | ----------------------------------------------- |
| Thông tin capture  | `capinfos FILE.pcap`                            |
| Protocol hierarchy | `tshark -r FILE.pcap -q -z io,phs`              |
| Display filter     | `tshark -r FILE.pcap -Y 'FILTER'`               |
| Xuất field         | `tshark -r FILE.pcap -T fields -e FIELD`        |
| Export HTTP        | `tshark -r FILE.pcap --export-objects http,DIR` |

### 23.4 Disk/Sleuth Kit <a href="#id-234-disksleuth-kit" id="id-234-disksleuth-kit"></a>

| Mục đích           | Lệnh                                     |
| ------------------ | ---------------------------------------- |
| Partition          | `mmls IMAGE`                             |
| Liệt kê filesystem | `fls -r -o SECTOR IMAGE`                 |
| Entry đã xóa       | `fls -r -d -o SECTOR IMAGE`              |
| Lấy content        | `icat -o SECTOR IMAGE META > OUT`        |
| Metadata entry     | `istat -o SECTOR IMAGE META`             |
| Timeline bodyfile  | `fls -r -m / -o SECTOR IMAGE > bodyfile` |

### 23.5 Log và database <a href="#id-235-log-va-database" id="id-235-log-va-database"></a>

| Mục đích      | Lệnh                                       |
| ------------- | ------------------------------------------ |
| Format JSON   | `jq . FILE.json`                           |
| Lọc JSONL     | `jq -r 'select(CONDITION)' FILE.jsonl`     |
| SQLite table  | `sqlite3 DB '.tables'`                     |
| SQLite schema | `sqlite3 DB '.schema'`                     |
| Query dễ đọc  | `sqlite3 -header -column DB 'SELECT ...;'` |
| MIME extract  | `ripmime -i mail.eml -d OUTPUT`            |
| XML format    | `xmllint --format FILE.xml`                |

### 23.6 Memory/Volatility 3 <a href="#id-236-memoryvolatility-3" id="id-236-memoryvolatility-3"></a>

| Câu hỏi                          | Plugin                              |
| -------------------------------- | ----------------------------------- |
| Ảnh thuộc hệ nào?                | `windows.info`                      |
| Kernel quản lý process nào?      | `windows.pslist`                    |
| Quét thấy process structure nào? | `windows.psscan`                    |
| Parent-child ra sao?             | `windows.pstree`                    |
| Command line gì?                 | `windows.cmdline`                   |
| Endpoint mạng nào?               | `windows.netscan`                   |
| PID giữ object nào?              | `windows.handles --pid PID`         |
| File object nào còn dấu?         | `windows.filescan`                  |
| Vùng nào đáng kiểm injection?    | `windows.malfind --pid PID`         |
| Rule YARA khớp đâu?              | `windows.vadyarascan`               |
| Dump file object                 | `windows.dumpfiles --virtaddr ADDR` |

### 23.7 Image/Stego <a href="#id-237-imagestego" id="id-237-imagestego"></a>

| Mục đích      | Lệnh                                     |
| ------------- | ---------------------------------------- |
| PNG structure | `pngcheck -v FILE.png`                   |
| LSB scan      | `zsteg FILE.png`                         |
| LSB đỏ        | `zsteg -E 'b1,r,lsb,xy' FILE.png`        |
| Steghide info | `steghide info FILE.jpg`                 |
| Spectrogram   | `sox FILE.wav -n spectrogram -o OUT.png` |

***

## 24. Thuật ngữ <a href="#id-24-thuat-ngu" id="id-24-thuat-ngu"></a>

| Thuật ngữ        | Giải thích ngắn                                   |
| ---------------- | ------------------------------------------------- |
| Acquisition      | quá trình thu thập dữ liệu từ nguồn               |
| Artifact         | vật liệu/dấu vết số dùng để phân tích             |
| Baseline         | kết quả gốc để so sánh                            |
| Carving          | phục hồi dữ liệu theo signature/cấu trúc          |
| Chain of custody | hồ sơ ai đã giữ và xử lý evidence khi nào         |
| Clue             | dấu hiệu có ích dẫn tới phép thử                  |
| Correlation      | nối nhiều nguồn bằng key/thời gian/ngữ cảnh       |
| Decoy            | dữ liệu đánh lạc hướng có chủ đích                |
| DFIR             | Digital Forensics and Incident Response           |
| Disk image       | bản sao logic/bitstream của thiết bị lưu trữ      |
| Encoding         | đổi cách biểu diễn dữ liệu, không nhằm giữ bí mật |
| Encryption       | mã hóa bằng thuật toán và key                     |
| Endpoint         | đầu giao tiếp mạng hoặc thiết bị cuối             |
| Entropy          | thước đo mức phân bố/ngẫu nhiên của dữ liệu       |
| Evidence         | dữ kiện có nguồn và đủ sức hỗ trợ kết luận        |
| False positive   | nhận định có vấn đề khi dữ liệu chưa đủ           |
| File signature   | mẫu byte đặc trưng cho định dạng                  |
| Hash             | digest dùng nhận diện/kiểm toàn vẹn               |
| IOC              | Indicator of Compromise, chỉ dấu xâm nhập         |
| LSB              | Least Significant Bit, bit trọng số thấp nhất     |
| Magic bytes      | byte đầu hoặc mẫu đặc trưng nhận dạng file        |
| Memory image     | bản chụp nội dung RAM                             |
| Metadata         | dữ liệu mô tả dữ liệu                             |
| MIME             | chuẩn đóng gói nhiều phần của email               |
| Offset           | vị trí tính từ đầu dữ liệu                        |
| OOXML            | định dạng Office dựa trên ZIP/XML                 |
| Parser           | chương trình đọc cấu trúc định dạng               |
| PCAP             | file packet capture                               |
| PID/PPID         | process ID/parent process ID                      |
| Polyglot         | một file được nhiều parser đọc hợp lệ             |
| Sequence         | số/thứ tự logic của fragment/event                |
| Sidecar          | file phụ đi kèm file chính, như WAL/SHM           |
| Steganography    | kỹ thuật giấu sự tồn tại của thông tin            |
| Stream           | luồng dữ liệu được ghép từ nhiều packet           |
| Timeline         | chuỗi sự kiện theo thời gian                      |
| Triage           | phân loại nhanh để chọn hướng ưu tiên             |
| WAL              | Write-Ahead Log của SQLite                        |
| Write blocker    | thiết bị/cơ chế ngăn ghi vào nguồn evidence       |

***

## 25. Tài liệu tham khảo <a href="#id-25-tai-lieu-tham-khao" id="id-25-tai-lieu-tham-khao"></a>

* CyberChef: <https://gchq.github.io/CyberChef/>
* Kali Linux: <https://www.kali.org/docs/>
* Wireshark User’s Guide: <https://www.wireshark.org/docs/>
* The Sleuth Kit: <https://www.sleuthkit.org/sleuthkit/docs.php>
* Volatility 3: <https://volatility3.readthedocs.io/>
* ExifTool: <https://exiftool.org/>
* YARA: <https://yara.readthedocs.io/>
* Zeek: <https://docs.zeek.org/>
* Suricata: <https://docs.suricata.io/>
* Sigma: <https://sigmahq.io/>
* SQLite: <https://www.sqlite.org/docs.html>
* Ghidra: <https://ghidra-sre.org/>

***

> **Nhắc lại:** công cụ chỉ có giá trị khi nó trả lời một câu hỏi. Một lời giải tốt không phải danh sách lệnh dài; đó là chuỗi quyết định mà mỗi bước đều có dữ kiện để đi tiếp.
