# __CHFI Module 01~03 課程共筆__
:::success
## 教材區
- [**教材**](https://drive.google.com/drive/folders/1QBTpzrowspTHIbweXdoKWZL9x5mOOC3A)
- [**工具**](https://drive.google.com/drive/folders/1A7TM9H5qHQCmQ4dULzmzW5U9APv4WXme?usp=sharing)
- [01~03課程共筆](https://hackmd.io/cWmT8NaFRzubo7CVOg1KxQ)
- [04~06課程共筆](https://hackmd.io/-PS9hnBOTc6wo-sz5RolKQ)
- [07~14課程共筆](https://hackmd.io/mqAL1L1ZRdiG1PmObPanCg)
- [LAB](https://hackmd.io/j9GzjYJlR6GmozF6sNtEWQ)
:::
## Module 01 Computer Forensics in Today's World
:::info
### __Forensic Science__
- 系統化
- 可重複
- 可再現
- 可檢驗
- Evidence 證據
- 電腦鑑識 → 將符合證據的東西找出來
[一元哥新聞](https://udn.com/news/story/7321/3862282)
:::
:::success
### **Cybercrimes** 類型
- 電腦犯罪→電腦為標的
- 電腦輔助犯罪→電腦為工具

- Internal Attacks
- Espionage 商業間諜
- Theft of Intellectual Property 智慧財產的偷竊
- Manipulation of the records 竄改紀錄
- External Attacks
- SQL attack
- brute
:::
:::warning
### **Challenges 現今網路犯罪的挑戰**
- Speed 速度快
- APT38 北韓網軍 Lazarus
- Western Union 西聯匯款 (錢出的去回不來 匿名匯款
- Anonymity 匿名性高->追查困難
- Volatile nature of evidence 證據的可揮發性(隨著時間與狀態的改變,證據會消失,ex.記憶體)
- Evidence Size and Complexity 證據的大小與複雜性
- Anti-Digital Forensics(ADF) 反鑑識的技術
- **sdelete.exe** → 專業滅證工具 (微軟內建刪除功能)
- [一銀案件](https://www.ithome.com.tw/news/107136)
- Windows Sysinternals
- Global origin and difference in laws 各國法律不同
- Limited legal understanding 對法律理解的不完備
:::
:::success
### **Investigation 犯罪調查(考試會考)**
- civil 民事
- 侵權行為
- Criminal 刑事
- 妨害電腦使用罪 刑法第36章
- Administrative 行政類、監管類
- 監管機構或政府對於管理以及表現的事實調查證明
- non criminal in nature - 本質上不可涉及到刑事案件
- Violation of organization's policies, rules, or protocols 違反組織內部條例
- Resources misuse 濫用公司資源
- Threatening or violent behavior 威脅或者暴力行爲
- improper promotion or pay rise 不當升職調薪
:::
:::info
### **鑑識調查規定Rules of Forensics Investigation**

- Integrity 完整性
- 不可以有僞證
- 有變動要記錄(保留完整性)
- **==Chain of custody 保管鏈==**(法務部的區塊鏈Block Chain)→有考必選
- ISO 27035 業界標準 事件管理標準
- jurisdiction standard 管理司法管轄權
:::
:::success
### **Locard's Exchange Principle 羅卡的交換原則**
行為人(犯罪嫌疑者)必然會帶走一些東西,亦會留下一些東西

:::
:::info
### **Types of Digital Evidence**
- Volatile Data
- 時間電量
隨著時間以及電量的流逝,資料會消失
- Primary Storage(第一儲存區) cache、RAM記憶體
- Non-volatile Data
- Secondary storage (Hard Disk)
:::
:::warning
### **Characteristics of Digital Evidence**

- Admissible 可採證性 (related to the fact)
- Authentic 真實性
- Complete 完整性 (integrity)
- Reliable 可靠性 (no doubt)
- Believable 可信度 (clear, understandable)
- 比如在專業議題上給與專業建議使人相信
:::
:::success
### **Sources of Potential Evidence**

- 使用者建立的檔案(User-Created Files使用者陳述)->基本上不成證據
- 資料庫
- 影音
- 檔案
- 網路書簽以及我的最愛
- 使用者保護的資料(User-Protected Files使用者保護檔案)
- 加密檔案(有加密技術問題)(找密碼找key金鑰)
- 壓縮檔案
- 更名檔案
- 密碼保護檔案
- 隱藏檔案
- 影像加密檔案
- 電腦創造的資料(Computer-Protected Files電腦產生證據)
- 原則上成證
- 但凡有原則必有例外
- ISO 27001→CEH會考
:::
:::info
### Rules of Evidence
- 在中華民國就跟刑事訴訟法有關
- 列出所有跟證據有關的法律要求(偏向原則性)
- 不符合就不構成證據
- Best Evidence Rule 最佳證物法則
- Prevent alteration of digital evidence(intentionally or unintentionally)
- 證據最重要的就是完整性
- 除以下三種條件外,須交付原始證據
- Original evidence is destroyed due to fire and flood
- Original evidence is destroyed in the normal course of business
- Original evidenceis in possession ofa third party
- FROE(Federal ROE) 聯邦證物法則 (考呦)
- Hearsay Rule 傳聞證據法則
Rule 803-6. Hearsay Exceptions(傳聞是不成證明的)
:::
:::success
### Privacy Issue
- Fourth Amendment(第四修正案)
- a person has a reasionable expectation of privacy
- 人具備對自我隱私的合理期待,不可受到無令的搜索
- 例外:private intrusions (私人入侵)->徵信社(找到證據比罰點錢還重要)
- 第四修正案局限在政府等公權力
- 第五修正案→人不需要證明己罪
:::
:::warning
### 電腦鑑識相關資源
- [線上資源](https://www.dropbox.com/s/hhenumw0w2jqfyn/Computer%20Forensics%20Resources.txt?dl=0)
- Forensics Sciences
- ForensicsWiki (ex. data carving)
- Forensics Focus
:::
## Module 02 Computer Forensics Investigation Process
鑑識流程
:::info
### Phase 1 - pre-investigation 建置鑑識調查的實驗室(6)

- 1.規劃及預算
- 2.地理位置和建築結構的考量

- 3.辦公環境規劃(Ambience of Lab)
- 4.實體安全
- 鑑識實驗室(one entrance 單一出入口)
- 窗戶緊閉
- 訪客登記
- 電子紀錄
- 警報系統
- 警衛
- 閉路電視 Closed-Circuit Camera
- 消防
- 氣體式滅火 Gas Suppression Systems(**FM200**)
- 灑水滅火 Water Suppresion Systems
- 濕管
- 乾管
- 預動式→火災發生當下才動
- 鎖具(保護證據)
- 稽核(Audit)
- 5.人員管理
- 6.建置鑑識工作站→實驗室認證
- ISO/IEC 17025 認證
- 一般的實驗室也在這個認證範疇
- ASCLD/LAB 認證
- ASCLD for人
- ASCL LAB for實驗室
- 鑑識實驗室
:::
:::danger
#### Forensic Laws
- 18 USC §1029 : **Fraud** and related activity in connection with **access devices**
- 18 USC §1030 : Fraud and related activity in connection with **computers**
#### Quality Assurance
- QC (Quality Control) 品質管制
- QA (Quality Assurance) 品質保證→有效性/信心
- validity testing
- 調查報告 Investigative reports must be under administrative
- technical review
- NIST(National of Standards and Technology美國國家技術研究院) 驗證工具有效性 - CFTT(Computer Forensics Tool Testing Project)工具的可用性
#### Management System
- Certification(驗證)
- 規格
- 要求
- Accreditation(認證)→認可 (考試會考喲)

- ISO/IEC 17025 認證
- 一般的實驗室也在這個認證範疇
- ASCLD/LAB 認證
- ASCLD for人
- ASCL LAB for實驗室
- 鑑識實驗室
#### Data Destruction 資料銷毀程度
- American : DoD 5220.22-M
- German : VSITR
- 寫0寫1寫亂數
#### Risk Management Matrix

:::
:::success
### Phase 2 - Investigation(6)
- 調查要點
- 設定目標 → Hypothesis 假設 → 設計實驗 → 選擇工具 → 評估結果 → 做結論

- First Response 緊急應變
- First Responder
- network administrator
- law enforcement officer
- investigating officer
- Role of First Responder
- 保留可揮發性證據
-
- Incident

- System administrator 網管人員
- Report according to the current organizational incident reporting procedures
- Non-forensic Staff 執法人員
- 證據保存
- Lab Forensic Staff 鑑識人員
- 事件釐清
- Common Mistakes
- 關機又開機(關了就關了,不要再打開)
- 假設電腦設備式穩定可用的
- 不按照標準作業流程
- 沒有紀錄採證流程
- Search and Seizure 搜索與扣押
- Electronic Storage Device Search Warrant
- hardware
- software
- storage device
- documentation
- Service Provider Search Warrant
- service records
- billing records
- subscriber information
- Searches Without a Warrant
- 現行犯
- 逮捕
- Collect the Evidence 資料採證
- 實體證據

- Dealing with Computers
- 開機的電腦
- 在行動前請三思
- 記憶體採證(困難,沒技術),可以改找pagefile和swapfile
- 如果電腦在螢幕保護程式,要慢慢移動滑鼠去執行動作,並拍照記錄畫面
- 關機的電腦
- 如果是電腦關著就不要打開
- 如果是螢幕關著,把螢幕打開,輕輕移動滑鼠
- 幫螢幕拍張照
- 切斷網路(視情況,測錄封包)
- Shutdown
- Unplug the power cord
- 直接斷電
- 筆電拔電池
- Secure the Evidence 證據保留
- **Chain of Custody**
-> 搜索
-> 扣押
-> 運送
-> 存放
-> 分析 的過程中證據未被變動,每個環節都要記錄
- For 證據的完整性
- Exhibit Numbering 編號

- aaa 鑑識人員編號
- ddmmyy 日期
- nnnn 序號
- zz 流水號
- Data Acquistion 資料擷取
- Principle

- Copy Data Procedure

- Original Evidence (封存)
- Tool#1 -> Working Copy (作業用)
- Tool#2 -> Backup Copy (還原用)
- Verify Image Integrity
- Tools: HashCalc, MD5 Calculator, HashMyFiles
- Data Analysis 資料分析
:::
:::warning
### Phase 3 - Post-investigation(3)

- Evidence Assessment 證據評估
- Documentation and Reporting
- Testify as an Expert Wutness
:::
## Module 03 Understanding Hard Disk and File Systems
瞭解硬碟以及檔案系統
:::danger
### 磁碟機
- Overview
- HDD 傳統硬碟
- SSD 固態硬碟
- NAND-based flash memory
- Volatile RAM
- Physical Structure of a Hard Disk

- Platters 圓盤
- Head 讀寫頭
- Spindle 轉軸

- Cylinder 圓筒(每個盤面同一位置的磁軌)
- Track 磁軌
- Cluster 叢集(最小邏輯儲存單位)
- Sector 磁區(最小實體儲存單位)

- Logical Structure of a Hard Disk

- Interface 硬碟介面
- | 串列 | 序列 |
| --- | ---|
| ATA | Serial ATA(SATA)|
| SCSI | Serial Attacked SCSI|

- USB

- Fibre Channel
- point to point, bidirectional, high speed(16 Gbps)

- Units
- Tracks
- 圓盤上的同心圓

- Sector
- Smallest **physical** storage unit
- 通常大小為 512 bytes
- AF(Advanced Format)格式 4096 bytes
- 一個Sector裡會有一些額外的資訊
- ID Information
- Synchronization fields
- Data
- ECC: Ensure the integrity
- Gaps: Spaces used to provide time for the controller to continue the read process

- Clusters

- Parted 愈大 Cluster 愈大
- NTFS為什麼有效率?
- Ans:格式化當下,Cluster大小可以跟Parted大小可以分開
- Slack Space 已配置的空間中剩下的部分

- Lost Clusters
- OS視為已用但實際上並沒有存放data
- Logical Structure Error
- Usually because of interrupted file activities
- CHKDSK (Windows指令,用來尋找遺失Clusters,修正邏輯錯誤)
- Bad Sectors OS標示為故障(unusable)的磁區,作業系統不會檢查,放病毒!!!
- Bit, Nibble(4 bits), Byte(8 bits)
- Data Addressing
- CHS(Cylinder-Header-Sector)
- used on most IDE drives
- LBA(Logical Block Address) 把磁區用序號編碼
- used on SCSI and EIDE drives
- Data Density
- Track density
- Areal density
- Bit density
- zoned bit recording(ZBR)
- 讓磁碟空間更有效運用
-磁區切割為扇形,相同面積下可以塞較多資料
- Capacity

- IEC Standard
- 1kibi = 1024
- 1k = 1000

:::
:::success
### 分割區(裏面不同的空間)
- 分割系統(支援不同firmware)
|分割系統 | MBR|GPT|
|:----: |:---:|:---:|
|韌體類型 | BIOS | EFI/UEFI |
|可分割數量 | 4 | 128 |
- MBR Partition System
- Primary Partition(4)
- Extended Partition(1,Logical drive(infinite))
- (Disk Editor 去看)
> dd 指令
> - if=src
> - of=dst
>

- MBR Code: 一小段碼,在系統開機時load 進BIOS
- Table of Primary Partitions(4x16=64bytes)

- 0x00
- 0x01-0x03 : First Sector 起始磁區(CHS)
- 0x04 : 分割區類型(檔案系統ID, e.g. 07=IFS/HPFS/NTFS/exFAT)
- [Partition Type wiki](https://en.wikipedia.org/wiki/Partition_type)
- 
- 0x05-0x07 : Last Sector 結束磁區(CHS)
- 0x08-0x0B : First Sector - Logical block address(LBA)
- 0x0C-0X0F : 分割區長度(4bytes=32bits → 定址上限 2^32^ = 40億 Sectors)
- MBR Signature (0xAA55)
> **Big Endian**(0xAA55): High byte → Low byte (RISC: ARM)
> **Little Endian**(0x55AA): Low byte → High byte (CISC: x86)
- PBR/VBR 記載磁碟資訊

- GPT Partition

> GUID(Global Unique Identifier)
- 128bits unique reference numbers → 32 hex numbers
- LBA0 放 protective MBR → Sector 0 會保留下來(為了相容MBR)
- GPT Header(512 bytes)

- GPT Entry(128 bytes)

## [LAB 1 - Disk Editor](https://hackmd.io/j9GzjYJlR6GmozF6sNtEWQ?view#LAB-1-Disk-Editor)
一個磁區512byte,offset=磁區 x 512bytes
- HPA(Hosted Protected Area)/DCO(Device Configuration Overlays) [HPA wiki](https://zh.wikipedia.org/wiki/%E4%B8%BB%E6%9C%BA%E4%BF%9D%E6%8A%A4%E5%8C%BA%E5%9F%9F)
- 電腦廠商不希望user開啓但需要存在的隱藏磁碟區(HPA/DCO)
:::
:::warning
### 開機流程
- ==Types of Booting==(Important)
- Cold → start from poweroff
- Warm → restart a poweron computer
- Windows Boot Process
- BIOS-MBR

- cmd(系統管理員) → bcdedit 可查看及修改Windows參數
- SMSS.EXE → GUI
- UEFI

- GPT Artifacts
- Case1: MBR repartitioned/ Convert to GPT → Sector Zero will be overwrite by protective MBR 得直接去磁區裡找資料
- Case2: GPT repartitioned/ Convert to MBR → remain
- Linux Boot Process

- OS (User/kernel/Bootloader) → FN → HW
:::
:::info
### 檔案系統 File System (基於功能去裝潢)
#### Windows File System
- File Allocation Table (以文字檔存資料)
- FAT12 → FAT16 → FAT32 → exFAT(FAT64)
- PBR/VBR → FAT1 → FAT2 → DATA叢集 (FAT2為FAT1備份)
- Partition Boot Record(PBR)


Metadata->後設資料(檔名、屬性、大小)
- Root Directory Entry
- 一筆 32 bytes


- offset 0x00: 0x00 or 0xE5(rename or delete)
- rename 流程: Copy 檔案紀錄到新的檔案紀錄,原檔案紀錄標示E5
- permanently delete(shift + delete): 標示E5
- delete(delete) = 把檔案移到垃圾筒(move)
- FAT undelete
- 1.修好FAT表 > 2.改Root Directory Entry(檔名要是大寫)
- 檔名的第一個字救不回來
- offset 00-10 (11bytes): 記錄短檔名(8+3)
- 長檔名設有短檔名 (8+3檔名: 檔案前六個字 + ~(數字) + 副檔名)
- cmd: dir /x 顯示短檔名
- 儲存長檔名


## [LAB 2 - FAT File Undelete](https://hackmd.io/j9GzjYJlR6GmozF6sNtEWQ?view#LAB-2---FAT-File-Undelete)
- New Technology File System (類似非結構式資料庫)
- 特色
- performance - reliability,disk space utilization
- file system journaling 日誌式
- 叢集大小不必跟分隔區成正比 → NTFS較有效率的原因
- System Files
- OS <-> NTFS <-> Disk


- $logfile : 日誌
- $mft(Master File Table) $mftmirr : Directory Entry(Contain the record of every files)

- 磁區開頭為FILE0(每兩個磁區出現一次FILE0)
- 一筆mft紀錄大小為1K
- B-Tree Structure
- flags:

- in use 檔案是否存在
- Directory
- $10 : Standard Information(time stamp 時間戳記 → MAC (Modify/Access/Create)/Record Change
|檔案系統| 修改 | 存取 | 建立 | Record Change |
|:----:|:---:|:---:|:---:|:---:|
|FAT|M|A|C|n/a|
|NTFS|M|A|Born|C|

- $30 : File Name

- 可存在超過一個檔名(短檔名、完整檔名)
- $80 : Data

同一檔案名稱可以放一個以上的資料
- Alternate Data Streams(ADS)
- notepad hihi.txt:yy.txt
- hihi.txt
- yy.txt
- ...
- 兩筆$80
- dir /r
- $100 : Encryption
- EFS Attribute

- 小檔案

- Data 會存在 MFT 裡,所以Size on disk = 0


- 多塞幾個A

- 壓縮與加密
- 檔案壓縮(藍色) -> 為磁區層級的分片以及重新編碼##
- 檔案加密EFS(綠色) -> 為磁區層級的加密,從磁區存取時是密文
- Sparse File 微量檔案
#### Linux File System
- File System Hierarchy Standard(FHS)

- /bin 必要指令
- /sbin required for working
- /usr Secondary hierarchy for read-only user data
- /opt 最不需要、額外的應用程式
- Extended File System(EXT2、3、4)
- EXT2 File System (一般的傳統檔案系統)
- Block Group

- Block bit map → Data blocks
- Inode bit map → Inode table
- EXT3 File System (日誌式)
- journaling version(EXT3~)
- EXT4 File System
- 增強版EXT3
#### MAC OS X File Systems
- Categories
- Hierarchical File System (HFS)
- **HFS Plus**
- Journal based
- UNIX File System (UFS)
- APFS -> SSD唯一的選擇
- ZFS
#### CD-ROM/DVD
- File System
- Compact Disc File System (CDFS)
- Universal Disk Format (UDF)
- ISO 13490 with multisession support(音軌+資料軌並行)
- VFS
#### RAID
- RAID 0

- for I/O performance
- does not provide data redundancy
- minimum two drives
- RAID 1

- Mirroring(備份用)
- two disks are identical
- 成本高
- RAID 2(無於商業環境實踐過)

- Error Connecting codeECC
- RAID 3

- data stripping and dedicated parity
- **Byte Level**
- 可容錯
- RAID 4
- 跟RAID 3一樣(差在不同level)
- **Block Level**
- 效能較RAID 3好
- RAID 5

- 每次寫入時parity disk都會換人當
- RAID 10 or Mirrored Striping
- 兩個RAID 1 做 Mirrored Striping
### HPA/DCO
資料隱藏
:::
:::warning
### 檔案系統分析 [HxD](https://mh-nexus.de/en/downloads.php?product=HxD20)
- 編碼
- ascii
- unicode
- Byte Order Mark(FE FF)
- Little Endian

- Big Endian

- UTF-8 (EF BB BF)

- UTF16
- BOM是微軟系統特有,歷史共業
- File Carving
- recover files and fragments of files
- 不需紀錄(無法得到,記錄在磁碟中其他位置) 暴力解
- File 結構
- Start : [**File Signature**](https://www.garykessler.net/library/file_sigs.html)(Magic Number)
- Header
- Data
- End : Trailer
- Trailer address - File signature address + 1 = File size(可利用來找到整個檔案的内容)
- Tool : [**Photorec**](https://www.cgsecurity.org/wiki/PhotoRec)
- 支援一百多種檔案類型
- free / whole
## [LAB 3 - File Carving](https://hackmd.io/j9GzjYJlR6GmozF6sNtEWQ?view#LAB-3---File-Carving)
## [LAB 4 - PhotoRec](https://hackmd.io/j9GzjYJlR6GmozF6sNtEWQ?view#LAB-4---Photorec)
## [LAB 5 - Honeynet_Q](https://hackmd.io/j9GzjYJlR6GmozF6sNtEWQ?view#LAB-5---Honeynet_Q)
### 檔案格式 (Hex 檔頭)
- JPG (FF D8 FF ... FF D9)

- BMP (42 4D)

- GIF (47 49 46 38)

- 256 colors
- PNG (89 50 4E 47) - 為取代GIF TIFF

- word
- Binary File format
- .doc**x**, .ppt**x** -> **X**ML in zip(PK)
- Remove ReadOnly Setting

- [File signatures](https://www.garykessler.net/library/file_sigs.html)
- tools :
- Autopsy (framework 等級的鑑識工具)
- The Sleuth Kit (+介面 => Autopsy)
:::
## [Module 04~06](https://hackmd.io/-PS9hnBOTc6wo-sz5RolKQ?both)
# **聊天室**
>-------------------------------------------------
>第二天要開始了
>唐牛想多了
>開始鄙視
>恆逸教office的老師表示
>3.47秒...
>以分鐘為單位 哈哈
>承憲挑戰以小時為單位
>他挑戰的應該是別的
>老師懂的
>他練習很久了
>真好,有練習的對象
>玄學
>真的是玄學
>他發現國軍的操作了
>蕭蕭都可以去資電部
>當然是玄學
>好酸啊 XD
>我只聽過LBJ
>LBJ 劉寳捷
>唐牛逼
>唐牛怒了
>
>------------------------------------------------------
>糟了 不懂[**凱燕**](https://autos.udn.com/autos/story/7825/3068237)是啥車
>原來是porsche
>10 km /l
>還好嘛
>https://www.ettoday.net/news/20180119/1096737.htm
>買不起凱燕可以買眾泰
>漫威宇宙都來了
>黑鳳凰
>畫面帶一下哦
>開嘴
>看到鬼
>我笑了
>—————————————————
>歐巴馬
>混音高手唐牛
>哈哈
>開始嘴了
>JJ
>selfie
>還真講不出來
>老唐又開始了