# 如何修復IIS列舉 8.3filename 的風險
###### tags: `資安` `程式設計`
## 8.3 filename是什麼
8.3檔名是一種限制對檔案名稱的長度的方法,這在DOS和Microsoft Windows的Windows 95及Windows NT 3.5以前的版本中,在FAT檔案系統中的常用方法。在以前的CP/M及某些的通用資料和迪吉多微型電腦作業系統中使用。
8.3檔案名稱最多只可以含有8個字元,跟著最多3個字元的副檔名,利用『.』號將兩者連接起來。檔案及目錄名稱是全部使用大寫字母的。
### 問題點
IIS的短文件名機制,可以暴力猜測短文件名,當訪問的某個存在的短文件名,會返回404,訪問構造的某個不存在的短文件名,返回400。
### 使用 IIS Short Name Scanner 檢測
irsdl 有提供的以 java 語言寫的檢測程式碼
https://github.com/irsdl/iis-shortname-scanner/
如果有安裝 java 的話,在 windows 環境可以直接執行 run.bat ,輸入要檢測的網址後,一直按 enter 採用預設設定,就可以觀看結果了
輸入run.bat後,會看到類似的畫面
```
- Example 5 (using a new config file):
java -jar IIS_shortname_scanner.jar 2 20 http://example.com/folder/ newconfig.xml
Note 1: Edit config.xml file to change the scanner settings, for instance to add additional headers.
Note 2: Sometimes it does not work for the first time and you need to try again.
*****************************************************************
What is the target (e.g. http://localhost:8080/folder/)? https://localhost:10443 <--手動輸入的
Do you want to use a new config file [Y=Yes, Anything Else=No]?
Do you want to only verify whether or not the target is vulnerable without scanning it thoroughly [Y=Yes, Anything Else=No]?
Scan Mode [0=Show final results only, 1=Show final results step by step, 2=Show Progress (default)]?
Number of threads [0-50 (20 default)]?
```
### 檢測結果
如果有檢測到 8.3 filename的東西,Result 會顯示 Vulnerable,並且展示看到的檔案或資料夾,下面是展示就是找到 ASPNET~1 和 FORMRE~1 兩個 8.3 filename 的資料夾
```
# IIS Short Name (8.3) Scanner version 2.3.9 (05 February 2017) - scan initiated 2020/10/20 13:56:55
Target: https://localhost:10443/
|_ Result: Vulnerable!
|_ Used HTTP method: DEBUG
|_ Suffix (magic part): \a.aspx
|_ Extra information:
|_ Number of sent requests: 3534
|_ Identified directories: 8
|_ ASPNET~1
|_ FORMRE~1
```
## 應急處理方式
開IIS,把 要求篩選 的 http指令動詞 拒絕下面這幾個
```
OPTIONS
HEAD
PUT
DELETE
TRACE
CONNECT
```
### 要求篩選操作教學
https://dotblogs.com.tw/rainmaker/2013/12/09/133071
### http方法教學
https://hackmd.io/_E-JcoZyTp-C0I9Lt8yiGw?view
## 完整防護 關閉 8.3 filename 的機碼
### 修復方式
適用於 Windows Vista、Windows Server 2008、Windows 7、Windows Server 2008 R2、Windows 8 和 Windows Server 2012
若要停用所有的 NTFS 磁碟分割上的 8.3 名稱建立,請鍵入fsutil.exe 行為設定 disable8dot3 1在提高權限的命令提示字元],然後按 Enter 鍵。 這項作業會立即生效 (不需要的重新啟動)。 備忘稿 未指定磁碟區,此作業會更新登錄值:
0-系統上的所有磁碟區上啟用 8.3 名稱建立
1-停用系統上的所有磁碟區上的 8.3 名稱建立
2-每個磁碟區為基礎來設定 8.3 名稱建立
3-停用系統磁碟區以外的所有磁碟區上的 8.3 名稱建立
適用於 Windows Server 2000
新增以下機碼,類型為 REG_DWORD ,設定為 1 就不會產生8.檔名
HKLM\SYSTEM\CurrentControlSet\Control\FileSystem
接下來有兩個做法,兩者擇一即可
* 手動刪除原本的8.3 file
將資料夾的內容copy到另一個磁區,如˙把 c:\www copy到 d:\www , 然後刪除 c:\www 資料夾,再把 d:\www 搬回 c:\www
* 使用 fsutil 移除檔案
適用於 Windows Server 2019、Windows Server 2016、Windows 10、Windows Server 2012 R2、Windows 8.1、Windows Server 2012、Windows 8
若要在 D:\MyData 目錄和所有子目錄中移除8.3 檔案名,將資訊寫入指定為 mylogfile的記錄檔,請輸入:
```
fsutil 8dot3name strip /l mylogfile.log /s d:\MyData
```
## 參考來源
web中間件漏洞之IIS篇
https://kknews.cc/code/l3rjb4z.html
fsutil 8dot3name
https://docs.microsoft.com/zh-tw/windows-server/administration/windows-commands/fsutil-8dot3name
NtfsDisable8dot3NameCreation
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-2000-server/cc959352(v=technet.10)?redirectedfrom=MSDN
https://support.detectify.com/customer/portal/articles/1711520-microsoft-iis-tilde-vulnerability