---
title: "asp破解图片盗链代码"
author: "fengxu"
date: "2008-11-26T14:38:00Z"
tags: ["ASP", "Cache", "Microsoft"]
slug: "asp"
draft: false
lastmod: "2008-11-26T14:38:00Z"
id: 343521
url: "https://fengxu.iteye.com/blog/343521"
---

源代码如下：

001. &lt;%
002. '破解图片盗链
003. '使用方法:tu.asp?url=
004. 'tu.asp?url=http://hi.baidu.com/egergfdgregwe.jpg
005. Dim url, body, myCache
006. url = Request.QueryString("url")
007. Set myCache = new cache
008. myCache.name = "picindex"
009. If myCache.valid Then
010. body = myCache.value
011. Else
012. body = GetWebData(url)
013. myCache.add body,dateadd("d",1,now)
014. End If
015. If Err.Number = 0 Then
016. Response.CharSet = "UTF-8"
017. Response.ContentType = "application/octet-stream"
018. Response.BinaryWrite body
019. Response.Flush
020. Else
021. Wscript.Echo Err.Description
022. End if
023. '取得数据
024. Public Function GetWebData(ByVal strUrl)
025. Dim curlpath
026. curlpath = Mid(strUrl,1,Instr(8,strUrl,"/"))
027. Dim Retrieval
028. Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
029. With Retrieval
030. .Open "Get", strUrl, False,"",""
031. .setRequestHeader "Referer", curlpath
032. .Send
033. GetWebData =.ResponseBody
034. End With
035. Set Retrieval = Nothing
036. End Function
037. 'cache类
038. class Cache
039. private obj                                'cache内容
040. private expireTime                '过期时间
041. private expireTimeName        '过期时间application名
042. private cacheName                'cache内容application名
043. private path                        'url
044. private sub class\_initialize()
045. path=request.servervariables("url")
046. path=left(path,instrRev(path,"/"))
047. end sub
048. private sub class\_terminate()
049. end sub
050. public property get blEmpty
051. '是否为空
052. if isempty(obj) then
053. blEmpty=true
054. else
055. blEmpty=false
056. end if
057. end property
058. public property get valid
059. '是否可用(过期)
060. if isempty(obj) or not isDate(expireTime) then
061. valid=false
062. elseif CDate(expireTime)&lt;now then
063. valid=false
064. else
065. valid=true
066. end if
067. end property
068. public property let name(str)
069. '设置cache名
070. cacheName=str & path
071. obj=application(cacheName)
072. expireTimeName=str & "expires" & path
073. expireTime=application(expireTimeName)
074. end property
075. public property let expires(tm)
076. '重设置过期时间
077. expireTime=tm
078. application.lock
079. application(expireTimeName)=expireTime
080. application.unlock
081. end property
082. public sub add(var,expire)
083. '赋值
084. if isempty(var) or not isDate(expire) then
085. exit sub
086. end if
087. obj=var
088. expireTime=expire
089. application.lock
090. application(cacheName)=obj
091. application(expireTimeName)=expireTime
092. application.unlock
093. end sub
094. public property get value
095. '取值
096. if isempty(obj) or not isDate(expireTime) then
097. value=null
098. elseif CDate(expireTime)&lt;now then
099. value=null
100. else
101. value=obj
102. end if
103. end property
104. public sub makeEmpty()
105. '释放application
106. application.lock
107. application(cacheName)=empty
108. application(expireTimeName)=empty
109. application.unlock
110. obj=empty
111. expireTime=empty
112. end sub
113. public function equal(var2)
114. '比较
115. if typename(obj)&lt;&gt;typename(var2) then
116. equal=false
117. elseif typename(obj)="Object" then
118. if obj is var2 then
119. equal=true
120. else
121. equal=false
122. end if
123. elseif typename(obj)="Variant()" then
124. if join(obj,"^")=join(var2,"^") then
125. equal=true
126. else
127. equal=false
128. end if
129. else
130. if obj=var2 then
131. equal=true
132. else
133. equal=false
134. end if
135. end if
136. end function
137. end class
138. %&gt;