1回答

1收藏

关于js变量赋值时怎么被hook到(问题补充)

问答交流 问答交流 2344 人阅读 | 1 人回复 | 2020-07-12


怎么做到当一个变量被赋值为 'hello' 时被hook到呢 (以下三种都要能被hook)?

1、var a = 'hello';

2、var obj = {}; obj.b = 'hello';

3、(function(){

var z = 'hello';

return z;

})()

一、首先排除了下面方法的可能性,因为对象名和变量名都是不确定的,并且3中的还是局部变量,不通用

Object.defineProperty(window, 'a', {

set:function(x){

if (x == 'hello'){

debugger;

};

return x;

}

})




二、目前想到的只能下面这种形式的赋值能够被hook到,但实际中很少有这种赋值方式:

var a = new String('hello');

相关的hook函数

myString = String;

String = function(value){

if (value == 'hello'){

debugger;

};

console.log(value);

return myString(value);

}

如果能够实现,可以对整个网页js执行时hook所有变量的赋值过程,对一些加密后为固定值的参数可以秒定位,求大佬解答
分享到:
回复

使用道具 举报

回答|共 1 个

mengtao

发表于 2020-7-24 14:29:23 | 显示全部楼层

// ==UserScript==
// @name         参数破解
// @namespace    http://*
// @version      0.1
// @description  try to take over the world!
// @author       Mengtao
// @match        https://*
// @grant        none
// ==/UserScript==

var code = function(){
     var open = window.XMLHttpRequest.prototype.open;

     window.XMLHttpRequest.prototype.open = function open(method, url, async){
         if (url.indexOf("MmEwMD")>-1){
             debugger;
         }
         if (url.indexOf("sensor_data")>-1){
             debugger;
         }
         return open.apply(this, arguments);
     };
}

var script = document.createElement('script');
script.textContent = '(' + code + ')()';
(document.head||document.documentElement).appendChild(script);
script.parentNode.removeChild(script);
回复

使用道具 举报