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 注入的認證旁路javascript

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

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

// 關鍵字java

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

//關鍵字符sql

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

2.已解密的登陸請求瀏覽器

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

3.登陸錯誤消息憑證枚舉cookie

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

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

相關文章
相關標籤/搜索