asp 判断上传文件中是否存在危险代码
(编辑:jimmy 日期: 2024/11/27 浏览:3 次 )
复制代码 代码如下:
<%
function CheckFileContent(FileName)
dim ClientFile,ClientText,ClientContent,DangerString,DSArray,AttackFlag,k
set ClientFile=Server.CreateObject("Scripting.FileSystemObject")
set ClientText=ClientFile.OpenTextFile(Server.MapPath(FileName),1)
ClientContent=LCase(ClientText.ReadAll)
set ClientText=nothing
set ClientFile=nothing
AttackFlag=false
DangerString=".getfolder|.createfolder|.deletefolder|.createdirectory|.deletedirectory|.saveas|wscript.shell|script.encode|server.|.createobject|execute|activexobject|language=|include|filesystemobject|shell.application"
DSArray=split(DangerString,"|")
for k=0 to UBound(DSArray)
if InStr(ClientContent,DSArray(k))>0 then '判断文件内容中是否包含有危险的操作字符,如有,则必须删除该文件。
AttackFlag=true
exit for
end if
next
CheckFileContent=AttackFlag
end function
If CheckFileContent("0.jpg")=true then
Response.Write "危险"
else
Response.Write "安全"
end if
%>
<%
function CheckFileContent(FileName)
dim ClientFile,ClientText,ClientContent,DangerString,DSArray,AttackFlag,k
set ClientFile=Server.CreateObject("Scripting.FileSystemObject")
set ClientText=ClientFile.OpenTextFile(Server.MapPath(FileName),1)
ClientContent=LCase(ClientText.ReadAll)
set ClientText=nothing
set ClientFile=nothing
AttackFlag=false
DangerString=".getfolder|.createfolder|.deletefolder|.createdirectory|.deletedirectory|.saveas|wscript.shell|script.encode|server.|.createobject|execute|activexobject|language=|include|filesystemobject|shell.application"
DSArray=split(DangerString,"|")
for k=0 to UBound(DSArray)
if InStr(ClientContent,DSArray(k))>0 then '判断文件内容中是否包含有危险的操作字符,如有,则必须删除该文件。
AttackFlag=true
exit for
end if
next
CheckFileContent=AttackFlag
end function
If CheckFileContent("0.jpg")=true then
Response.Write "危险"
else
Response.Write "安全"
end if
%>
下一篇:asp 取一个数的整数 但不是四舍五入,只要有小数,就取大于这个数的整数