Server-Side Request Forgery
弱點描述 SSRF(伺服器請求偽造)是一種由攻擊者在服務端發起的偽造的請求,一般攻擊的目標為無法透過外網存取的內部系統。 弱點根源 伺服器端未對請求URL進行過濾或過濾不完全。 SSRF 形成的原因大都是由於伺服器端提供了從其他服務器應用程式存取資料或執行應用程式的功能,同時沒有對目標地址做過濾與權限控管,像說透過指定的 URL 地址存取主機的資源、下載內部的資源…等等。 弱點利用 https: // URL /ssfr.php?url=file:/ /etc/ passwd 以偽造的請求 Payload 進行攻擊 掃瞄內網 Denial of Service 修改建議 設置 URL白名單或者限制允許存取的內網 IP <內網黑名單> 不提供"多餘存取"的功能 禁止不需要的協議,僅允許協議為 HTTP、HTTPS 對返回內容進行過濾,減少機敏內容暴露 建議解決方式: Compliant Solution using System.Linq; using System.IO; using System.Net; using Microsoft.AspNetCore.Mvc; namespace WebApplicationDotNetCore.Controllers { public class RSPEC5144SSRFCompliantController : Controller { public IActionResult Index() { return View(); } private readonly string[] whiteList = { "https://www.sonarsource.com" }; public IActionResult ReadContentOfURL(string url) { // Match the incoming URL against a whitelist if (!whiteList.Contains(...