简体   繁体   English

我的Greasemonkey脚本在我的PC之外可见吗?

[英]Are my Greasemonkey scripts visible outside my PC?

Forgive me if this is a dumb question. 如果这是一个愚蠢的问题,请原谅我。 I'm not familiar with how browser scripts are handled. 我不熟悉浏览器脚本的处理方式。

I'm writing a short Greasemonkey script that involves auto-logging me into a website, which of course involves inserting my password. 我正在编写一个简短的Greasemonkey脚本,涉及自动将我登录到网站,当然还涉及插入密码。 I was planning to just include my password in the script itself, but I'm concerned that if it's possible for anyone else to see my script, they will also see my password. 我原本打算只在脚本本身中包含密码,但是我担心如果其他人有可能看到我的脚本,他们也会看到我的密码。

So my question is, is it possible for my script to be seen by anyone/anything beyond my browser and local PC? 所以我的问题是,我的脚本是否可能被我的浏览器和本地PC之外的任何人/任何人看到? I'm not talking about anyone else using my computer, but anyone "probing" or otherwise inspecting my browser from elsewhere on the net. 我不是在谈论使用我的计算机的任何其他人,而是任何在网络上其他地方“探测”或检查我的浏览器的人。

If so, how can I store my password so it can be auto-inserted without sacrificing my security? 如果是这样,我如何存储密码,以便在不牺牲安全性的情况下将其自动插入?

Nominally, no. 名义上,不。 Greasemonkey scripts are not any more visible outside your PC than any other unencrypted file on your hard drive. 与您的硬盘驱动器上的任何其他未加密文件相比,在计算机外部看不到Greasemonkey脚本。

That said, there are several things to keep in mind: 就是说,有几件事要牢记:

  1. Use a password utility instead. 请改用密码实用程序。
    Use trusted utilities that are designed to work-with and secure passwords as much as possible. 使用旨在与密码一起使用并尽可能保护密码的可信实用程序。 As mentioned, LastPass is pretty popular. 如前所述, LastPass非常受欢迎。 I have also used Secure Login to good effect. 我还使用了安全登录以取得良好的效果。

    Admittedly, these utilities do not work for every situation, since so many sites insist on their own variations of a login page/system. 不可否认,这些实用程序并不能在每种情况下都起作用,因为太多的站点坚持使用自己的登录页面/系统。 So, I personally do use Greasemonkey scripts to log into a few low-risk websites. 因此,我个人确实使用Greasemonkey脚本登录了一些低风险的网站。

  2. Never use an auto-login for sensitive sites. 切勿对敏感站点使用自动登录。 If you use a script for a bank, credit-card, important work database, etc. Somebody will be sitting at your computer some day and they will visit that site (and be automatically logged in), and bad things will happen. 如果您将脚本用于银行,信用卡,重要工作数据库等。某天某人坐在您的计算机上,他们访问该站点(并自动登录),并且发生不良情况。 Bank on it. 靠它。
    Now, I know that some will (foolishly) ignore this. 现在,我知道有些人(愚蠢地)会忽略这一点。 But, if you do, at least have the login triggered by a hotkey or hotkey sequence -- never fully automatic. 但是,如果您这样做了,至少登录是由热键或热键序列触发的-永远不要完全自动。

  3. Beware unsafeWindow . 当心unsafeWindow
    Greasemonkey scripts used to be vulnerable to an exploit against unsafeWindow . Greasemonkey脚本以前容易受到针对unsafeWindow的攻击。 While I believe that this vulnerability was closed by Firefox version 4 (The old exploit recipe certainly does not work with modern GM+FF), an unsafeWindow exploit would allow a compromised web page to see parts of your script source and to use GM_ functions. 尽管我认为该漏洞已由Firefox 4(以前的漏洞利用方法当然不适用于现代GM + FF)关闭,但unsafeWindow漏洞利用将允许被入侵的网页查看脚本源的某些部分并使用GM_函数。

    So, for login scripts especially, don't use unsafeWindow . 因此,尤其是对于登录脚本,请不要使用unsafeWindow

  4. Never include a real password in any source file. 不得包含任何源文件真实密码。
    Don't make it so easy for prying eyes or malware to get your password! 别轻易撬开眼睛或恶意软件来获取密码! This has been an easy route to pwn-dom for decades, and yet people still get burned by this -- probably every day. 数十年来,这一直是通往Pdom-dom的简便途径,但人们仍然为此感到烦恼-也许每天都有。

  5. Don't store passwords in clear text. 不要以明文形式存储密码。 and don't use "password" and "username", for variable names. 并且不要将“ password”和“ username”用作变量名。 This won't stop a determined bad guy, but it will slow down "honest" snoops and script-kiddies. 这不会阻止一个坚定的坏人,但是会减慢“诚实的”侦探和脚本小子。


Here is the Greasemonkey script framework I use on the two pages where I automatically login (both are forums, low-risk, low sensitivity). 这是我在自动登录的两个页面上使用的Greasemonkey脚本框架(都是论坛,低风险,低敏感度)。

The username and password are stored in the browser prefs database (visible via about:config ), not the script source. 用户名和密码存储在浏览器prefs数据库中(可通过about:config ),而不是脚本源。 They are lightly encrypted to slow down snoops. 对其进行了轻微加密,以减慢侦听速度。

The first time you run the script, it will prompt for a random key and for the username and password. 首次运行该脚本时,它将提示您输入随机密钥以及用户名和密码。 After that, the username and password can be changed via the Greasemonkey context menu. 之后,可以通过Greasemonkey上下文菜单更改用户名和密码。

// ==UserScript==
// @name     _Autologin, sensitive info framework
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @require  http://crypto.stanford.edu/sjcl/sjcl.js
// @grant    GM_getValue
// @grant    GM_setValue
// @grant    GM_registerMenuCommand
// ==/UserScript==

var encKey  = GM_getValue ("encKey",  "");
var usr     = GM_getValue ("lognUsr", "");
var pword   = GM_getValue ("lognPwd", "");

if ( ! encKey) {
    encKey  = prompt (
        'Script key not set for ' + location.hostname + '. Please enter a random string:',
        ''
    );
    GM_setValue ("encKey", encKey);

    usr     = pword = "";   // New key makes prev stored values (if any) unable to decode.
}
usr         = decodeOrPrompt (usr,   "U-name", "lognUsr");
pword       = decodeOrPrompt (pword, "P-word", "lognPwd");


function decodeOrPrompt (targVar, userPrompt, setValVarName) {
    if (targVar) {
        targVar     = unStoreAndDecrypt (targVar);
    }
    else {
        targVar     = prompt (
            userPrompt + ' not set for ' + location.hostname + '. Please enter it now:',
            ''
        );
        GM_setValue (setValVarName, encryptAndStore (targVar) );
    }
    return targVar;
}

function encryptAndStore (clearText) {
    return  JSON.stringify (sjcl.encrypt (encKey, clearText) );
}

function unStoreAndDecrypt (jsonObj) {
    return  sjcl.decrypt (encKey, JSON.parse (jsonObj) );
}

//-- Add menu commands that will allow U and P to be changed.
GM_registerMenuCommand ("Change Username", changeUsername);
GM_registerMenuCommand ("Change Password", changePassword);

function changeUsername () {
    promptAndChangeStoredValue (usr,   "U-name", "lognUsr");
}

function changePassword () {
    promptAndChangeStoredValue (pword, "P-word", "lognPwd");
}

function promptAndChangeStoredValue (targVar, userPrompt, setValVarName) {
    targVar     = prompt (
        'Change ' + userPrompt + ' for ' + location.hostname + ':',
        targVar
    );
    GM_setValue (setValVarName, encryptAndStore (targVar) );
}

/*-- These next 3 lines are for debug / edification.  
Remove or comment out of the final script.
*/
console.log ("Script start.");
console.log ("usr: ",   usr);
console.log ("pword: ", pword);

// ADD YOUR CODE TO SET THE USERNAME AND PASSWORD ON THE LOGIN PAGE, HERE.

yes they are!! 对,他们是!! With an event listener on the event DOMNodeInserted of a script by the requested site your source code (and by that your password) is visible by ALL the scripts on the requested site. 通过事件DOMNodeInserted上的事件侦听器(由请求的站点执行脚本),请求的站点上的所有脚本都可以看到源代码(并通过密码输入)。

Have a look here for further information. 在这里查看更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM