ASP防止圖片木馬上傳的代碼
更新時(shí)間:2010年09月14日 01:03:01 作者:
有時(shí)候通過(guò)程序上傳木馬,一般都是偽裝成圖片,下面是asp下檢測(cè)圖片木馬的代碼,需要的朋友可以參考下。
ASP木馬防御:
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
%>
復(fù)制代碼 代碼如下:
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
%>
您可能感興趣的文章:
相關(guān)文章
使用Flash DownLoad編寫(xiě)采集器(之突破防盜連下載音樂(lè)文件)
使用Flash DownLoad編寫(xiě)采集器(之突破防盜連下載音樂(lè)文件)...2007-02-02
ASP 循環(huán)導(dǎo)入導(dǎo)出數(shù)據(jù)處理 不使用緩存
非常不錯(cuò),大家可以自己應(yīng)用下。2009-01-01
ASP下實(shí)現(xiàn)自動(dòng)采集程序及入庫(kù)的代碼
ASP下實(shí)現(xiàn)自動(dòng)采集程序及入庫(kù)的代碼...2007-03-03
對(duì)于ASP編碼問(wèn)題的深入研究與最終解決方案
對(duì)于ASP編碼問(wèn)題的深入研究與最終解決方案...2007-05-05
Highlight patterns within strings
Highlight patterns within strings...2007-04-04
非常不錯(cuò)的ASP+Access數(shù)據(jù)庫(kù)的終極安全大法18則
非常不錯(cuò)的ASP+Access數(shù)據(jù)庫(kù)的終極安全大法18則...2007-06-06

