Created
October 19, 2018 14:04
-
-
Save ckalegi/f93c827fcb49de880696ebf9dc0b5542 to your computer and use it in GitHub Desktop.
Prevent obfuscated client side scripts from calling anonymous debugger functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.unsafeWindow || ( | |
unsafeWindow = (function () { | |
var el = document.createElement('p'); | |
el.setAttribute('onclick', 'return window;'); | |
return el.onclick(); | |
}()) | |
); | |
(function () { | |
var _constructor = unsafeWindow.Function.prototype.constructor; | |
unsafeWindow.Function.prototype.constructor = function () { | |
var fnContent = arguments[0]; | |
if (fnContent) { | |
// Check if function is trying to stop debugger | |
if (fnContent.includes('debugger')) { | |
var caller = Function.prototype.constructor.caller; // Non-standard hack to get the function caller | |
var callerContent = caller.toString(); | |
if (callerContent.includes(/\bdebugger\b/gi)) { // Eliminate all debugger statements from the caller, if any | |
callerContent = callerContent.replace(/\bdebugger\b/gi, ''); // Remove all debugger expressions | |
eval('caller = ' + callerContent); // Replace the function | |
} | |
return (function () {}); | |
} | |
} | |
// Execute the normal function constructor if nothing unusual is going on | |
return _constructor.apply(this, arguments); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment