--- disqus: jpower --- # OWASP TOP10 Injection(Path traversal) ## 2 Path traversal while uploading files Q: 範例是上傳檔案的練習,嘗試將檔案上傳到預期外的路徑 A: 提示中可以發現檔案名稱會是Full Name ![](https://i.imgur.com/4NMlEFQ.png) 可以嘗試目錄遍歷方式跳脫 ``` ../test123 ``` ![](https://i.imgur.com/4fHTWf0.png) ## 3 Path traversal while uploading files Q: 範例一樣是上傳檔案的練習,這次會過濾 \.\./,嘗試將檔案上傳到預期外的路徑 A: 可以發現\.\./會被過濾掉,可以用雙寫繞過來嘗試目錄遍歷 ``` .../.../..//test123 ``` ![](https://i.imgur.com/M9VcMGy.png) ## 4 Path traversal while uploading files Q: 範例一樣是上傳檔案的練習,這次不使用Full name名稱來建立儲存路徑,嘗試將檔案上傳到預期外的路徑 A: 嘗試上傳,可以方現路徑似乎是使用檔案原本的檔案名稱。 ![](https://i.imgur.com/B8dclM4.png) 使用brupsuite修改filename ``` ../image.jpg ``` ![](https://i.imgur.com/hfFixvg.png) ![](https://i.imgur.com/wVsKcVW.png) ## 5 Retrieving other files with a path traversal Q: 利用目錄遍歷的方式檢視目錄下其他檔案 ![](https://i.imgur.com/w6R9WrM.png) A: 每次點擊Show random cat picture圖案都會隨機變一張,使用brupsuite開Repeater觀察。 ![](https://i.imgur.com/4COj4Gi.png) 可以看到圖片檔案名稱是由id決定的,嘗試在request的地方給予id值 ``` GET /WebGoat/PathTraversal/random-picture?id=1 ``` ![](https://i.imgur.com/Hy8Axce.png) 測試後可以發現id值與檔案名稱有關,因此可以嘗試在id值使用Path traversal。如果id空白不給值的情況下,可以看到response會列舉該目錄位置下所有的檔案(1~9.jpg) ![](https://i.imgur.com/oNWpjM5.png) 測試用 \.\./ 來Path traversal 會發現有阻擋機制 ![](https://i.imgur.com/uj7jR4G.png) 改用%2e%2e%2f 方式發現可以繞過 ![](https://i.imgur.com/WVXtnAc.png) ``` GET /WebGoat/PathTraversal/random-picture?id=%2e%2e%2f%2e%2e%2fpath-traversal-secret ``` ![](https://i.imgur.com/7Yi6DNF.png) 可以看到答案是username的SHA-512值 ![](https://i.imgur.com/HIziDiY.png) ## 7 Zip Slip assignment Q: 利用目錄遍歷的方式讓上傳的zip檔案可以解壓縮到指定的路徑 ![](https://i.imgur.com/C1TXfNd.png) A: 暫時解不出來 ###### tags: `webgoat`,`Injection`