IBM AppScan 安全漏洞問題修復(.net)


按問題類型分類的問題

  1. 使用 SQL 注入的認證旁路2
  2. 已解密的登錄請求3
  3. 登錄錯誤消息憑證枚舉1
  4. 會話標識未更新2
  5. 跨站點請求偽造1
  6. Missing "Content-Security-Policy" header 9
  7. Missing "X-Content-Type-Options" header 9
  8. Missing "X-XSS-Protection" header 9
  9. 查詢中接受的主體參數1
  10. 啟用了 Microsoft ASP.NET 調試2
  11. 缺少跨幀腳本編制防御1
  12. 已解密的 __VIEWSTATE 參數1
  13. 檢測到應用程序測試腳本1
  14. 應用程序錯誤9
  15. 整數溢出3

問題修復 

1.使用 SQL 注入的認證旁路

答: 登錄、注冊頁面輸入信息,過濾sql關鍵字或關鍵字符;

提交表單頁面、查詢頁面的輸入項,過濾sql關鍵字或關鍵字符。

// 關鍵字

string StrKeyWord = @"select|insert|delete|from|count\(|drop table|update|truncate|asc\(|mid\(|char\(|xp_cmdshell|exec master|netlocalgroup administrators|:|net user|""|or|and";

//關鍵字符

string StrRegex = @"[-|;|,|/|\(|\)|\[|\]|}|{|%|\@|*|!|']";

2.已解密的登錄請求

答:一種說法是使用SSL證書,暫時沒有解決。

3.登錄錯誤消息憑證枚舉

答:用戶登錄時,如果輸入錯誤的用戶信息,最好提示同一個錯誤消息提醒,比如:你的用戶名或密碼輸入錯誤。提供枚舉提示,容易被暴力破解。

4.會話標識未更新

答:登錄之后更改會話標識符,主要用於登錄頁面。

參考方案: http://www.2cto.com/Article/201302/190228.html 測試沒有效果

http://blog.itpub.net/12639172/viewspace-441971/ 測試ok

在登錄頁面,添加紅線加粗部分

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

Session.Abandon();

//清除SessionId

Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));

txt_Fileld1.Focus();

}

}

5.跨站點請求偽造

答:每個頁面請求時,判斷主機和端口與配置文件信息是否一致。

網上參考方法:

1,利用referer判斷,

但是用戶有可能設置瀏覽器使其在發送請求時不提供 Referer,這樣的用戶也將不能訪問網站。

2,在請求中添加 token 並驗證

關鍵在於在請求中放入黑客所不能偽造的信息,並且該信息不存在於 cookie 之中,

可以在服務器端生成一個隨機碼,然后放在form的hidden元素中,form提交的時候在服務器端檢查。

6.Missing "Content-Security-Policy" header

答: 在web.config 配置文件中添加如下響應頭

<system.webServer>

<httpProtocol>

<customHeaders>

<add name="X-Content-Type-Options" value="nosniff"/>

<add name="X-XSS-Protection" value="1;mode=block"/>

<add name="X-Frame-Options" value="SAMEORIGIN"/>

<add name="Content-Security-Policy" value="default-src 'self'"/>

</customHeaders>

</httpProtocol>

</system.webServer>

7.Missing "X-Content-Type-Options" header

答: 在web.config 配置文件中添加如下響應頭,添加節點見 第6 個問題

<add name="X-Content-Type-Options" value="nosniff"/>

8.Missing "X-XSS-Protection" header

答: 在web.config 配置文件中添加如下響應頭,添加節點見 第6 個問題<add name="X-XSS-Protection" value="1;mode=block"/>

9.查詢中接受的主體參數

答:未解決

10.啟用了 Microsoft ASP.NET 調試

答:應用程序發布后,修改配置文件節點compilation 的屬性 debug為 false。<compilation debug="false" targetFramework="4.0"/>

11.缺少跨幀腳本編制防御

答:在web.config 配置文件中添加如下響應頭,添加節點見 第6 個問題<add name="Content-Security-Policy" value="default-src 'self'"/>

注意,添加之后,可能會出現不同瀏覽器,出現兼容性問題,會有不同的反應。比如,極速模式會出現頁面內部css無效。

12.已解密的 __VIEWSTATE 參數

答:在web.config 配置文件中添加 pages 的屬性viewStateEncryptionMode 為Always。<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" viewStateEncryptionMode="Always" />

13.檢測到應用程序測試腳本

答: 在系統開發過程中,添加的測試頁面,在程序發布前需要“從項目中排除”后再發布。

14.應用程序錯誤

答:出現應用程序錯誤頁面。如 :Server Error in '/' Application.

一是解決屬於開發人員的應用程序錯誤問題,二是在配置文件添加默認出錯頁面

<customErrors mode="On" defaultRedirect="~/error.html" />15.整數溢出

答:情況一:針對請求的url中的參數, 檢查其數據類型及邊界范圍。

如 /ApplyShow.aspx?id=99999999999999999999

情況二:登錄頁面按鈕參數,在請求正文里,未找到原因???

http://localhost:83/login.aspx 實體: ImgbtnDl.y (Parameter)

16.WebResource.axd

WebResources.axd?d=xyz。WebResource.axd有一個特點,便是會對錯誤的密文(即d=xyz中的xyz)產生500錯誤,而對正確的密文產生404錯誤,這便形成了足夠的提示

參考資料:http://www.2cto.com/Article/201009/75162.html

http://pan.baidu.com/share/link?shareid=3851057069&uk=2164275402

http://www.cnblogs.com/JeffreyZhao/archive/2010/09/25/things-about-padding-oracle-vulnerability-in-asp-net.html

http://www.cnblogs.com/shanyou/archive/2010/09/25/1834889.html Padding Oracle Attack 檢測工具

解決方法: http://www.cnblogs.com/shanyou/archive/2010/09/24/1833757.html  中文版http://weblogs.asp.net/scottgu/important-asp-net-security- vulnerability   英文版

1.添加配置節點

.net 3.5 及以前版本,添加配置節點

<customErrors mode="On" defaultRedirect="~/error.html" />

.net 3.5 SP1 或 .net 4.0添加如下配置節點,注意加粗部分必須

<customErrors mode="On" defaultRedirect="~/error.aspx" redirectMode="ResponseRewrite" />

2.添加默認錯誤頁面

<%@ Page Language="C#" AutoEventWireup="true" %> <%@ Import Namespace="System.Security.Cryptography" %> <%@ Import Namespace="System.Threading" %> <script runat="server"> void Page_Load() {  byte[] delay = new byte[1];  RandomNumberGenerator prng = new RNGCryptoServiceProvider();  prng.GetBytes(delay);  Thread.Sleep((int)delay[0]);  IDisposable disposable = prng as IDisposable;  if (disposable != null) { disposable.Dispose(); }  } </script> <html> <head runat="server">  <title>Error</title> </head> <body>  <div>   An error occurred while processing your request.  </div> </body> </html> 

如果誰有更好的解決方法 ,謝謝提供!

 

轉載自:http://www.tuicool.com/articles/Ajqa2uj


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM