Discuz教程网

ASP防止图片木马上传的代码

[复制链接]
authicon dly 发表于 2011-9-14 09:06:15 | 显示全部楼层 |阅读模式
ASP木马防御:
  1. const adTypeBinary=1

  2. dim jpg(1):jpg(0)=CByte(&HFF):jpg(1)=CByte(&HD8)
  3. dim bmp(1):bmp(0)=CByte(&H42):bmp(1)=CByte(&H4D)
  4. dim png(3):png(0)=CByte(&H89):png(1)=CByte(&H50):png(2)=CByte(&H4E):png(3)=CByte(&H47)
  5. 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)
  6. Response.Write CheckFileType(Server.MapPath("2.gif"))

  7. function CheckFileType(filename)
  8. on error resume next
  9. CheckFileType=false
  10. dim fstream,fileExt,stamp,i
  11. fileExt=mid(filename,InStrRev(filename,".")+1)
  12. set fstream=Server.createobject("ADODB.Stream")
  13. fstream.Open
  14. fstream.Type=adTypeBinary
  15. fstream.LoadFromFile filename
  16. fstream.position=0
  17. select case fileExt
  18. case "jpg","jpeg"
  19. stamp=fstream.read(2)
  20. for i=0 to 1
  21. if ascB(MidB(stamp,i+1,1))=jpg(i) then CheckFileType=true else CheckFileType=false
  22. next
  23. case "gif"
  24. stamp=fstream.read(6)
  25. for i=0 to 5
  26. if ascB(MidB(stamp,i+1,1))=gif(i) then CheckFileType=true else CheckFileType=false
  27. next
  28. case "png"
  29. stamp=fstream.read(4)
  30. for i=0 to 3
  31. if ascB(MidB(stamp,i+1,1))=png(i) then CheckFileType=true else CheckFileType=false
  32. next
  33. case "bmp"
  34. stamp=fstream.read(2)
  35. for i=0 to 1
  36. if ascB(MidB(stamp,i+1,1))=bmp(i) then CheckFileType=true else CheckFileType=false
  37. next
  38. end select
  39. fstream.Close
  40. set fseteam=nothing
  41. if err.number<>0 then CheckFileType=false
  42. end function
  43. %>
复制代码



上一篇:asp 删除数据库记录的代码
下一篇:ASP+ajax注册即时提示程序代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 07:15

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表