zy-补环境框架-实现-window补环境

This commit is contained in:
aiyingfeng 2023-08-12 15:11:22 +08:00
parent 1848ba9982
commit 71808525cb
3 changed files with 149 additions and 0 deletions

View File

@ -0,0 +1,128 @@
项目参考js逆向之模拟浏览器环境
https://hexo-fanchangrui.vercel.app/2022/08/05/js%E9%80%86%E5%90%91%E4%B9%8B%E6%A8%A1%E6%8B%9F%E6%B5%8F%E8%A7%88%E5%99%A8%E7%8E%AF%E5%A2%83/
# 补环境框架实现
```
.
├── CatVm2 文件目录
│ ├── browser 浏览器环境
│ │ ├── HTMLElements
│ │ │ ├── htmlDivElement.js
│ │ │ ├── htmlElements.node.js
│ │ ├── document.js
│ │ ├── eventTarget.js
│ │ ├── history.js
│ │ ├── htmlDocument.js
│ │ ├── location.js
│ │ ├── mimeType.js
│ │ ├── mimeTypeArray.js
│ │ ├── navigator.js
│ │ ├── plugin.js
│ │ ├── pluginArray.js
│ │ ├── screen.js
│ │ ├── storage.js
│ │ ├── window.js window环境
│ │ ├── windowProperties.js
│ │── tools
│ │ ├── memory.js 框架运行内存
│ │ ├── node.js 将工具代码组合
│ │ ├── print.js 框架日志功能
│ │ ├── proxy.js 框架代理功能
│ │ ├── safefunction.js 补环境的自定义方法
│ │ ├── tools.js 更改浏览器某些参数
│ │─── catvm2.node.js 补环境的拼接代码
├── code.js 原代码
├── index.js 启动代码
├── README.md 文档
```
## 补window环境原型链
![debugger](./img/1.png)
先尝试补一个window原型WINDOW_AYF
```javascript
function WINDOW_AYF(){}
window_ayf = {};
window_ayf.__proto__ = WINDOW_AYF.prototype;
Object.defineProperties(WINDOW_AYF.prototype,{
[Symbol.toStringTag]:{
value:'WINDOW_AYF',
configurable:true,
}
})
```
控制台对比效果
![debugger](./img/2.png)
在构建原型`WindowProperties_ayf`
```javascript
function WINDOW_AYF(){}
window_ayf = {};
window_ayf.__proto__ = WINDOW_AYF.prototype;
Object.defineProperties(WINDOW_AYF.prototype,{
[Symbol.toStringTag]:{
value:'WINDOW_AYF',
configurable:true,
}
})
function WindowProperties_ayf(){}
WINDOW_AYF.prototype.__proto__ = WindowProperties_ayf.prototype;
Object.defineProperties(WindowProperties_ayf.prototype,{
[Symbol.toStringTag]:{
value:'WindowProperties_ayf',
configurable:true,
}
})
```
控制台对比效果
![debugger](./img/3.png)
最后构建原型`EventTarget_ayf`
```javascript
function WINDOW_AYF(){}
window_ayf = {};
window_ayf.__proto__ = WINDOW_AYF.prototype;
Object.defineProperties(WINDOW_AYF.prototype,{
[Symbol.toStringTag]:{
value:'WINDOW_AYF',
configurable:true,
}
})
function WindowProperties_ayf(){}
WINDOW_AYF.prototype.__proto__ = WindowProperties_ayf.prototype;
Object.defineProperties(WindowProperties_ayf.prototype,{
[Symbol.toStringTag]:{
value:'WindowProperties_ayf',
configurable:true,
}
})
function EventTarget_ayf(){}
WindowProperties_ayf.prototype.__proto__ = EventTarget_ayf.prototype;
Object.defineProperties(EventTarget_ayf.prototype,{
[Symbol.toStringTag]:{
value:'EventTarget_ayf',
configurable:true,
}
})
```
控制台对比效果
![debugger](./img/4.png)

View File

@ -0,0 +1,21 @@
import fs from 'fs';
// 从 vm2 模块中导入了 VM 和 VMScript 两个类
import {VM, VMScript} from 'vm2';
// 引入需要执行的js文件
import cat_vm2 from './CatVm2/catvm2.node.js';
import path from 'path';
// 获取当前文件的目录
import {fileURLToPath} from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const cat_vm2_code = cat_vm2({proxy: true});
const code_file = `${__dirname}/code.js`;
const vm = new VM()
const script = new VMScript(cat_vm2_code + fs.readFileSync(code_file), `${__dirname}/调试.js`);
debugger
vm.run(script);
debugger