asp隱藏下載地址

來源:互聯網
上載者:User

如果我們知道一個靜態檔案的實際路徑如: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,調用隨機函數載入不同的指令碼等效果就不細說了 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.