# LAB - TLS版本會不會影響到SMB連線
## 環境
- Server (VM)
OS: Windows Server 2008 R2(Hypervisor -> VMware Workstation 17)
關閉:TLS 1.0, 1.1
開啟:TLS 1.2
IP: 192.168.0.135
- Client1(VM2)
OS: Windows Server 2012R2(Hypervisor -> VMware Workstation 17)
關閉:TLS 1.0, 1.1
開啟:TLS 1.2
IP: 192.168.0.134
- Client2(Host)
OS: Windows 11
協議根據狀況調整,無預設情況
IP: 192.168.0.111
---
## LAb規劃
### 註冊表設定
- Clinet 設定: 僅修改Client 設定
1. SSL設定
註冊表路徑:
`HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\`
底下新增`Key` <各SSL版本>,接著新增`key`<Client>並新增`DWORD(32bit值)`
:::info
- DisabledByDefault: `0` or `1`
- Enabled: `0` or `1`
:::
> DisabledByDefault -> 默認下為禁用
> Enabled -> 啟用
示意圖:

2. SMB設定
註冊表路徑:
`HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters`
:::info
新增<SMB1,2,3>
修改值`1`(啟用)或`0`(關閉)
:::

- Server 設定: 僅修改Server 設定
1. SSL設定
註冊表路徑:
`HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\`
底下新增`Key` <各SSL版本>,接著新增`key`<Server>並新增`DWORD(32bit值)`
:::info
- DisabledByDefault: `0` or `1`
- Enabled: `0` or `1`
:::
> DisabledByDefault -> 默認下為禁用
> Enabled -> 啟用

2. SMB設定
註冊表路徑:
`HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters`
:::info
新增<SMB1,2,3>
修改值`1`(啟用)或`0`(關閉)
:::

---
### SMB 環境
- 在Server 上建立Folder共享
- 命名為testSMB和SMBTEST
示意圖:

---
### 操作的指令或路徑
1. 基本網路檢查
```
cmd
ping <目標IP address>
ipconfig
```
下可略
2. 檢查SMB開啟的版本
```
powerSHell
Get-SmbServerConfiguration
Get-SmbClientConfiguration
```
上為Server, 下為Client
---
### 條件預設、交叉測試表以及測試
#### 1.預設條件
本段針對兩機器的預設設定做說明。
- TLS:
Assume:
- Client端: 預設啟用 TLS 1.2 和 TLS 1.3, 其他禁用(啟用Client)
- Server端: 預設啟用 TLS 1.2 其他禁用(啟用Server)
- SMB:
Assume:
- Client端: 預設啟用SMB2, 關閉SMB1
- Server端: 預設啟用SMB2, 關閉SMB1
- 參考圖:
- Client:
- TLS:


- SMB:

- Server:
- TLS:

- SMB:

#### 2. 交叉測試表
##### 2-1 第一次測試
i. 以Windwos 2012R2(Client)和 Windows 2008R2(Server) 做比較
| null | SMBv1 | SMBv2 | SMBv3 | TLS1.0 | TLS 1.1 | TLS 1.2 | case|
| ------------ | ----- | ----- | ----- | ------ | ------- | ------- | --- |
| LAB-1 Server | x | ✓ | x | x | x | ✓ |case1|
| LAB-1 Client | x | ✓ | ✓ | x | x | ✓ |case1|
| LAB-2 Server | x | ✓ | x | x | x | ✓ |case2|
| LAB-2 Client | x | ✓ | x | x | x | ✓ |case2|
| LAB-3 Server | x | ✓ | x | x | x | ✓ |case3|
| LAB-3 Client | x | x | ✓ | x | x | ✓ |case3|
| LAB-4 Server | x | ✓ | x | x | x | ✓ |case4|
| LAB-4 Client | ✓ | x | x | x | x | ✓ |case4|
| LAB-5 Server | x | ✓ | x | x | x | ✓ |case5|
| LAB-5 Client | x | ✓ | ✓ | ✓ | ✓ | ✓ |case5|
| LAB-6 Server | x | ✓ | x | x | x | ✓ |case6|
| LAB-6 Client | x | ✓ | ✓ | x | ✓ | ✓ |case6|
| LAB-7 Server | x | ✓ | x | x | x | ✓ |case7|
| LAB-7 Client | x | ✓ | ✓ | ✓ | x | ✓ |case7|
| LAB-8 Server | x | ✓ | x | x | x | ✓ |case8|
| LAB-8 Client | x | ✓ | ✓ | ✓ | ✓ | x |case8|
| LAB-9 Server | x | ✓ | x | x | x | ✓ |case9|
| LAB-9 Client | x | ✓ | ✓ | x | x | x |case9|
| LAB-10 Server | x | ✓ | x | x | x | ✓ |case10|
| LAB-10 Client | x | ✓ | x | x | x | x |case10|
| LAB-11 Server | x | ✓ | x | x | x | ✓ |case11|
| LAB-11 Client | ✓ | x | x | x | x | x |case11|
| LAB-12 Server | x | ✓ | x | x | x | ✓ |case12|
| LAB-12 Client | x | x | x | x | x | x |case12|
| LAB-13 Server | ✓ | x | x | x | x | ✓ |case13|
| LAB-13 Client | x | x | x | x | x | x |case13|
| LAB-14 Server | x | x | x | x | x | ✓ |~~case14~~|
| LAB-14 Client | x | x | x | x | x | x |~~case14~~|
| LAB-15 Server | ✓ | ✓ | x | x | x | ✓ |case15|
| LAB-15 Client | x | x | x | x | x | x |case15|
| LAB-16 Server | ✓ | ✓ | x | x | x | ✓ |case16|
| LAB-16 Client | ✓ | ✓ | ✓ | x | x | x |case16|
| LAB-17 Server | ✓ | ✓ | x | x | x | ✓ |case17|
| LAB-17 Client | ✓ | ✓ | x | x | x | x |case17|
| LAB-18 Server | ✓ | ✓ | x | x | x | ✓ |case18|
| LAB-18 Client | ✓ | x | x | x | x | x |case18|
| LAB-19 Server | ✓ | ✓ | x | x | x | ✓ |case19|
| LAB-19 Client | x | ✓ | x | x | x | x |case19|
| LAB-20 Server | ✓ | ✓ | x | x | x | ✓ |case20|
| LAB-20 Client | x | x | ✓ | x | x | x |case20|
| LAB-21 Server | ✓ | ✓ | x | x | x | ✓ |case21|
| LAB-21 Client | x | x | ✓ | x | x | ✓ |case21|
...etc
- 通過:`case1`, `case2`, `case3`, `case4`, `case5`, `case6`, `case7`, `case8`, `case9`, `case10`, `case11`, `case12`, `case13`, `case15`, `case16`, `case17`, `case18`, `case19`, `case20`, `case21` ...etc
:::success
進行到LAB-12以後,推斷可能出錯的情況會出現在Server端修改上
特別提一下,`case12`, `13`, `15`算特殊情況,關閉了SMB但仍能連線,代表他是依靠不同協議進出的,詳細可以看`ii.`和`iii.`的操作。
:::
- 錯誤:`case14`
:::danger
`LAB-14`會出錯是必然,與TLS部分一點關係都沒有,因為測試關閉了SMBv1, SMBv2
:::
ii. 設定Windows Server 2008R2防火牆
進入到`Windows firewall Whih advanced security` -> `inbound` -> `File and printer sharing(SMB-In)`Profile是Public -> `Action` 設定為`Block the connection`


設定完以後利用開起虛擬機主機的Windows 11(Client2)進行Debug及測試,測試完畢後回推資訊到Client1繼續進行LAB
(case22)
:::info
Windows 11
SSL:開啟TLS 1.2, TLS 1.3;TLS 1.1及其之下版本皆禁用
SMB:開啟SMB2, SMB3, 禁用SMB1
Windows 2008R2
SSL:開啟TLS 1.2, TLS 1.3;TLS 1.1及其之下版本皆禁用
SMB:開啟SMB1, 開啟SMB2
:::
結果如圖:


結果可以發現連不上。修改Windows Server 2008的規則
:::info
SSL:開啟TLS 1.1, 1.0, 禁用TLS 1.2
:::
結果仍舊相同,後續關閉Windows 11的TLS 1.2也沒有辦法連線,可以推斷**問題不是出在TLS版本上**
將`File and printer sharing(SMB-In)`設定為`允許連線`之後Winodws 11 則可以正常連線。

- 資訊推斷
由上面測試推斷,Windows 11可能只有依靠`Port 445`再進行檔案共享,如果`Port 445`關閉了,則無建立會議的手段,這些手段可能包括「較不安全」的網路協議,Microsoft可能會針對這些協議進行修改或刪除,例如SMB可能就單純交給SMB託管,不依靠其他手段連入。
接下來針對「其他手段」的部分反推向Client2,因為Windows Server 2012R2是一個比較舊的版本,這個版本可能會有一些不安全的網路協議,e.g Net-bios over TCP/IP
因此接下來會針對Net-bios進行測試。
iii. 將Net-bios 相關防火牆設定關閉
如題,將Net-bios相關設定以及SMB-In全部關閉先測試是否可以連線:


結果不行,因為137,138,139關閉後發現不行,因此針對不同情況做測試:
沒有寫`open`就是關閉
| 137/public | 137/domain | 138/public | 138/domain | 139/public | 139/domain | 能否連上 |
| ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | -------- |
| open | | | | | | 否 |
| | open | | | | | 否 |
| | | open | | | | 否 |
| | | | open | | | 否 |
| | | | | open | | 否 |
| | | | | | open | 否 |
| | | | | open | open | 否 |
| | | open | open | | | 否 |
| open | open | | | | | 否 |
| open | open | open | open | | | 否 |
| open | open | | | open | open | 是 |
| open | open | | | open | | 是 |
| open | open | | | | open | 否 |
| | open | | | | open | 否 |
| open | | | | open | | 是 |
| open | | | | | open | 否 |
| | open | | | open | | 否 |
| | | open | open | open | open | 是 |
| | | open | | open | | 是 |
.
.
.
.
.
| open | open | open | open | | | 否 |
| open | | open | | open | | 是 |
- 測試結果
經過測試並且最簡化配置可以連上的有:
:::success
1. `137(Public) + 139(Public)`
2. `138(Public) + 139(Public)`
3. `137(Public) + 138(Public) + 139(Public)`
:::
結果說明:當`Port 445`關閉後,Windows會利用NetBIOS(TCP/IP)進行連線;
`Port 139(TCP)`必須開啟,且至少需`Port 137(UDP)` or `Port 138(UDP)`中的一個配合才能成功連線。以上是為`NBT`的工作原理,連線需要`Port 139`,而名稱解析或瀏覽功能需要`Port 137` or `138`
- 修復連線參考圖,以`Port 137`和`Port 138`為例:


##### 2-2 第二次測試
由於第一次幾乎都測試通過,我決定用其他方式進行測試,在Client1做取消相依的測試
- 操作步驟說明:
接下來的步驟會依LAB表格的需求去輸入指令做調整,不一一演示,遇到SSL調整則與上一步相同。
- 依照LAB要求`停用驅動` or `修改 Workstation 的相依項目`
- SMB1 `停用驅動` +`清除關聯`
```
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\MRxSmb10" -Name "Start" -Value 4
```
```
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanWorkstation" -Name "DependOnService" -Value @("Bowser", "MRxSmb20")
```
- 停用SMB2/3(修改Workstation 的相依項目)
```
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanWorkstation" -Name "DependOnService" -Value @("Bowser")
```
- SMB1恢復
```
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\MRxSmb10" -Name "Start" -Value 2
```
- SMB2/3恢復(加回依賴設定)
```
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanWorkstation" -Name "DependOnService" -Value @("Bowser", "MRxSmb10", "MRxSmb20")
```
| null | SMBv1 | SMBv2 | SMBv3 | TLS1.0 | TLS 1.1 | TLS 1.2 | case|
| ------------ | ----- | ----- | ----- | ------ | ------- | ------- | --- |
| LAB-1 Server | x | ✓ | x | x | x | ✓ |case1|
| LAB-1 Client | ✓ | x | x | x | x | ✓ |case1|
| LAB-2 Server | x | ✓ | x | x | x | ✓ |case2|
| LAB-2 Client | x | ✓ | ✓ | x | x | ✓ |case2|
| LAB-3 Server | x | ✓ | x | x | x | ✓ |case3|
| LAB-3 Client | x | x | x | x | x | ✓ |case3|
| LAB-4 Server | x | ✓ | x | x | x | ✓ |case4|
| LAB-4 Client | x | ✓ | ✓ | ✓ | ✓ | x |case4|
| LAB-5 Server | x | ✓ | x | x | x | ✓ |case5|
| LAB-5 Client | ✓ | ✓ | ✓ | ✓ | ✓ | x |case5|
| LAB-6 Server | x | ✓ | x | ✓ | ✓ | x |case6|
| LAB-6 Client | ✓ | x | x | ✓ | ✓ | x |case6|
| LAB-7 Server | x | ✓ | x | x | x | ✓ |case7|
| LAB-7 Client | ✓ | x | x | ✓ | ✓ | x |case7|
| LAB-8 Server | ✓ | x | x | x | x | ✓ |case8|
| LAB-8 Client | x | ✓ | ✓ | ✓ | ✓ | ✓ |case8|
| LAB-9 Server | ✓ | x | x | ✓ | ✓ | x |case9|
| LAB-9 Client | x | ✓ | ✓ | ✓ | ✓ | x |case9|
| LAB-10 Server | ✓ | x | x | ✓ | ✓ | x |case10|
| LAB-10 Client | x | ✓ | ✓ | x | x | ✓ |case10|
| LAB-11 Server | ✓ | x | x | ✓ | ✓ | x |case11|
| LAB-11 Client | ✓ | x | x | x | x | ✓ |case11|
| LAB-12 Server | x | ✓ | x | x | x | ✓ |case12|
| LAB-12 Client | x | ✓ | ✓ | x | x | ✓ |case12|
| LAB-13 Server | x | ✓ | x | ✓ | ✓ | ✓ |case13|
| LAB-13 Client | x | ✓ | ✓ | ✓ | ✓ | ✓ |case13|
:::success
通過:`case2`, `case4`, `case5`, `case12`, `case13`
:::
:::danger
錯誤:`case1`, `case3`, `case6`, `case7`, `case8`, `case9`, `case10`, `case11`
note:`case1,3,6,7` 都是只有開SMB1 和 沒有開任何SMB之情況下才導致連線失敗的;`case8,9,10`則是狀況也相同。
:::
---
### Case 為成功連線之範例
1. 情境一:
- 情境範例:預設條件
參考「條件預設以及交叉測試」以及「註冊表」的修改範例,說明不針對細項修改提出圖片說明。
i. 測試連線是否正常
先測試是否在同一網段使用`ping <IP address>`確認。
ii. 檢查設定條件無誤
測試者前往註冊表查看,或者使用指令查詢
iii. 確定沒問題後,進行連線測試
連線沒有問題,`WRX`都正常

2. 情境二:防火牆未關閉`Port 445`
3. 情境三:Server防火牆未關閉Net-bios port
:::info
情境二、三結果與情境一相同,不再贅述。
:::
---
### Case 為失敗連線之範例
1. 情況一:
- 情境範例:關閉Server所有版本之SMB
- 說明:正常情形,不加以討論
2. 情況二:
- 情境範例:`Windows firewall Whih advanced security` 設定`File and printer sharing(SMB-In)`的Action為`Block the Connection`(Profile: Public)
- 說明:設定後,Client2 無法連線,Client1不關開關皆為正常連線
圖:`Windows firewall Whih advanced security` 設定`File and printer sharing(SMB-In)`的Action為`Block the Connection`


3. 情況三(關於Windows Server 2012R2)
- 情境範例:關閉`Port 445` 且將Net-Bios相關Port關閉,例如關閉`Port 137 + Port 139`, `Port 138 + Port 139`
- 說明:關閉Port 445後,Windows會使用Net-bios進行連線,若是使用者將137(138) 和 139都關閉的話,則無法使用SMB的連線
- 修補建議:檢查Server端的防火牆是否有將Net-bios 相關Port關閉,若有關閉請將其開放。詳細資訊請參考上面Lab內容。