<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      在ASP中過濾用戶輸入 提高安全

      [摘要]安全對于所有應用程序來說都是十分重要的。一個簡單應用程序里的某個失誤都會造成對數據庫或者其他企業資源未經授權的訪問,因此安全尤其重要。一種常用的攻擊方法是將命令嵌入到用戶的回應里,而從用戶輸入里過濾...

      安全對于所有應用程序來說都是十分重要的。一個簡單應用程序里的某個失誤都會造成對數據庫或者其他企業資源未經授權的訪問,因此安全尤其重要。一種常用的攻擊方法是將命令嵌入到用戶的回應里,而從用戶輸入里過濾掉這些非法的字符就能夠防止這種攻擊。

       
      允許用戶輸入非法的字符會增加用戶導致問題的機會。例如,很多應用程序都能夠接受用戶在SQL命令里增加的WHERE子句。惡意用戶會通過向其輸入的信息里增加額外命令的方法,來執行數據庫服務器上的代碼。例如,他們不是輸入“Smith”,將其作為檢索字符串,而是輸入“Smith'; EXEC master..xp_cmdshell 'dir *.exe”。

      下面這段代碼是設計用來處理從服務器返回的多個Recordset的。用戶的輸入會包含一個額外的、未預料的的執行命令。當NextRecordset方法被調用的時候,潛藏的惡意代碼就會被執行。

      這一攻擊可以通過過濾掉用戶輸入信息中的非法字符(在注釋段里)來避免。這樣做了之后,用戶的輸入仍然被允許處理,但是清除掉了所有的非法字符。

      Dim rst As Recordset
      Dim rst2 As Recordset
      Dim strUserInput As String

      strUserInput = "Smith';EXEC master..xp_cmdshell 'dir *.exe"

      'Filter input for invalid characters
      strUserInput = Replace(strUserInput, "<", vbNullString)
      strUserInput = Replace(strUserInput, ">", vbNullString)
      strUserInput = Replace(strUserInput, """", vbNullString)
      strUserInput = Replace(strUserInput, "'", vbNullString)
      strUserInput = Replace(strUserInput, "%", vbNullString)
      strUserInput = Replace(strUserInput, ";", vbNullString)
      strUserInput = Replace(strUserInput, "(", vbNullString)
      strUserInput = Replace(strUserInput, ")", vbNullString)
      strUserInput = Replace(strUserInput, "&", vbNullString)
      strUserInput = Replace(strUserInput, "+", vbNullString)
      strUserInput = Replace(strUserInput, "-", vbNullString)

      Set rst = New Recordset
      rst.ActiveConnection = "PROVIDER=SQLOLEDB;DATA SOURCE=SQLServer;" & _
                             "Initial Catalog=pubs;Integrated Security=SSPI"
      rst.Open "Select * from authors where au_lname = '" & strUserInput & _
               "'", , adOpenStatic
      'Do something with recordset 1

      Set rst2 = rst.NextRecordset()
      'Do something with recordset 2

      在用戶的輸入中嵌入命令也是攻擊ASP Web應用程序的一種常見手法,也叫做跨網站腳本攻擊。過濾輸入的內容并使用Server.HTMLEncode和Server.URLEncode這兩個方法會有助于防止你ASP應用程序里這類問題的發生。


       




      日韩精品一区二区三区高清