經得起原始碼資安弱點掃描的程式設計習慣培養(六)_Path Traversal

 
接續前幾篇系列




https://spanning.com/blog/directory-traversal-web-based-application-security-part-8/


Path Traversal
為一種利用網站的安全驗證潛在缺陷(如傳遞特定字符串至文件應用程式接口)來列出伺服器目錄的漏洞利用方式。 
該攻擊手段的目的是利用存在缺陷的應用程式來獲得目標文件系統上的非授權訪問權限。


過去重大事件

遠通電收再度出包!eTag官網遭駭,民眾資料外洩

近期實際案例
中興保全Dr.ID 門禁考勤系統 - Path Traversal



近期遇到這項掃描報告要做改善


對斜線、反斜線及點符號做一個取代為空字串處理

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
//https://owasp.org/www-community/attacks/Path_Traversal
/// <summary>
/// 取代會導致Path Traversal的符號
/// </summary>
/// <param name="inputString"></param>
/// <returns></returns>
public static string RemovePathTraversalSymbol(string inputString)
{
	return inputString.Replace(@"\", "").Replace(@"/", "").Replace(@"..", "");
}

通常跟File System有關操作的函數(Delete,Copy,Exists)只要傳入參數來自client
串過來的檔案名稱都很容易報錯
可能dropdownlist , textbox ,  FileUpload的FileName
每個都設置

也可能出現在DataRow , DataTable某個column 對應cell值
當你在都file path路徑時候經常容易報這塊風險











Ref:
Path Traversal

Checkmarx Path Traversal 的解法

[交戰守則] 避免造訪路徑攻擊 (Path Traversal Attack),免得成為下一個遠通電收


[ASP.net MVC/資安] 如何防範Path Traversal目錄瀏覽漏洞


[Checkmarx掃描漏洞處理] - Path traversal


How to prevent Path Traversal in .NET

From Path Traversal to Source Code in Asp.NET MVC Applications



留言

這個網誌中的熱門文章

經得起原始碼資安弱點掃描的程式設計習慣培養(五)_Missing HSTS Header

經得起原始碼資安弱點掃描的程式設計習慣培養(三)_7.Cross Site Scripting(XSS)_Stored XSS_Reflected XSS All Clients

(2021年度)駕訓學科筆試準備題庫歸納分析_法規是非題