FireFox JavaScript修改window.navigator对象实现随机useragent、platform、language等属性

April 23, 2015

Tags:trick

最近在测试crack某种用户信息统计功能,顺手研究了下这个“全局污染”,没太注意coding style 权当抛砖引玉~ 适合伪造数据,防止被其他站的统计代码拿走真实浏览器和系统标识

randomBrowserProper = function(){
                var ua = ["Fake Mozilla", "Fake IE", "Faker"];
                var platform = ["Linux", "win32", "bsd"];
                var language = ["zh", "fr", "birds"];
                navigator = window.navigator;
                if (navigator.__defineGetter__) {
                    navigator.__defineGetter__("userAgent", function () { return ua[Math.floor(Math.random()*ua.length+0)];});
                    navigator.__defineGetter__("platform", function () { return platform[Math.floor(Math.random()*platform.length+0)];});
                    navigator.__defineGetter__("language", function () { return language[Math.floor(Math.random()*language.length+0)]; });

                } else if (Object.defineProperty) { 
                    Object.defineProperty(navigator, "userAgent", { 
                        get: function () { 
                            return ua[Math.floor(Math.random()*ua.length+0)];
                        }
                    });
                    Object.defineProperty(navigator, "platform", { 
                        get: function () { 
                            return platform[Math.floor(Math.random()*platform.length+0)];
                        }
                    });
                    Object.defineProperty(navigator, "language", { 
                        get: function () { 
                            return language[Math.floor(Math.random()*language.length+0)];
                        }
                    }  );                                      
                }                
            }
randomBrowserProper();

参考
Object.prototype.defineGetter()

· EOF ·