js常用hook

moxiaoying
2年前发布 /正在检测是否收录...
温馨提示:
本文最后更新于2024年01月24日,已超过452天没有更新,若内容或图片失效,请留言反馈。

无限debugger

Function.prototype.__constructor_back = Function.prototype.constructor;
Function.prototype.constructor = function() {
    if(arguments && typeof arguments[0]==='string'){
        if("debugger" === arguments[0]){
            return
        }
    }
   return Function.prototype.__constructor_back.apply(this,arguments);
}

方法一

(()=>{
    Function.prototype.__constructor = Function.prototype.constructor;
    Function.prototype.constructor = function(){
        if(arguments && typeof arguments[0]==='string'){
            if("debugger"===arguments[0]){
                return
            }
            return Function.prototype.__constructor.apply(this,arguments);
        }
    }
})()

方法二

Function.prototype.constructor_ = Function.prototype.constructor;
Function.prototype.constructor = function (a) {
    if(a == "debugger") {
        return function (){};
    }
    return Function.prototype.constructor_(a);
};

方法三

setInterval_new=setInterval
setInterval=function(a,b){
if(a.indexOf("debugger")==-1){
    return setInterval_new(a,b)
    }
}

方法四

Function.prototype.constructor = function(){}

eval_bc = eval  
eval =function(a){
    if (a===='debugger;a=asdasdasdas')
    return eval_bc(a)
}

eval

(function() {
    if (window.__cr_eval) return
    window.__cr_eval = window.eval
    var myeval = function (src) {
        console.log("================ eval begin: length=" + src.length + ",caller=" + (myeval.caller && myeval.caller.name) + " ===============")
        console.log(src);
        console.log("================ eval end ================")
        return {}
        return window.__cr_eval(src)
    }
    var _myeval = myeval.bind(null)  // 注意:这句和下一句就是小花招本招了!
    _myeval.toString = window.__cr_eval.toString
    Object.defineProperty(window, 'eval', { value: _myeval })
    console.log(">>>>>>>>>>>>>> eval injected: " + document.location + " <<<<<<<<<<<<<<<<<<<")
})();

Cookie

(function(){
    var cookie_cache = document.cookie;
    Object.defineProperty(document,'cookie',{
        get:function(){
            console.log('Get cookie');
            debugger
            return cookie_cache;
        },
        set:function(val){
            console.log('Set cookie',val);
            debugger
            var cookie=val.split(";")[0];
            var ncookie=cookie.split("=");
            var flag = false;
            var cache=cookie_cache.split("; ");
            cache = cache.map(function(a){
                if (a.split("=")[0]===ncookie[0]){
                    flag=true;
                    return cookie;
                }
                return a;
            })
            cookie_cache=cache.join("; ");
            if (!flag){
                cookie_cache+=cookie+"; ";
            }
            this._value=val;
            return cookie_cache;
        },
    });
})();
(function(){
    'use strict'
    Object.defineProperty(document, 'cookie', {
        get: function() {
            //debugger;
            return "";
        },
        set: function(value) {
            debugger;
            return value;
        },
});
})()
(function() {
    // 严谨模式 检查所有错误
    'use strict';
    // document 为要hook的对象 这里是hook的cookie
 var cookieTemp = "";
    Object.defineProperty(document, 'cookie', {
  // hook set方法也就是赋值的方法 
  set: function(val) {
    // 这样就可以快速给下面这个代码行下断点
    // 从而快速定位设置cookie的代码
    console.log('Hook捕获到cookie设置->', val);
                debugger;
    cookieTemp = val;
    return val;
  },
  // hook get 方法也就是取值的方法 
  get: function()
  {
   return cookieTemp;
  }
    });
})();
 
喜欢就支持一下吧
点赞 0 分享 收藏
评论
所有页面的评论已关闭