无限Debugger 、hook处理

1、eval 函数

eval() 函数计算 JavaScript 字符串,并把它作为脚本代码来执行。

eval(string)

eval("x=10;y=20;document.write(x*y)"); document.write("<br>" + eval("2+2")); document.write("<br>" + eval(x+17));

涉及的混淆网站:

tools.jb51.net/password/evalencode

2.hook函数

在js中,把替换函数称为hook函数。

一般在声明后,调用前替换。

function foo() {
            console.log("foo功能...")
            bar(11,22,33,44,55)
        }

let _foo = foo
function foo(){
    debugger;   //断点调用
    _foo(arguments);
//或 _foo.apply(this,arguments)
}

案例:hook eval

var _eval = eval
eval = function (src){
console.log("eval截断开始……");
debugger;
_eval.apply(this,src);
console.log("eval截断结束……");

}



案例2. Hook JSON.stringfy

( function(){
    var stringfy  = JSON.stringfy;
        JSON.stringfy = function(params){
        console.log('hook jsonstringfy');
        if (conditon){     // 当满足一定条件的才触发debugger;
        debugger;
            }
      return stringfy(params);
 }

}
)();


案例3. Hook JSON.parse

( function(){
    var parse= JSON.parse;
        JSON.parse= function(params){
        console.log('hook json.parse');
        if (conditon){     // 当满足一定条件的才触发debugger;
        debugger;
            }
      return parse(params);
 }

}
)();

3. Object.defineProperty

Object.defineProperty(zhangsan, "age", {
    get: function () {
        return "yuan"
    },
    set: function (val) {
        console.log("设置已经完成,值:",val)
    }
})

4.hook cookie

(function(){
   'use strict'
    var _cookie = "";
    Object.defineProperty(document, 'cookie', {
        set: function(val) {
            console.log(val);
            debugger
            _cookie = val;
            return val;
        },
        get: function() {
            return _cookie;
        },
});
})()

5.hook header

(function (){
   let set_header  = window.XMLHttpRequest.prototype.setRequestHeader
    window.XMLHttpRequest.prototype.setRequestHeader = function (header,val){
       if (header.toUpperCase()=== "hexin-v".toUpperCase()){
           debugger
       }
       return set_header.apply(this,arguments)
    }

})()

6.debugger

debugger 类型

// debugger
// console.log("hello yuan")
// eval("debugger")
// console.log("hello alex")

// 回顾setInterval和setTimeout
// var ID = setInterval(function (){
//     console.log("hello yuan")
// },1000)
//
//
// clearInterval(ID)


// var ID = setTimeout(function (){
//     console.log("hello yuan")
// },1000)

// clearTimeout(ID)


// 定时器触发debugger
// setInterval(function () {
//         debugger;
//         console.log("hello yuan")
//     }, 1000
// )

// setTimeout(function foo (){
//     debugger;
//     console.log("hello world")
//     setTimeout(foo,1)
// },1)
//


// 通过原型链的方式执行debugger
// Function("debugger").call()
// console.log("111")
// Function("debugger").apply()
// console.log("222")
// Function.constructor("debugger").call("action")
// console.log("333")
// Function.constructor("debugger").apply("action")
// console.log("444");
// (function (){return!![]}["constructor"]("debugger")["call"]("action"))
// console.log("555");
// eval('(function (){return!![]}["constructor"]("debugger")["call"]("action"))')
// console.log("666");


AAA=Function.prototype.constructor
Function.prototype.constructor=function(n){
  if(n!="debugger"){
    return AAA(n)
  }
  return function(){};
}

let _Function = Function;

Function = function (s) {
    if (s === "debugger") {
        console.log(s)
        return null

    }
    return _Function(s)
}

// (2)
let _constructor = constructor

Function.prototype.constructor = function (s) {
    if (s === "debugger") {
        console.log(s)
        return null
    }
    return _constructor(s)
}


// (3)
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)
};

方案1: 重构hook Function.construnctor

方案2: 文件替换原文件,找到debugger, 把debugger 去掉;根据调用堆栈,找到调用函数;

注意:重新设置 setInterval = function(param){}; 时,要在文件一开始执行,否则有时会报错。

过无限的debugger
。代码行号右击:不在此处暂停
鼠标右击: 条件断点 让当前代码条件不成立
方法置空
前提:需要知道执行的是什么 方法,在执行之前下断点置空替换文件方式 把断点的位置注释O
。hook代码完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值