目录
一、使用油猴脚本进行注入,获取Cookie的加密参数
新建油猴脚本文件
// ==UserScript==
// @name cookie的HOOK
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://*/*
// @icon https://g.csdnimg.cn/static/logo/favicon32.ico
// @grant none
// ==/UserScript==
(function() {
var cookieTemp = "";
Object.defineProperty(document,'cookie',{
set: function(val){
if (val.indexOf("cookie内加密参数名") != -1){
debugger;
}
console.log('cookie值:',val);
cookieTemp = val;
return val;
},
get: function()
{
return cookieTemp;
}
});
})();
二、油猴脚本hook之跳过定时器无限debugger
(function (){
var gid = setInterval(clearAllInverval, 1000);
function clearAllInverval(){
var id = setInterval(function(){}, 0);
while (id>0){
if (id!=gid){
clearInterval(id);
};
id --
}
}
})();
三、直接在控制台进行注入,打印输出调试
在
window['encrypt'][0]
加密函数下面打断点,然后在控制台输入下面代码,刷新页面即可debugger【该方法可用在一些隐蔽的加密函数进行栈回溯,从而找到加密入口】
encrypt = window['encrypt'][0]
window['encrypt'][0] = function(a,b,c,d,e){
var result = encrypt(a,b,c,d,e);
console.log(result.toString())
debugger;
return result;
}
四、根据url的特征进行断点
复制url的一部分,在XHR 中输入,刷新页面即可等待中断,然后进行栈回溯找参数的加密方法。存在一些请求不适用,不会断下来。
五、让控制台输出加密日志
在加密函数下log断点,填写加密函数回车,看到粉色即成功
控制台即可看到加密函数所有历史输出记录,从而判断某些参数是如何生成的
六、常见hook脚本
1.过无限debugger
var _constructor = constructor;
Function.prototype.constructor = function(s) {
if (s == "debugger") {
console.log(s);
return null;
}
return _constructor(s);
}
//去除无限debugger
Function.prototype.__constructor_back = Function.prototype.constructor ;
Function.prototype.constructor = function() {
if(arguments && typeof arguments[0]==='string'){
//alert("new function: "+ arguments[0]);
if( "debugger" === arguments[0]){
// arguments[0]="consoLe.Log(\"anti debugger\");";
//arguments[0]=";";
return
}
}
return Function.prototype.__constructor_back.apply(this,arguments);
};
var _Function = Function;
Function = function(s) {
if (s == "debugger") {
console.log(s);
return null;
}
return _Function(s);
}
2.cookie生成的位置
(function () {
// 严谨模式 检查所有错误
'use strict';
// document 为要hook的对象 这里是hook的cookie
var cookieTemp = "";
Object.defineProperty(document, 'cookie', {
// hook set方法也就是赋值的方法
set: function (val) {
// 这样就可以快速给下面这个代码行下断点
// 从而快速定位设置cookie的代码
if (val.indexOf('FSSBBIl1UgzbN7N80T') != -1) {
debugger;
}
console.log('Hook捕获到cookie设置->', val);
cookieTemp = val;
return val;
}, // hook get 方法也就是取值的方法
get: function () {
return cookieTemp;
}
});
})();
3.js补环境自动吐算法
使用方法:放在扣出来的代码最前面
function get_enviroment(proxy_array) {
for (var i = 0; i < proxy_array.length; i++) {
handler = '{\n' +
' get: function(target, property, receiver) {\n' +
' console.log("方法:", "get ", "对象:", ' +
'"' + proxy_array[i] + '" ,' +
'" 属性:", property, ' +
'" 属性类型:", ' + 'typeof property, ' +
// '" 属性值:", ' + 'target[property], ' +
'" 属性值类型:", typeof target[property]);\n' +
' return target[property];\n' +
' },\n' +
' set: function(target, property, value, receiver) {\n' +
' console.log("方法:", "set ", "对象:", ' +
'"' + proxy_array[i] + '" ,' +
'" 属性:", property, ' +
'" 属性类型:", ' + 'typeof property, ' +
// '" 属性值:", ' + 'target[property], ' +
'" 属性值类型:", typeof target[property]);\n' +
' return Reflect.set(...arguments);\n' +
' }\n' +
'}'
eval('try{\n' + proxy_array[i] + ';\n'
+ proxy_array[i] + '=new Proxy(' + proxy_array[i] + ', ' + handler + ')}catch (e) {\n' + proxy_array[i] + '={};\n'
+ proxy_array[i] + '=new Proxy(' + proxy_array[i] + ', ' + handler + ')}')
}
}
proxy_array = ['window', 'document', 'location', 'navigator', 'history', 'screen', 'aaa', 'target']
get_enviroment(proxy_array);
4.请求头header参数hook
var code = function(){
var org = window.XMLHttpRequest.prototype.setRequestHeader;
window.XMLHttpRequest.prototype.setRequestHeader = function(key,value){
if(key=='Authorization'){
debugger;
}
return org.apply(this,arguments);
}
}
var script = document.createElement('script');
script.textContent = '(' + code + ')()';
(document.head||document.documentElement).appendChild(script);
script.parentNode.removeChild(script);
5.url包含某字符串hook
var code = function(){
var open = window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function (method, url, async){
if (url.indexOf("gdgshseeqqp")>-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);
6.JSON HOOK
var my_stringify = JSON.stringify;
JSON.stringify = function (params) {
//这里可以添加其他逻辑比如
debugger
console.log("json_stringify params:",params);
return my_stringify(params);
};