不說廢話,直接上代碼!
簡單模式:
setInterval(function() { debugger }, 100);
稍微復雜一點:
function t() { try { var a = ["r", "e", "g", "g", "u", "b", "e", "d"].reverse().join(""); ! function e(n) { (1 !== ("" + n / n).length || 0 === n) && function() {} .constructor(a)(), e(++n) }(0) } catch (a) { setTimeout(t, 500) } }
這段代碼首先是設置變量 a 表示字符串“debugger”,然后使用 constructor() 來實現調用 debugger 方法,再使用 setTimeout 實現每0.5秒中斷一次。
解決方案:
將反調試具名函數重新定義一遍,然后重新打開 DevTools,就能進行調試了。對於上面的例子,可以在控制台中輸入以下內容:
t = function() {}
我實際項目中的代碼:
function t() { var r = "V", n = "5", e = "8"; function o(r) { if (!r) return ""; for (var t = "", n = 44106, e = 0; e < r.length; e++) { var o = r.charCodeAt(e) ^ n; n = n * e % 256 + 2333, t += String.fromCharCode(o) } return t } try { var a = ["r", o("갯"), "g", o("갭"), function (t) { if (!t) return ""; for (var o = "", a = r + n + e + "7", c = 45860, f = 0; f < t.length; f++) { var i = t.charCodeAt(f); c = (c + 1) % a.length, i ^= a.charCodeAt(c), o += String.fromCharCode(i) } return o }("@"), "b", "e", "d"].reverse().join(""); ! function c(r) { (1 !== ("" + r / r).length || 0 === r) && function () {}.constructor(a)(), c(++r) }(0) } catch (a) { setTimeout(t, 100); } } t(); document.onkeydown = function() { if ((e.ctrlKey) && (e.keyCode == 83)) { alert("CTRL + S 被管理員禁用"); return false; } } document.onkeydown = function() { var e = window.event || arguments[0]; if (e.keyCode == 123) { alert("F12 被管理員禁用"); return false; } } document.oncontextmenu = function() { alert('右鍵被管理員禁用'); return false; }
到這一步了,沒完,還有這段代碼配合使用,仿偽君子必備。(通過正常函數來實現):
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script> // 反調試函數,參數:開關,執行代碼 function endebug(off, code) { if (!off) { ! function(e) { function n(e) { function n() { return u; } function o() { window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized ? t("on") : (a = "off", console.log(d), console.clear(), t(a)); } function t(e) { u !== e && (u = e, "function" == typeof c.onchange && c.onchange(e)); } function r() { l || (l = !0, window.removeEventListener("resize", o), clearInterval(f)); } "function" == typeof e && (e = { onchange: e }); var i = (e = e || {}).delay || 500, c = {}; c.onchange = e.onchange; var a, d = new Image; d.__defineGetter__("id", function() { a = "on" }); var u = "unknown"; c.getStatus = n; var f = setInterval(o, i); window.addEventListener("resize", o); var l; return c.free = r, c; } var o = o || {}; o.create = n, "function" == typeof define ? (define.amd || define.cmd) && define(function() { return o }) : "undefined" != typeof module && module.exports ? module.exports = o : window.jdetects = o }(), jdetects.create(function(e) { var a = 0; var n = setInterval(function() { if ("on" == e) { setTimeout(function() { if (a == 0) { a = 1; setTimeout(code); } }, 200); } }, 100); }) } } </script> </head> <body> <h1>你可以看見嗎?</h1> <script type="text/javascript"> endebug(false, function() { // 非法調試執行的代碼(不要使用控制台輸出的提醒) document.write("檢測到非法調試,請關閉后刷新重試!"); }); </script> </body> </html>