hook原理:
hook是常用于js反編譯的技術;翻譯就是鉤子,他的原理就是劫持js的函數然后進行篡改
一段簡單的js代碼 :這個代碼是順序執行的
function test01(){console.log('test01')test02()
}
function test02(){console.log('02')test03()}function test03(){console.log("03")test04()
}
function test04(){console.log("04")
}
test01()var a=test03
function test03 (){console.log("hook successful")
}
這個就是簡單的hook原理? 當然如果是web上? ?我們的函數重構實際上就是? 篡改猴腳本在 控制臺上進行的操作
實驗一? 使用簡單的hook腳本進行鎖定瀏覽器的寬高
我們知道 js的bom樹中有個? 這個是瀏覽器當前的寬高 我們可以使用hook技術讓 這個的輸出是固定的
因為我們只有把窗口縮小 就會出現數值的同步
hook前置知識 :
這里有一堆注釋的東西? 是什么呢
// ==UserScript==
// @name 固定百度頁面窗口尺寸 //腳本的名稱
// @namespace http://tampermonkey.net/ // 腳本的作用域
// @version 1.0 //腳本的版本
// @description 強制讓百度頁面的 innerWidth/innerHeight 返回固定值 520 //腳本的注釋
// @author YourName //腳本的作者
// @match https://www.baidu.com/* // 腳本作用的url 這個建議一個每個腳本都 固定特定的url 不要使用 htttp://*
// @grant none //定義腳本所需的權限
// @run-at document-start
完整腳本? 可以直接讓 ai幫寫
實驗二 :結合ai幫我們解決 js逆向常見的debuger 問題??
最簡單的步驟 :
1、Title? ?先判斷debugger函數定義的位置(一般hook 的方法就是使用 函數重構)
這種 我們點擊快進? 看看有幾個debugfer?
發現就一個
然后使用全局搜索進行 搜索debugger 函數的定義
發現之后就讓ai幫我們寫腳本 (上面這個需要繞過 2個地方? 1、 debuger函數? 2、連續的時間)
// ==UserScript==
// @name 禁用網站反調試(無限debugger)
// @namespace http://tampermonkey.net/
// @version 1.1
// @description 繞過網站通過debugger實現的無限斷點反調試
// @author YourName
// @match http://www.xiaodi8.com/test.html
// @grant none
// @run-at document-start
// ==/UserScript==(function() {'use strict';// ========== 核心防御邏輯 ==========// 1. 劫持 Function 構造函數 (防止通過 new Function("debugger") 創建調試器)const nativeFunction = window.Function;window.Function = function(...args) {const code = args.slice(-1)[0];if (/debugger|setInterval|setTimeout/i.test(code)) {return function(){}; // 返回空函數}return nativeFunction.apply(this, args);};// 2. 劫持 setInterval/setTimeout (防止定時觸發debugger)const originalSetInterval = window.setInterval;window.setInterval = function(fn, delay, ...args) {if (typeof fn === 'function' && /debugger/.test(fn.toString())) {return -1; // 阻止執行}return originalSetInterval(fn, delay, ...args);};// 3. 直接重寫 debugger 關鍵字行為Object.defineProperty(window, 'debugger', {get: () => {},set: () => {},configurable: true});// 4. 防御動態腳本注入new MutationObserver(() => {// 持續重寫 Function 和 debuggerwindow.Function = function(){};window.eval = function(){};}).observe(document, { subtree: true, childList: true });// ========== 附加防御層 ==========// 禁用控制臺調試 (可選)if (window.console) {window.console.log = function(){};window.console.debug = function(){};}// 劫持 onbeforeunload 事件window.onbeforeunload = null;
})();
之后就能解決了