- 取得連結
- X
- 以電子郵件傳送
- 其他應用程式
HP Fortify 是一款很優秀的弱點掃描,它是直接去「掃描程式碼」來告訴你可能的弱點在哪邊
關於範例程式碼:
使用 Visual Studio 2012 與 Net Framework 4.5 建立的 WebForm Web Application 應用程式,輸入檔案名稱後可以取得指定檔案名稱下的檔案內容。
範例程式碼可以在以下連結取得
FortifyPathManipulation on Github使用 HP Fortify 掃描後出現 "Path Manipulation" Critical 弱點

範例程式碼中,檔案名稱中輸入 "hyperlink.txt" 可以取得該檔案的文字內容


我們假設 hyperlink.txt 檔案是在網頁目錄下個某個資料夾中(這種狀況非常常見)

若輸入 "..\web.config" 的話 ...

點選 "Get File Content" 按鈕,可以獲得完整的 web.config 檔案的文字內容(真是太棒了!)

這就是 Path Manipuation 要告訴你的案例之一
本次解決方式
將來源路徑進行 String.Replace 加工移除異常的文字內容
但來源參數還是會回傳給讀取檔案的方法使用,Fortify 認為這樣還是有弱點,使用 Base64 加工路徑內容並使用 Dictionary 物件將 Base64 加密的結果逐筆字元的替換
網路上有人分享類似的方式但使用非英文字元會無法成功轉換,透過 Base64 就可以接受非英文字母的文字內容。
透過這種方式就可以讓 HP Fortify 不會出現 Path Manipulation 弱點,再次輸入 "..\web.config" 文字內容的時候已經被加工掉,所以會出現找不到檔案的訊息。


參考連結
- http://fortifyissue.blogspot.tw/2014/08/path-manipulation.html
- http://blog.xuite.net/locktime/blog/55593570-Path+Manipulation+-+Fortify+白箱測試工具
異動紀錄
- 2017/11/27 - 若路徑格式為 UNC 路徑需重新補上 "\\" 起始字串
留言
張貼留言