2023年11月20日 星期一

[研究][ASP.NET]弱點掃描出現Clickjacking: X-Frame-Options header之解決

[研究][ASP.NET]弱點掃描出現Clickjacking: X-Frame-Options header(點閱綁架, User Interface redress attack, UI redress attack, UI redressing)

2023-11-09

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

弱點名稱:Clickjacking: X-Frame-Options header(Clickjacking: X-Frame-Options header)

弱點中文名稱:點閱綁架, User Interface redress attack, UI redress attack, UI redressing)

風險等級:Low

弱點描述:Clickjacking (User Interface redress attack, UI redress attack, UI redressing) is a malicious technique of tricking a Web user into clicking on something different from what the user perceives they are clicking on, thus potentially revealing confidential information or taking control of their computer while clicking on seemingly innocuous web pages. 

The server did not return an X-Frame-Options header with the value DENY or SAMEORIGIN, which means that this website could be at risk of a clickjacking attack. The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page inside a frame or iframe. Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into untrusted sites.

弱點中文描述:點閱綁架是一種惡意的攻擊手法,藉由偽裝的網頁圖形介面,誘使使用者點擊表面上無害的網頁,使得攻擊者可能可以控制受害者的電腦或取得機密資訊。

建議修補方式:Configure your web server to include an X-Frame-Options header and a CSP header with frame-ancestors directive. Consult Web references for more information about the possible values for this header.

建議修補方式中文:設定網頁伺服器,以增加X-Frame-Options的HTTP標頭欄位以及於CSP標頭中增加frame-ancestors 屬性。

參考資料:

The X-Frame-Options response header
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

Clickjacking
https://en.wikipedia.org/wiki/Clickjacking

OWASP Clickjacking
https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html

Frame Buster Buster
https://stackoverflow.com/questions/958997/frame-buster-buster-buster-code-needed

參數資訊

Paths without secure XFO header:

https://xxx.xxx.xxx.xxx/.htpasswd

https://xxx.xxx.xxx.xxx/DocumentFile/.htpasswd

https://xxx.xxx.xxx.xxx/fonts/.htpasswd

https://xxx.xxx.xxx.xxx/Content/DataTables/css/.htpasswd

https://xxx.xxx.xxx.xxx/logs/.htpasswd

https://xxx.xxx.xxx.xxx/Scripts/babel-polyfill/7.2.5/.htpasswd

https://xxx.xxx.xxx.xxx/Content/themes/base/.htpasswd

https://xxx.xxx.xxx.xxx/Content/DataTables/.htpasswd

https://xxx.xxx.xxx.xxx/Account/.htpasswd

https://xxx.xxx.xxx.xxx/Content/themes/.htpasswd

https://xxx.xxx.xxx.xxx/Scripts/babel-polyfill/.htpasswd

https://xxx.xxx.xxx.xxx/Content/.htpasswd

https://xxx.xxx.xxx.xxx/Scripts/http-vue-loader@1.4.0/src/.htpasswd

https://xxx.xxx.xxx.xxx/Scripts/.htpasswd

https://xxx.xxx.xxx.xxx/Scripts/http-vue-loader@1.4.0/.htpasswd


測試語法

GET /.htpasswd HTTP/1.1

Referer: https://xxx.xxx.xxx.xxx/

Cookie: __AntiXsrfToken=32efd5d9624c49e9bc1ead9e0bad97e5; ASP.NET_SessionId=an1dxf4hybm0dswzsgaaxx0m

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Encoding: gzip,deflate,br

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

Host: xxx.xxx.xxx.xxx

Connection: Keep-alive

********************************************************************************

User

ASP.NET WebForm 網站如何防護 弱點掃描出現Clickjacking: X-Frame-Options header ?

ChatGPT

防護 Clickjacking 攻擊通常需要使用 HTTP 標頭來禁止網站在嵌入的框架中顯示,而 X-Frame-Options 標頭正是用於這個目的的。透過設定 X-Frame-Options,你可以指定是否允許你的網頁在嵌入的 <frame>、<iframe>、<object> 或 <embed> 中顯示。

在 ASP.NET WebForm 中,你可以透過以下方式在 Web.config 中設定 X-Frame-Options:

<configuration>
<system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="X-Frame-Options" value="DENY" />
    </customHeaders>
  </httpProtocol>
</system.webServer>
</configuration>

這個配置的含義是,拒絕在嵌入的框架中顯示網頁,這有助於防止 Clickjacking 攻擊。其他可能的值還包括:

  • DENY: 是一種較為保守和廣泛適用的防護措施。
  • SAMEORIGIN: 允許在相同的網域中顯示。
  • ALLOW-FROM uri: 允許在指定的 URI 中顯示。

選擇適當的值取決於你的應用程式需求。將 X-Frame-Options 設置為 DENY 是一種較為保守和廣泛適用的防護措施。

確保在加入這樣的設定之前,你測試一下是否會對你的網站的正常功能產生任何負面影響,特別是如果你有使用嵌入式框架的功能。

********************************************************************************

User

如何測試 ASP.NET WebForm 網站是否對 Clickjacking: X-Frame-Options header 有防護 ?

ChatGPT

要測試 ASP.NET WebForm 網站是否對 Clickjacking 有防護,主要的方法是檢查網站的 HTTP 響應標頭,確保是否存在 X-Frame-Options 並且它的值是符合預期的。

以下是一些步驟,你可以進行測試:

1.使用開發者工具檢查 HTTP 響應:

使用瀏覽器的開發者工具,瀏覽到網站,並檢查網站的 HTTP 響應標頭。

在 Network 部分查看相應的 HTTP 頭部,確保存在 X-Frame-Options。

2.檢查 X-Frame-Options 的值:

確保 X-Frame-Options 的值符合你的預期設置。如果你希望完全禁止嵌入,則值應該是 DENY。

如果需要允許特定來源,請確保值是 ALLOW-FROM uri,其中 uri 是允許的 URI。

3.測試 Clickjacking 攻擊:

嘗試在網站中創建一個包含 <iframe> 元素的 HTML 頁面,嘗試將網站嵌入到這個 <iframe> 中。

應該收到與 X-Frame-Options 設置相關的錯誤,防止網站在框架中顯示。

4.使用網上提供的工具:

有一些線上工具可以用來測試網站的 Clickjacking 防護,這些工具通常會模擬攻擊來檢查網站的安全性。

5.手動測試:

手動測試不同的情境,例如使用不同的瀏覽器和裝置,以確保 X-Frame-Options 的設置在各種情況下都有效。

請記住,測試的結果可能會受到瀏覽器的支援情況影響。大多數現代瀏覽器都支援 X-Frame-Options 標頭,但還是應該進行全面的測試以確保安全性。如果你有使用其他安全性標頭(如 Content Security Policy),也應該一併檢查這些標頭的設置。

********************************************************************************

(下圖) 寫個小程式測試一下


(下圖) 某系統是設定為 SAMEORIGIN,但被弱掃工具判定有 Clickjacking: X-Frame-Options header 弱點。

(完)

相關

沒有留言:

張貼留言