欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp防止上傳圖片木馬原理解析

 更新時(shí)間:2022年05月05日 10:58:08   投稿:lijiao  
有時(shí)候通過(guò)程序上傳木馬,一般都是偽裝成圖片,下面是asp下檢測(cè)圖片木馬的代碼,需要的朋友可以參考下

本文為大家分享了asp防止上傳圖片木馬原理,供大家參考,具體內(nèi)容如下

首先判斷文件大小:

if file.filesize<10 then
  Response.Write("<script>alert('您沒(méi)有選擇上傳文件')</script>")
  Response.Write("<script>history.go(-1)</script>")
  Response.End()
end if

將文件上傳到服務(wù)器后,判斷用戶文件中的危險(xiǎn)操作字符:

set MyFile = server.CreateObject("Scripting.FileSystemObject")
set MyText = MyFile.OpenTextFile(FilePath, 1) '讀取文本文件
sTextAll = lcase(MyText.ReadAll)
MyText.close
set MyFile = nothing
sStr=".getfolder|.createfolder|.deletefolder|.createdirectory|.deletedirectory|.saveas
|wscript.shell|script.encode|server.|.createobject|execute|activexobject|language="
sNoString = split(sStr,"|") 
for i=0 to ubound(sNoString)
  if instr(sTextAll,sNoString(i)) then
   set filedel = server.CreateObject("Scripting.FileSystemObject")
   filedel.deletefile FilePath
   set filedel = nothing
   Response.Write("<script>alert('您上傳的文件有問(wèn)題,上傳失敗');window.close();</script>")
   Response.End()
  end if
next

如何防止木馬性圖片上傳

這個(gè)代碼我檢驗(yàn)過(guò)沒(méi)有問(wèn)題,可以阻擋木馬性圖片的上傳

<%
'***************************************************************
'CheckFileType 函數(shù)用來(lái)檢查文件是否為圖片文件
'參數(shù)filename是本地文件的路徑
'如果是文件jpeg,gif,bmp,png圖片中的一種,函數(shù)返回true,否則返回false
'***************************************************************
 
const adTypeBinary=1
 
dim jpg(1):jpg(0)=CByte(&HFF):jpg(1)=CByte(&HD8)
dim bmp(1):bmp(0)=CByte(&H42):bmp(1)=CByte(&H4D)
dim png(3):png(0)=CByte(&H89):png(1)=CByte(&H50):png(2)=CByte(&H4E):png(3)=CByte(&H47)
dim gif(5):gif(0)=CByte(&H47):gif(1)=CByte(&H49):gif(2)=CByte(&H46):gif(3)=CByte(&H39):gif(4)=CByte(&H38):gif(5)=CByte(&H61)
Response.Write CheckFileType(Server.MapPath("2.gif"))
 
function CheckFileType(filename)
on error resume next
CheckFileType=false
dim fstream,fileExt,stamp,i
fileExt=mid(filename,InStrRev(filename,".")+1)
set fstream=Server.createobject("ADODB.Stream")
fstream.Open
fstream.Type=adTypeBinary
fstream.LoadFromFile filename
fstream.position=0
select case fileExt
case "jpg","jpeg"
stamp=fstream.read(2)
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=jpg(i) then CheckFileType=true else CheckFileType=false
next
case "gif"
stamp=fstream.read(6)
for i=0 to 5
if ascB(MidB(stamp,i+1,1))=gif(i) then CheckFileType=true else CheckFileType=false
next
case "png"
stamp=fstream.read(4)
for i=0 to 3
if ascB(MidB(stamp,i+1,1))=png(i) then CheckFileType=true else CheckFileType=false
next
case "bmp"
stamp=fstream.read(2)
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=bmp(i) then CheckFileType=true else CheckFileType=false
next
end select
fstream.Close
set fseteam=nothing
if err.number<>0 then CheckFileType=false
end function
%>

以上就是asp防止上傳圖片木馬原理解析,希望對(duì)大家的學(xué)習(xí)有所幫助。

相關(guān)文章

最新評(píng)論