【发布时间】:2011-09-29 14:24:13
【问题描述】:
好的。我正在处理一个用 VBScript 编写的经典 ASP 应用程序。我正在尝试过滤可能通过编码查询字符串出现的 XSS。
我有一个简单的 XSS 消除功能 [getUserInput]。这会寻找特殊字符,如 / ' .... 并用空格替换它们。效果很好。
但是,当我输入通过 Server.URLEncode (VBScript) 或转义 (Javascript) 编码的内容时,显然我上面的过滤器不起作用。
我想知道推荐的解决方案,以防止这种 Unicode 转换的输入使我的页面易受 XSS 攻击。
复制步骤:
<%
Response.Write getUserInput(Request("txt1")) + "<br/>"
Response.Write Server.URLEncode(getUserInput(Request("txt1"))) + "<br/>"
'the below line is where I am trying to decode and echo the input
Response.Write URLDecode2((getUserInput(Request("txt1")))) + "<br/>"
Response.Write "<br/>"
%>
<html>
Try any of the below two encoded strings in the input box and hit the button. </br></br>
alert('hi') </br>
%3Cscript%3Ealert%28%27hi%27%29%3C%2Fscript%3E <br/>
alert(document.cookie) </br>
%3Cscript%3Ealert%28document.cookie%29%3C%2Fscript%3E <br/>
</br>
<form method="get" name="form1" id="form1" action="#" onSubmit="CallOnLoad()">
<input type='text' name='txt1' id='txt1' />
<button name='btn' type='submit' id='btn'>Hitme</button>
</form>
</html>
<%
function getUserInput(input)
dim newString
newString=input
newString = replace(newString,"--","")
newString = replace(newString,";","")
newString = replace(newString,chr(34),"'")
newString = replace(newString,"'","")
newString = replace(newString,"=","=")
newString = replace(newString,"(","[")
newString = replace(newString,")","]")
newString = replace(newString,"'","''")
newString = replace(newString,"<","[")
newString = replace(newString,">","]")
newString = replace(newString,"/*","/")
newString = replace(newString,"*/","/")
getUserInput = newString
end function
%>
<%
'URLDecode2 - source code from http://www.motobit.com/tips/detpg_URLDecode/
Function URLDecode2(ByVal What)
Dim Pos, pPos
What = Replace(What, "+", " ")
on error resume Next
Dim Stream: Set Stream = CreateObject("ADODB.Stream")
If err = 0 Then
on error goto 0
Stream.Type = 2 'String
Stream.Open
Pos = InStr(1, What, "%")
pPos = 1
Do While Pos > 0
Stream.WriteText Mid(What, pPos, Pos - pPos) + _
Chr(CLng("&H" & Mid(What, Pos + 1, 2)))
pPos = Pos + 3
Pos = InStr(pPos, What, "%")
Loop
Stream.WriteText Mid(What, pPos)
Stream.Position = 0
URLDecode2 = Stream.ReadText
Stream.Close
Else 'URL decode using string concentation
on error goto 0
Pos = InStr(1, What, "%")
Do While Pos>0
What = Left(What, Pos-1) + _
Chr(Clng("&H" & Mid(What, Pos+1, 2))) + _
Mid(What, Pos+3)
Pos = InStr(Pos+1, What, "%")
Loop
URLDecode2 = What
End If
End Function
%>
我需要在 IIS 7.5/Win 2008 R2 上托管应用程序。 请简单/优雅的建议?
How To: Prevent Cross-Site Scripting in ASP.NET 是一篇好文章,但它对我的场景并不安静,因为我正在处理经典 ASP。
谢谢。
【问题讨论】:
标签: unicode vbscript asp-classic xss