• JavaScript 实现阻碍调试(反调试)


    先将鼠标改为禁用状态,第一步

    body:hover{
            cursor:not-allowed;
        }
    

    设置禁用NoScript

    <noscript><iframe class="iframe_display" src="";</iframe></noscript>
    

    禁用掉键盘的全部按键(键盘报废)

    $(document).ready(function () {
     document.body.onkeydown = function (event) {
     if (window.event) {
     //alert("不允许使用任何键盘按键");
     return false;
    }
    }
    });
    

    实现全屏爆炸:这段代码很简单,当按下调试键的时候,全屏都是乱码,所有标签里都会填充为乱码,轻则直接可以让浏览器崩溃,经测试有些系统则可能会蓝屏!(慎用)

    <script type="text/javascript">
    window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
        if(event.keyCode==123)
        {
            for( i=0;i<99999999999;i++){
            $("body div").append("TIHI!@#$%^&*()_+)()*&*^&TGYGJGYGuygT^&6746t78t78g785tgyuGGIUGOIUB&^Y(*^&^$$&*G*GUIGUOUIYUIT&*%$^%#^%ER^%RF&FGIY*G*&^T*(G*O");
            }
        }
    }
    </script>
    

    禁用F12调试键

    <script type="text/javascript">
    // 临时性,禁用F12调试器
    window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
        // 判断是否按下F12,F12键码为123
        if (event.keyCode === 123) {
            event.preventDefault(); // 阻止默认事件行为
            window.event.returnValue = false;
        }
    }
    </script>
    

    禁用页面的ctrl功能,来禁止ctrl+S保存功能

    <script type="text/javascript">
    //禁用页面的ctrl功能,来禁止ctrl+S保存功能
    window.addEventListener('keydown', function (e) {
        if(e.keyCode == 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)){
            e.preventDefault();
        }
    })
    </script>
    

    禁用页面的ctrl功能,来禁止ctrl+C保存功能

    //禁用页面的ctrl功能,来禁止ctrl+C保存功能
    window.addEventListener('keydown', function (e) {
        if(e.keyCode == 67 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)){
            e.preventDefault();
        }
    })
    

    为右键添加自定义事件,禁用菜单右键!

    // 为右键添加自定义事件,禁用菜单右键!
    window.oncontextmenu = function() {
        event.preventDefault(); // 阻止默认事件行为
        return false;
    }
    

    当通过特殊途径打开浏览器调试窗口时,会无限刷新,导致无法调试

    // 无限回写,阻碍调试
    var x = document.createElement('div');
    var isOpening = false;
    Object.defineProperty(x, 'id', {
      get:function(){
         console.log("警告!控制台已被打开!");
          window.location.reload()
      }
    });
    console.info(x);
    

    屏蔽Ctrl+Shift+I

    //屏蔽Ctrl+Shift+I
    window.addEventListener('keydown', function (e) {
        if((e.ctrlKey) && (e.shiftKey) && (e.keyCode == 73)){
            e.preventDefault();
        }
    })
    

    通过HTML实现反调试

    <body leftmargin=0 topmargin=0 oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>
    
    <noscript> 
    <iframe src="*.htm"></iframe> 
    </noscript>
    
    <body onmousemove=/HideMenu()/ oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">
    

    实现自动跳转到百度

    window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
            event.preventDefault();
            window.event.returnValue = false;
    }
    window.oncontextmenu = function() {
        event.preventDefault();
        return false;
    }
    
    var threshold = 160; 
    window.setInterval(function() {  
        if (window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold){    
            window.location.href="https://www.baidu.com";
    }
    },100);
    

    头部防范

    <body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0" oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onbeforecopy="return false">
    

    版权声明: 本博客,文章与代码均为学习时整理的笔记,博客中除去明确标注有参考文献的文章,其他文章【均为原创】作品,转载请务必【添加出处】,您添加出处是我创作的动力!

    警告:如果您恶意转载本人文章,则您的整站文章,将会变为我的原创作品,请相互尊重!
  • 相关阅读:
    python(内置高阶函数)
    cms 环境搭建
    cookie、session 和 token 区别
    接口用例设计
    python(字符编码与转码)
    从北斗卫星时钟(北斗校时器)发展纵论世界卫星导航新格局
    北斗授时系统(GPS授时设备)错一秒会怎样?京准电子科技
    北斗校时服务器(GPS时钟服务器)在电力调度系统应用
    GPS卫星时钟(北斗授时设备)在监狱管理系统方案
    NTP校时(网络对时服务器)IPC网络摄像机时钟同步
  • 原文地址:https://www.cnblogs.com/LyShark/p/11828856.html
Copyright © 2020-2023  润新知