当前位置:首页 > ASP教程 > 应用技巧

ASP下检测图片木马的函数代码

木马原理:入侵者使用诸如asp图片木马生成器之类的工具将一张正常的图片与一个asp木马文件合并成一个图片文件(即将对网站有害的
asp代码插在图片编码之后,虽然图片仍然可以正常显示,但是文件内容和尺寸已被改变),然后通过网站提供的文件上传功能上传这一张“合
'法的”图片,进而实现了上传asp木马的目的。
' 防范方法:因为这种木马是图片与木马的二合一,所以需要在上传图片前检查文件内容,若文件内容不合法(即包含有恶意代码在里面),
'则禁止上传,从而堵住了木马攻击的源头,这是木马攻击的第一关,至关重要,必须堵住。
'***************************************************************************
复制代码 代码如下:

'begin--------------------------------------------------------------------------------------------------------------------------
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
'end----------------------------------------------------------------------------------------------------------------------------

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!