☰
补环境常见检测点以及瑞数补环境框架
2026/11/6 1:18:05 网站建设 项目流程

补环境常见检测点与Node.js模拟

前言

通常我们在进行js逆向的时候,会发现js文件它通过检测大量的浏览器环境特征来区分真实浏览器和自动化脚本/模拟环境。本文将分析补环境的关键环境检测点,并探讨如何在Node.js环境中进行有效模拟。

环境检测点详解

1. Window对象属性存在性检测

检测含义与目的
  • 检测浏览器特有的全局对象和属性是否存在
  • 验证环境是否具备完整的浏览器特性集合
  • 识别非浏览器环境(如Node.js)中缺失的浏览器特有属性
检测点
'chrome'inwindow'webkit'inwindow'localStorage'inwindow'sessionStorage'inwindow
Node.js模拟方案
Object.defineProperties(global,{chrome:{value:{runtime:{},loadTimes:()=>({})},writable:false,configurable:false},webkit:{value:{messageHandlers:{}},writable:false,configurable:false}});classMockStorage{constructor(){this.store=newMap();}getItem(key){returnthis.store.get(key)||null;}setItem(key,value){this.store.set(key,String(value));}removeItem(key){this.store.delete(key);}clear(){this.store.clear();}getlength(){returnthis.store.size;}key(index){returnArray.from(this.store.keys())[index];}}global.localStorage=newMockStorage();global.sessionStorage=newMockStorage();

2. 属性描述符检测

检测含义与目的
  • 验证浏览器内置属性的描述符特征
  • 检测环境是否正确实现了属性描述符标准
  • 识别通过简单赋值模拟的属性(缺少正确的描述符配置)
检测点
Object.getOwnPropertyDescriptor(window,'chrome')Object.getOwnPropertyDescriptor(navigator,'userAgent')
Node.js模拟方案
constdefinePropertyWithDescriptor=(obj,prop,value)=>{Object.defineProperty(obj,prop,{value,writable:false,enumerable:true,configurable:false});};definePropertyWithDescriptor(global,'chrome',{runtime:{},loadTimes:()=>({})});definePropertyWithDescriptor(global.navigator,'userAgent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36');

3. Navigator对象硬件信息检测

检测含义与目的
  • 获取用户设备的硬件配置信息
  • 检测环境是否提供合理的硬件参数
  • 识别虚拟机或自动化环境中的异常硬件配置
检测点
navigator.hardwareConcurrency navigator.deviceMemory navigator.webdriver
Node.js模拟方案
Object.defineProperties(global.navigator,{hardwareConcurrency:{value:8,writable:false,configurable:false},deviceMemory:{value:8,writable:false,configurable:false},webdriver:{value:false,writable:false,configurable:false}});

4. Battery API检测

检测含义与目的
  • 检测设备电池状态API的可用性
  • 验证Promise-based API的正确实现
  • 识别缺乏硬件相关API的模拟环境
检测点
navigator.getBattery().then(battery=>{console.log(battery.level,battery.charging);});
Node.js模拟方案
constmockBattery={level:0.85,charging:true,chargingTime:1800,dischargingTime:Infinity,onchargingchange:null,onlevelchange:null,onchargingtimechange:null,ondischargingtimechange:null};Object.defineProperty(global.navigator,'getBattery',{value:()=>Promise.resolve(mockBattery),writable:false,configurable:false});

5. 插件和MIME类型检测

检测含义与目的
  • 检测浏览器插件生态系统的完整性
  • 验证插件与MIME类型的关联关系
  • 识别缺乏常见浏览器插件的自动化环境
检测点
navigator.plugins navigator.mimeTypes
Node.js模拟方案
constmockPlugins=[{name:'Chrome PDF Plugin',filename:'internal-pdf-viewer',description:'Portable Document Format',length:1}];Object.defineProperty(global.navigator,'plugins',{value:mockPlugins,writable:false,configurable:false});constmockMimeTypes=[{type:'application/pdf',description:'Portable Document Format',suffixes:'pdf',enabledPlugin:mockPlugins[0]}];Object.defineProperty(global.navigator,'mimeTypes',{value:mockMimeTypes,writable:false,configurable:false});

6. 屏幕属性检测

检测含义与目的
  • 获取用户屏幕的物理特性参数
  • 检测屏幕配置的合理性和一致性
  • 识别异常的屏幕配置(如零尺寸或极端值)
检测点
screen.width screen.height screen.colorDepth screen.pixelDepth screen.availWidth screen.availHeight
Node.js模拟方案
Object.defineProperties(global.screen,{width:{value:1920,writable:false,configurable:false},height:{value:1080,writable:false,configurable:false},colorDepth:{value:24,writable:false,configurable:false},pixelDepth:{value:24,writable:false,configurable:false},availWidth:{value:1920,writable:false,configurable:false},availHeight:{value:1040,writable:false,configurable:false}});

7. 原型链toString检测

检测含义与目的
  • 验证对象内部[[Class]]属性的正确性
  • 检测对象原型链的完整性
  • 识别通过简单对象模拟的内置对象
检测点
Object.prototype.toString.call(navigator)Object.prototype.toString.call(screen)Object.prototype.toString.call([])
Node.js模拟方案
constoriginalToString=Object.prototype.toString;Object.prototype.toString=function(){if(this===global.navigator)return'[object Navigator]';if(this===global.screen)return'[object Screen]';if(this===global)return'[object Window]';if(Array.isArray(this))return'[object Array]';returnoriginalToString.call(this);};

8. 时区和语言检测

检测含义与目的
  • 检测用户的地理位置和语言偏好
  • 验证国际化API的正确实现
  • 识别配置异常或缺乏国际化支持的环境
检测点
Intl.DateTimeFormat().resolvedOptions().timeZone navigator.language navigator.languages
Node.js模拟方案
Object.defineProperties(global.navigator,{language:{value:'zh-CN',writable:false,configurable:false},languages:{value:['zh-CN','zh','en'],writable:false,configurable:false}});constoriginalDateTimeFormat=Intl.DateTimeFormat;Intl.DateTimeFormat=function(locales,options){constopts=options||{};if(!opts.timeZone){opts.timeZone='Asia/Shanghai';}returnoriginalDateTimeFormat(locales,opts);};

9. 媒体能力检测

检测含义与目的
  • 检测浏览器对多媒体格式的支持能力
  • 验证HTMLMediaElement API的正确实现
  • 识别缺乏媒体支持或支持异常的自动化环境
检测点
constvideo=document.createElement('video');video.canPlayType('video/mp4')video.canPlayType('video/webm')
Node.js模拟方案
global.document={createElement:(tagName)=>{constelement={tagName:tagName.toLowerCase()};if(tagName.toLowerCase()==='video'||tagName.toLowerCase()==='audio'){element.canPlayType=(type)=>{constsupportedTypes={'video/mp4':'probably','video/webm':'maybe','audio/mp3':'probably','audio/wav':'maybe','audio/mpeg':'probably'};returnsupportedTypes[type]||'';};}returnelement;}};

10. 字体检测

检测含义与目的
  • 检测系统字体的可用性和多样性
  • 验证CSS Font Loading API的实现
  • 识别缺乏字体多样性或字体API异常的环境
检测点
document.fonts.check('12px Arial')document.fonts.check('12px "Microsoft YaHei"')
Node.js模拟方案
Object.defineProperty(global.document,'fonts',{value:{check:(fontSpec)=>{constcommonFonts=['Arial','Times New Roman','Courier New','Verdana','Microsoft YaHei','SimSun','SimHei','KaiTi'];returncommonFonts.some(font=>fontSpec.includes(font));},ready:Promise.resolve(),add:()=>{},delete:()=>{},clear:()=>{},load:()=>Promise.resolve()},writable:false,configurable:false});

11. Performance API检测

检测含义与目的
  • 检测性能时间线的准确性和合理性
  • 验证高精度时间API的实现
  • 识别性能数据异常或缺乏性能监控的环境
检测点
performance.now()performance.timing performance.memory
Node.js模拟方案
classMockPerformance{constructor(){this.startTime=Date.now();this.timing={navigationStart:this.startTime-1000,loadEventEnd:this.startTime,domainLookupStart:this.startTime-800,domainLookupEnd:this.startTime-700,connectStart:this.startTime-700,connectEnd:this.startTime-600,requestStart:this.startTime-500,responseStart:this.startTime-300,responseEnd:this.startTime-200,domLoading:this.startTime-150,domInteractive:this.startTime-100,domContentLoadedEventStart:this.startTime-50,domContentLoadedEventEnd:this.startTime-40,domComplete:this.startTime-20,loadEventStart:this.startTime-10};}now(){returnDate.now()-this.startTime;}}global.performance=newMockPerformance();if(global.chrome){Object.defineProperty(global.performance,'memory',{value:{usedJSHeapSize:10000000,totalJSHeapSize:20000000,jsHeapSizeLimit:400000000},writable:false,configurable:false});}

12. WebGL检测

检测含义与目的
  • 检测图形渲染能力和硬件加速支持
  • 验证WebGL API的完整性和正确性
  • 识别缺乏图形支持或WebGL实现异常的环境
检测点
constcanvas=document.createElement('canvas');constgl=canvas.getContext('webgl');gl.getParameter(0x1F00)gl.getParameter(0x1F01)
Node.js模拟方案
constoriginalCreateElement=global.document.createElement;global.document.createElement=function(tagName){constelement=originalCreateElement.call(this,tagName);if(tagName.toLowerCase()==='canvas'){element.getContext=(contextType)=>{if(contextType==='webgl'||contextType==='experimental-webgl'){return{getParameter:(param)=>{constparams={0x1F00:'Google Inc. (Apple)',0x1F01:'Apple A15 GPU',0x1F03:'WebGL 2.0',0x8B64:'WebGL GLSL ES 1.0',0x8B8C:4096};returnparams[param]||null;},getExtension:()=>null,getSupportedExtensions:()=>['ANGLE_instanced_arrays','EXT_blend_minmax','EXT_texture_filter_anisotropic'],clear:()=>{},drawArrays:()=>{}};}returnnull;};}returnelement;};

瑞数补环境框架

最近本人做了一个瑞数的补环境框架,通杀瑞数4\5\6代瑞数,有兴趣的可以一起交流一下




免责声明:本文内容仅供技术研究和学习之用,请遵守相关法律法规和网站使用条款,不得用于非法用途。

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询