hook笔记分享
见多了前端各种js的混淆,参数的加密,虽然抓包会拿到最后的结果,但是一步步分析是真的折磨人,像一些恶心的sojson混淆,可能会让人看着各种参数而头皮发麻。
这里分享一些常用的hook js的方法,与反爬一起进步!
//hook window对象的__pt__属性的设置与取值
(function(){ 'use strict'; var pre = window._pt_; Object.defineProperty(window,"_pt_", { get:function(){ console.log("pre:", pre) }, set:function(val){ console.log("_pt_:", val); debugger; pre = val; return pre; } }) })();
//hook 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 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 + " <<<<<<<<<<<<<<<<<<<") })();