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 = constructorFunction.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){}; 时,要在文件一开始执行,否则有时会报错。