asp 判断上传文件中是否存在危险代码
程序员文章站
2022-07-05 19:29:00
复制代码 代码如下:<% function checkfilecontent(filename) dim clientfile,clienttext,clientco...
复制代码 代码如下:
<%
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
%>