首先看下效果,以下兩張圖分别使用直接盜鍊和破解盜鍊,可以右鍵檢視圖檔URL,是同一張圖檔。

直接盜鍊
破解盜鍊
實作代碼:
<code>function</code> <code>showImg( url ) {</code>
<code> </code><code>var</code> <code>frameid =</code><code>'frameimg'</code> <code>+ Math.random();</code>
<code> </code><code>window.img =</code><code>'<img id="img" src=\''</code><code>+url+</code><code>'?'</code><code>+Math.random()+</code><code>'\' /><script>window.onload = function() { parent.document.getElementById(\''</code><code>+frameid+</code><code>'\').height = document.getElementById(\'img\').height+\'px\'; }<'</code><code>+</code><code>'/script>'</code><code>;</code>
<code> </code><code>document.write(</code><code>'<iframe id="'</code><code>+frameid+</code><code>'" src="javascript:parent.img;" frameBorder="0" scrolling="no" width="100%"></iframe>'</code><code>);</code>
<code>}</code>
調用方式:
<code>showImg(</code><code>'圖檔位址'</code><code>);</code>
關于防禦方法,有以下3點:
1、不允許referer為空(不建議,因在某些開啟隐私模式的浏覽器中,或https頁面引用下,referer是空的)
2、位址變更(lighttpd的是根據有效時間,nginx的根據是md5)
3、登入校驗(如必須登入網站帳号後才能通路)
本文轉自胡尐睿丶部落格園部落格,原文連結:http://www.cnblogs.com/hooray/archive/2011/05/12/2044744.html,如需轉載請自行聯系原作者