# Disk ## Sleuth Kit(TSK)指令整理 ### img_stat * 用途:查看磁碟映像檔的基本資訊(大小、磁區大小、類型、分割資訊) * 使用時機:拿到 .img 或 .dd 檔的第一步,先了解這顆磁碟的結構 * 🌰 `img_stat disk.img` ### mmls * 用途:顯示磁碟映像檔內的分割區資訊(MBR/GPT 分割區表) * 使用時機:確認檔案系統從哪個 offset 開始,供後續指令使用 * 🌰`mmls disk.img` * 📌 注意 Start 欄位的數值,後續像 fls、icat 要用 `-o <offset>` ### fsstat * 用途:顯示某個檔案系統的細節(例如 FAT/EXT/NTFS 的 metadata 結構) * 使用時機:分析文件系統類型與結構 * 🌰`fsstat -o 2048 disk.img` ### fls * 用途:列出檔案系統中的檔案與目錄(包含已刪除的) * 使用時機:找到目標檔案或目錄(例如 flag.txt 或特定資料夾) * 🌰`fls -o 2048 -r disk.img` * 🌰`fls -o 2048 -r disk.img 16` ### ffind - 用途:透過檔案名稱找出 inode 號碼 - 使用時機:若你知道檔名(例如 "flag.txt")但不想手動看 fls 結果,可快速找 inode - 🌰 `ffind -o 2048 disk.img flag.txt` ### tsk_recover * 用途:從映像檔中恢復檔案(包含刪除檔) * 使用時機:想直接將檔案系統內容 dump 出來分析(不用一個個 icat) * 🌰`tsk_recover -o 2048 disk.img output_dir/` * > 會把整個分割區的檔案複製到 output_dir,可以直接用 ls 看 ### icat * 用途:依 inode 號碼從映像檔中提取單一檔案 * 使用時機:用 fls 找到特定檔案 inode 後,用來匯出內容 * 作用檔案:磁碟映像檔 * 🌰`icat -o 2048 disk.img 128` * 📌 上面會把 inode 為 128 的檔案內容印出來,可以用 > output 存檔 ### istat - 用途:顯示指定 inode 的 metadata(建立時間、大小、狀態) - 使用時機:想知道檔案什麼時候被建立、是否刪除、還在不在 - 🌰 `istat -o 2048 disk.img 128` - 📌 刪除檔案也會有 metadata(可能幫助你確認「flag.txt 是不是被刪掉」) ### blkls - 用途:直接印出資料區塊(raw data) - 使用時機:想用 strings 擷取出某些資料,像是被藏起來的 flag、png 頭之類的 raw data - 🌰 `blkls -o 2048 disk.img > raw.bin && strings raw.bin | grep CTF` ## 題目 :::spoiler picoCTF-Sleuthkit Intro 題目給了一個img檔案跟一個nc連線的資訊 先連線上去看他要問什麼,他要問的是Linux部分的長度 ![image](https://hackmd.io/_uploads/SylCp1_0Jx.png) 題目已經有告訴我們要用mmls了,所以就`mmls disk.img` ![image](https://hackmd.io/_uploads/rkx1CydA1e.png) 第三行的length就是答案了,送出答案就會得到flag了 ::: :::spoiler picoCTF-Sleuthkit Apprentice 題目給了一個disk檔 下載之後用`gunzip`解壓縮 然後用`mmls`查看分隔區表 ![image](https://hackmd.io/_uploads/SyQvP5D01l.png) 有兩個Linux分隔區 分別用`fsstat -o 2048 disk.flag.img `跟`fsstat -o 360448 disk.flag.img`查看內容 發現第二個`Last mounted on: /`所以應該是要找這個 ![image](https://hackmd.io/_uploads/HkcRDcwA1x.png) 用`fls -o 360448 disk.flag.img`查看目錄 然後`fls -o 360448 disk.flag.img 1995`發現root下有資料夾 `fls -o 360448 disk.flag.img 3981`找到兩個檔案(一個被刪除了) 用`tsk_recover -e -o 360448 disk.flag.img -d 3981 Apprentice/`導出資料夾裡的所有檔案,cat 檔案就能找到flag ::: :::spoiler picoCTF-Disk, disk, sleuth! 這題說要用srch_strings,上網查發現它可以印出可視字串 直接使用會噴出一堆東西,所以要搭配grep進行搜尋 `srch_strings dds1-alpine.flag.img | grep "CTF"`然後就找到flag了 ::: :::spoiler picoCTF-Disk, disk, sleuth! II 這題一樣解壓縮後用 `mmls dds2-alpine.flag.img`確認分隔區 我們現在知道要找的檔案的名字,所以可以直接讓他列出全部的檔案再搜尋 `fls -o 2048 -r dds2-alpine.flag.img| grep "down-at-the-bottom"` ![image](https://hackmd.io/_uploads/SyWy65DC1g.png) 找到之後用`icat -o 2048 dds2-alpine.flag.img 18291 > dds2.txt`提取檔案 `cat dds2.txt`會出現![image](https://hackmd.io/_uploads/H1XLQp9vCye.png) 組合起來就是flag ::: :::spoiler picoCTF-Operation Oni 下載之後解壓縮,用mmls查看分隔區 分別用`fsstat -o 2048 disk.img `跟`fsstat -o 206848 disk.img`查看內容 發現第二個`Last mounted on: /`所以應該是要找這個 `fls -o 206848 disk.img`然後通常私鑰預設就會存在`root`底下 進去root看看`fls -o 206848 disk.img 470` ![image](https://hackmd.io/_uploads/BJBC91OCJl.png) 看到一個叫.ssh的目錄,再進去可以看到兩個檔案 ![image](https://hackmd.io/_uploads/SkG7j1uCJg.png) 分別查看兩個檔案內容 ![螢幕擷取畫面 2025-05-20 204954](https://hackmd.io/_uploads/rJHCql5bxx.png) 導出id_ed25519這個檔案`icat -o 206848 disk.img 2345 > ssh1.txt` 然後加權限給他`chmod 600 ssh1.txt` 用這個檔案進行ssh連線後`cat flag.txt`就找到flag了 ![image](https://hackmd.io/_uploads/Bkc9jyuRJg.png) ::: :::spoiler picoCTF-Operation Orchid 解壓縮後用`mmls`查看分隔區表 ![image](https://hackmd.io/_uploads/B1BWM-cZlx.png) 一跟三是linux分隔區,分別用`fsstat`查看內容 ![image](https://hackmd.io/_uploads/Bkhk3b9-ge.png)![image](https://hackmd.io/_uploads/S1O-n-cbex.png) 第三個`Last mounted on: /`所以猜是在第三個這個裡面 用`fls -o 411648 disk.flag.img`查看一下目錄![image](https://hackmd.io/_uploads/S1HOnW5bex.png) 查看root目錄,發現加密過的flag檔案 ![image](https://hackmd.io/_uploads/ryxA2Wcblg.png) 用 `strings -t d disk.flag.img | grep flag.txt`尋找金鑰在哪 ![image](https://hackmd.io/_uploads/H1xVaW9bel.png) 找到`openssl aes256 -salt -in flag.txt -out flag.txt.enc -k unbreakablepassword1234567` 用`icat -o 411648 disk.flag.img 1782 > flag.txt.enc`導出檔案,再用密鑰進行解密,然後就可以得到flag ![image](https://hackmd.io/_uploads/rkei6ZcWxe.png) :::