it-swarm.cn

Facebook如何禁用浏览器的集成开发人员工具?

显然,由于最近的骗局,开发人员工具被人们利用来发布垃圾邮件,甚至用来“破解”帐户。 Facebook已经阻止了开发人员工具,我甚至无法使用控制台。

Enter image description here

他们是怎么做到的?? One Stack Overflow帖子声称这是不可能的 ,但Facebook证明他们错了。

只需转到Facebook并打开开发人员工具,在控制台中键入一个字符,然后弹出此警告。无论你投入什么,它都不会被执行。

这怎么可能?

他们甚至在控制台中阻止了自动完成:

Enter image description here

1617
Derek 朕會功夫

我是Facebook的安全工程师,这是我的错。我们正在为一些用户测试这一点,看看它是否可以减慢一些用户被欺骗将(恶意)JavaScript代码粘贴到浏览器控制台中的攻击。

需要明确的是:试图阻止黑客客户端是 坏主意 一般来说; 这是为了防范 特定社会工程攻击

如果你最终进入测试组并对此感到恼火,抱歉。我试图让旧的退出页面(现在 帮助页面 )尽可能简单,同时仍然是可怕的足以阻止至少某些受害者。

实际代码非常类似于 @ joeldixon66的链接 ;没有充分理由,我们的情况要复杂得多。

Chrome将所有控制台代码包装在中

with ((console && console._commandLineAPI) || {}) {
  <code goes here>
}

...所以该网站重新定义console._commandLineAPI以抛出:

Object.defineProperty(console, '_commandLineAPI',
   { get : function() { throw 'Nooo!' } })

这是 不够(试试吧!) ,但这是主要技巧。


结语:Chrome团队认为从用户端JS中击败控制台是一个错误并且 修复了问题 ,使这种技术无效。之后,为 保护用户免受自我xss 添加了额外的保护。 

2339
Alf

我使用Chrome开发人员工具找到了Facebook的控制台破坏程序脚本。以下是可读性稍有变化的脚本。我删除了一些我无法理解的内容:

Object.defineProperty(window, "console", {
    value: console,
    writable: false,
    configurable: false
});

var i = 0;
function showWarningAndThrow() {
    if (!i) {
        setTimeout(function () {
            console.log("%cWarning message", "font: 2em sans-serif; color: yellow; background-color: red;");
        }, 1);
        i = 1;
    }
    throw "Console is disabled";
}

var l, n = {
        set: function (o) {
            l = o;
        },
        get: function () {
            showWarningAndThrow();
            return l;
        }
    };
Object.defineProperty(console, "_commandLineAPI", n);
Object.defineProperty(console, "__commandLineAPI", n);

这样,控制台自动完成将无声地失败,而在控制台中键入的语句将无法执行(将记录异常)。

参考文献:

78
Salman A

我无法在任何页面上触发它。一个更强大的版本可以做到这一点:

window.console.log = function(){
    console.error('The developer console is temp...');
    window.console.log = function() {
        return false;
    }
}

console.log('test');

设置输出样式: JavaScript控制台中的颜色

编辑 思考 @ joeldixon66 有正确的想法: 从控制台禁用JavaScript执行«::: KSpace :::

38
Will

Netflix也实现了这一功能

(function() {
    try {
        var $_console$$ = console;
        Object.defineProperty(window, "console", {
            get: function() {
                if ($_console$$._commandLineAPI)
                    throw "Sorry, for security reasons, the script console is deactivated on netflix.com";
                return $_console$$
            },
            set: function($val$$) {
                $_console$$ = $val$$
            }
        })
    } catch ($ignore$$) {
    }
})();

它们只是覆盖console._commandLineAPI以引发安全性错误。

22
Fizer Khan

这实际上是可能的,因为Facebook能够做到这一点。[。_____。]嗯,不是实际的Web开发人员工具,而是在控制台中执行Javascript。

看到: Facebook如何禁用浏览器的集成开发人员工具?

这真的不会做太多,因为有其他方法可以绕过这种类型的客户端安全性。

当你说它是客户端时,它发生在服务器的控制之外,因此你无能为力。如果你问为什么Facebook仍然这样做,这不是为了安全,而是为了保护那些不知道javascript的普通用户运行代码(他们不知道如何阅读)进入控制台。这对于承诺自动提供服务或其他Facebook功能机器人的网站来说很常见,因为在您执行他们要求您执行的操作之后,在大多数情况下,他们会为您提供在控制台中运行的javascript片段。

如果你没有Facebook那样多的用户,那么我认为没有必要去做Facebook正在做的事情。

即使你在控制台中禁用Javascript,仍然可以通过地址栏运行javascript。

enter image description here

enter image description here

如果浏览器在地址栏中禁用了javascript,(当您将代码粘贴到Google Chrome中的地址栏时,它会删除短语'javascript:')将javascript粘贴到其中一个链接中仍然可以通过inspect元素。

检查锚点:

enter image description here

在href中粘贴代码:

enter image description here

enter image description here

enter image description here

底线是服务器端验证,安全应该是第一个,然后是客户端。

20
Jomar Sevillejo

自从facebook可以禁用控制台以来,Chrome改变了很多... 

截至2017年3月,这不再适用。 

你可以做的最好是禁用一些控制台功能,例如:

if(!window.console) window.console = {};
var methods = ["log", "debug", "warn", "info", "dir", "dirxml", "trace", "profile"];
for(var i=0;i<methods.length;i++){
    console[methods[i]] = function(){};
}
7
Alpha2k

我的简单方法,但它可以帮助进一步改变这个主题。列出所有方法并将它们改为无用。

  Object.getOwnPropertyNames(console).filter(function(property) {
     return typeof console[property] == 'function';
  }).forEach(function (verb) {
     console[verb] =function(){return 'Sorry, for security reasons...';};
  });
6
Dusan Krstic

内部devtools将一个名为getCompletions的IIFE注入到页面中,当在Devtools控制台中按下某个键时调用它。 

查看该函数的 ,它使用了一些可以覆盖的全局函数。

通过使用 Error 构造函数,可以获得调用堆栈,当Devtools调用时,它将包含getCompletions


示例:

const disableDevtools = callback => {
  const original = Object.getPrototypeOf;

  Object.getPrototypeOf = (...args) => {
    if (Error().stack.includes("getCompletions")) callback();
    return original(...args);
  };
};

disableDevtools(() => {
  console.error("devtools has been disabled");

  while (1);
});

3
samdd

简单的解决方案!

setInterval(()=>console.clear(),1500);
2
Mohmmad Ebrahimi Aval

我会一路走来:

Object.defineProperty(window, 'console', {
  get: function() {

  },
  set: function() {

  }
});
0
Zibri

这不是弱代码无人看管的安全措施。在实施此策略之前,始终要获得弱代码的永久解决方案并正确保护您的网站

到目前为止,根据我的知识,最好的工具是添加多个javascript文件,只需通过刷新或替换内容就可以将页面的完整性恢复正常。禁用此开发人员工具不是最好的主意,因为绕过问题始终存在问题,因为代码是浏览器的一部分而不是服务器呈现,因此可能会被破解。 

如果js file one检查重要元素的<element>更改,js file twojs file three检查此文件是否存在于每个期间,您将在该期间内在页面上进行完整的完整性恢复。 

让我们举一个4个文件的例子,告诉你我的意思。 

index.html

   <!DOCTYPE html>
   <html>
   <head id="mainhead">
   <script src="ks.js" id="ksjs"></script>
   <script src="mainfile.js" id="mainjs"></script>
   <link rel="stylesheet" href="style.css" id="style">
   <meta id="meta1" name="description" content="Proper mitigation against script kiddies via Javascript" >
   </head>
   <body>
   <h1 id="heading" name="dontdel" value="2">Delete this from console and it will refresh. If you change the name attribute in this it will also refresh. This is mitigating an attack on attribute change via console to exploit vulnerabilities. You can even try and change the value attribute from 2 to anything you like. If This script says it is 2 it should be 2 or it will refresh. </h1>
   <h3>Deleting this wont refresh the page due to it having no integrity check on it</h3>

   <p>You can also add this type of error checking on meta tags and add one script out of the head tag to check for changes in the head tag. You can add many js files to ensure an attacker cannot delete all in the second it takes to refresh. Be creative and make this your own as your website needs it. 
   </p>

   <p>This is not the end of it since we can still enter any tag to load anything from everywhere (Dependent on headers etc) but we want to prevent the important ones like an override in meta tags that load headers. The console is designed to edit html but that could add potential html that is dangerous. You should not be able to enter any meta tags into this document unless it is as specified by the ks.js file as permissable. <br>This is not only possible with meta tags but you can do this for important tags like input and script. This is not a replacement for headers!!! Add your headers aswell and protect them with this method.</p>
   </body>
   <script src="ps.js" id="psjs"></script>
   </html>

mainfile.js

   setInterval(function() {
   // check for existence of other scripts. This part will go in all other files to check for this file aswell. 
   var ksExists = document.getElementById("ksjs"); 
   if(ksExists) {
   }else{ location.reload();};

   var psExists = document.getElementById("psjs");
   if(psExists) {
   }else{ location.reload();};

   var styleExists = document.getElementById("style");
   if(styleExists) {
   }else{ location.reload();};


   }, 1 * 1000); // 1 * 1000 milsec

ps.js

   /*This script checks if mainjs exists as an element. If main js is not existent as an id in the html file reload!You can add this to all js files to ensure that your page integrity is perfect every second. If the page integrity is bad it reloads the page automatically and the process is restarted. This will blind an attacker as he has one second to disable every javascript file in your system which is impossible.

   */

   setInterval(function() {
   // check for existence of other scripts. This part will go in all other files to check for this file aswell. 
   var mainExists = document.getElementById("mainjs"); 
   if(mainExists) {
   }else{ location.reload();};

   //check that heading with id exists and name tag is dontdel.
   var headingExists = document.getElementById("heading"); 
   if(headingExists) {
   }else{ location.reload();};
   var integrityHeading = headingExists.getAttribute('name');
   if(integrityHeading == 'dontdel') {
   }else{ location.reload();};
   var integrity2Heading = headingExists.getAttribute('value');
   if(integrity2Heading == '2') {
   }else{ location.reload();};
   //check that all meta tags stay there
   var meta1Exists = document.getElementById("meta1"); 
   if(meta1Exists) {
   }else{ location.reload();};

   var headExists = document.getElementById("mainhead"); 
   if(headExists) {
   }else{ location.reload();};

   }, 1 * 1000); // 1 * 1000 milsec

ks.js

   /*This script checks if mainjs exists as an element. If main js is not existent as an id in the html file reload! You can add this to all js files to ensure that your page integrity is perfect every second. If the page integrity is bad it reloads the page automatically and the process is restarted. This will blind an attacker as he has one second to disable every javascript file in your system which is impossible.

   */

   setInterval(function() {
   // check for existence of other scripts. This part will go in all other files to check for this file aswell. 
   var mainExists = document.getElementById("mainjs"); 
   if(mainExists) {
   }else{ location.reload();};
   //Check meta tag 1 for content changes. meta1 will always be 0. This you do for each meta on the page to ensure content credibility. No one will change a meta and get away with it. Addition of a meta in spot 10, say a meta after the id="meta10" should also be covered as below.
   var x = document.getElementsByTagName("meta")[0];
   var p = x.getAttribute("name");
   var s = x.getAttribute("content");
   if (p != 'description') {
   location.reload();
   }
   if ( s != 'Proper mitigation against script kiddies via Javascript') {
   location.reload();
   }
   // This will prevent a meta tag after this meta tag @ id="meta1". This prevents new meta tags from being added to your pages. This can be used for scripts or any tag you feel is needed to do integrity check on like inputs and scripts. (Yet again. It is not a replacement for headers to be added. Add your headers aswell!)
   var lastMeta = document.getElementsByTagName("meta")[1];
   if (lastMeta) {
   location.reload();
   }
   }, 1 * 1000); // 1 * 1000 milsec

style.css

现在这只是为了表明它适用于所有文件和标签

   #heading {
   background-color:red;
   }

如果将所有这些文件放在一起并构建示例,您将看到此度量的功能。如果您在索引文件中的所有重要元素上正确实现它,这将防止一些不可预测的注入,尤其是在使用PHP时。

为什么我选择重新加载而不是将每个属性更改回正常值是因为某些攻击者可能已经配置并准备好了网站的另一部分并且减少了代码量。重新加载将删除所有攻击者的辛勤工作,他可能会更容易在某个地方玩。

另一个注意事项: 这可能会成为很多代码,因此请保持清洁,并确保将定义添加到它们所属的位置,以便将来轻松编辑。同时将秒数设置为您的首选金额,因为大页面上的1秒间隔可能会对访问者可能使用的旧计算机产生严重影响

0
user9374996