asp隐藏下载地址

如果我们知道一个静态文件的实际路径如:http://www.xx.com/download/51windows.pdf,如果服务器没有作特别的限制设置,我们就可以毫不费力的把它下载下来!当网站提供51windows.pdf下载时,怎么样才能让下载者无法得到他的实际路径呢!本文就来介绍如何使用Asp来隐藏文件的实际下载路径。

我们在管理网站文件时,可以把扩展名一样的文件放在同一个目录下,起一个比较特别名字,例如放pdf文件目录为the_pdf_file_s,把下面代码另存为down.asp,他的网上路径为http://www.xx.com/down.asp,我们就可以用http://www.xx.com/down.asp?FileName=51windows.pdf来下载这个文件了,而且下载者无法看到这个文件实际下载路径的!在down.asp中我们还可以设置下载文件是否需要登陆,判断下载的来源页是否为外部网站,从而可以做到防止文件被盗链。

示例代码:

<%
From_url = Cstr(Request.ServerVariables("HTTP_REFERER"))
Serv_url = Cstr(Request.ServerVariables("SERVER_NAME"))
if mid(From_url,8,len(Serv_url)) <> Serv_url then
response.write "非法链接!" '防止盗链
response.end
end if

if Request.Cookies("Logined")="" then
response.redirect "/login.asp" '需要登陆!
end if
Function GetFilelongname(longname)'/folder1/folder2/file.asp=>file.asp
while instr(longname,"/")
longname = right(longname,len(longname)-1)
wend
GetFileName = longname
End Function
Dim Stream
Dim Contents
Dim FileName
Dim TrueFileName
Dim FileExt
Const adTypeBinary = 1
FileName = Request.QueryString("FileName")
if FileName = "" Then
    Response.Write "无效文件名!"
    Response.End
End if
FileExt = Mid(FileName, InStrRev(FileName, ".") + 1)
Select Case UCase(FileExt)
    Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
        Response.Write "非法操作!"
        Response.End
End Select
Response.Clear
if lcase(right(FileName,3))="gif" or lcase(right(FileName,3))="jpg" or lcase(right(FileName,3))="png" then
Response.ContentType = "image/*" '对图像文件不出现下载对话框
else
Response.ContentType = "application/ms-download"
end if
Response.AddHeader "content-disposition", "attachment; filename=" & GetFilelongname(Request.QueryString("FileName"))
Set Stream = server.CreateObject("ADODB.Stream")
Stream.Type = adTypeBinary
Stream.Open
if lcase(right(FileName,3))="pdf" then '设置pdf类型文件目录
TrueFileName = "/the_pdf_file_s/"&FileName
end if
if lcase(right(FileName,3))="doc" then '设置DOC类型文件目录
TrueFileName = "/my_D_O_C_file/"&FileName
end if
if lcase(right(FileName,3))="gif" or lcase(right(FileName,3))="jpg" or lcase(right(FileName,3))="png" then
TrueFileName = "/all_images_/"&FileName '设置图像文件目录
end if
Stream.LoadFromFile Server.MapPath(TrueFileName)
While Not Stream.EOS
    Response.BinaryWrite Stream.Read(1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End
%>
-----------------------------------------
但是这个好象不支持外地连接的.

 

 

 

 

 

 

隐藏脚本地址的ASP代码

要实现隐藏脚本地址的ASP代码的写法很多,首先你要有个ASP空间,然后……就不废话了,直接看代码吧

<%
From_url = Cstr(Request.ServerVariables("HTTP_REFERER"))'获取链接脚本的页面地址
if From_url <> "①你要设定的地址" then
Response.Write "<meta http-equiv=refresh content=0;url=转向地址>"
Response.End
'当链接脚本的地址不等于你设定的地址时自动转向到一个地址
else
Response.Write "②"
Response.End
end if
%>

①处的地址,如果是用于QQ空间的简单防盗,当然是输入你空间的页面地址。值得注意的是这个页面地址并不是http://xxx.qzone.qq.com;而是加载完你的空间后出现的类似http://u13.q-zone.qq.com/cgi-bin/cgi_client_entry.cgi?uin=407765896这样的地址

上面②处,里面可以直接写入JS代码,这样就不存在什么脚本了,这个ASP本身就是脚本。

也可以写入:var s=document.createElement('script');s.src='脚本地址';document.body.appendChild(s);但有方法可以让②的内容按代码方式显露出来(算是破解吧,暂且不说),一旦显露出来,这个脚本地址就被暴露于外了。还有个方法可以让即使被破解,但破解者也只能获取到脚本文件,仍然不能获取到正确的脚本地址。

将上面的
  Response.Write "②"
  Response.End
换成:(以下代码要求ASP空间支持下载性质的代码,一般免费空间都不支持下面的代码)
  Function GetFileName(longname)
  while instr(longname,"/")
  longname = right(longname,len(longname)-1)
  wend
  GetFileName = longname
  End Function
  Dim Stream
  Dim Contents
  Dim id'可以通过ASP地址直接赋值,比如xxx.asp?id=yyy
  Dim TrueFileName
  Dim FileExt
  Const adTypeBinary = 1
  id = Request.QueryString("id")
  '③
  FileExt = Mid(id, InStrRev(id, ".") + 1)
  Select Case UCase(FileExt)
  Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
  Response.Write "<meta http-equiv=refresh content=0;url=转向地址>"
  Response.End
  End Select
  Response.Clear
  Response.AddHeader "content-disposition", "attachment; filename=" & GetFileName(Request.QueryString("id"))
  Set Stream = server.CreateObject("ADODB.Stream")
  Stream.Type = adTypeBinary
  Stream.Open
  TrueFileName = "④这里就是实际脚本的地址了"
  Stream.LoadFromFile Server.MapPath(TrueFileName)
  While Not Stream.EOS
  Response.BinaryWrite Stream.Read(1024 * 64)
  Wend
  Stream.Close
  Set Stream = Nothing
  Response.Flush
  Response.End

上面③处还可以加入一个判断,比如if id <> 'XXX' then 加入一行转向什么的

上面④处的脚本地址路径为相对路径(不是绝对路径),设的越复杂越好,比如
  TrueFileName = "../my_location/new_qzone_js/asderc9834.js"
这样别人想用猜的来猜出脚本地址就绝对不可能了,千万别像本空间这样,阿K就懒得设得太复杂,相信有不少人都已经猜出阿K新方案的脚本文件名就是style04.js了

④处也可以引入id变量,比如
  TrueFileName = "../my_location/new_qzone_js/" & id & '.js"
这样你在调用地址xxx.asp?id=yyy的时候,打开的就是../my_location/new_qzone_js/yyy.js

④处也可以对id值进行判断来对文件进行分类,比如
  if right(id,3) = "gif" then
  TrueFileName = "images/gif/" & id
  else if right(id,2) = "js" then
  TrueFileName = "javascript/" & id
  end if
这样,在打开xxx.asp?id=yyy.gif的时候,就会去打开images/gif/yyy.gif;打开xxx.asp?id=zzz.js的时候,就会去打开javascript/zzz.js。就算你不是用这段ASP来做隐藏脚本地址,利用这个方法来对文件进行分类管理也是非常好的。

其它的诸如使用Randomize,调用随机函数加载不同的脚本等效果就不细说了 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值