有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何从Post请求url和浏览器转储中隐藏密码

这可能是一个老问题,但我仍然没有找到这个问题的正确答案,所以请耐心等待。 我有一个https登录页面,它使用form post方法并将凭据发送到服务器。。。诸如此类

登录时,如果使用IE和F12进行网络监控,请单击开始捕获。你可以看到一些类似于登录的URL,ServeLoginauth(来自gmail.com),你可以看到带有用户名和密码的请求正文。 好吧,有人会说,只有用户没有注销,你才能看到

现在注销,不要关闭浏览器并从Task Manager中获取浏览器转储(任何浏览器,任何版本)(我不知道如何在Mac中执行相同操作)。 使用WinHex编辑器打开转储文件并进行搜索/查找:“password=”或实际密码(因为您正在测试自己的登录名,所以您已经知道自己的密码)。 您可以在明文中看到密码

现在我的问题是,如何屏蔽密码: 1.在Post请求URL中 2.或者当浏览器将我的凭据保存到转储文件时,我需要对其进行屏蔽/加密,或者根本不应该保存密码

我的jsp代码:

<s:form id="login" name="loginForm1" action="login" namespace="/" method="post" enctype="multipart/form-data" >  
      <fieldset><!-- login fieldset -->
        <div><!-- div inside login fieldset -->
                <div....
                  <label for="password" class="loginLabel">Password</label>
                  <input type="password" name="password" id="password" class="longField nofull absPosition" size="16" autocomplete="off" alt="Password" placeholder="Password" title="Password|<

我目前的解决方案如下,但我需要没有太多努力的任何替代方案

The password can be read from the memory if it is being sent as cleartext. Using the salted hash technique for password transmission will resolve this issue. Hashing is a cryptographic technique in which the actual value can never be recovered. In the salted hash technique, the passwords are stored as hashes in the database. The server generates a random string, salt, and sends it along with the Login page to the client. A JavaScript code on the page computes a hash of the entered password, concatenates the salt and computes a hash of the entire string. This value is sent to the server in the POST request.

The server then retrieves the user's hashed password from the database, concatenates the same salt and computes a hash. If the user had entered the correct password, these two hashes should match.

Now, the POST request will contain the salted hash value of the password and the cleartext password will not be present in the memory

SHA 256 is a strong hashing algorithm available today – readymade implementations in JavaScript are available and quoted in the "Good Reads" section.

Note: For pages containing sensitive information or pages wherein data can be modified in the database, use JavaScript to flush the memory of the browse

图片如下。 enter image description here enter image description here enter image description here

另外,我可以通过花旗银行在其网站上为客户做的事情来解决问题。 我登录了网站,在转储文件中我看到我的用户名被屏蔽了(就像它出现在网站上一样),我需要一些对密码字段也有同样作用的东西。谁能给我解释一下怎么做吗。 enter image description here


共 (2) 个答案

  1. # 1 楼答案

    你必须了解密码在数据库中的存储方式。有多种方法可以做到这一点,但你无法创建任何不可能被破解/读取的东西

    但是,可以通过在将密码发送到服务器之前对密码进行X次哈希运算来限制MITM攻击。 当服务器接收到散列时,需要执行X轮新的散列。你还应该弄清楚如何管理你的盐

    对于大多数应用来说,这应该足够了。现在大多数应用程序也是这样做的

    gpEasy:http://gpeasy.com/通过在客户端使用Sha-256 50次来实现这一点。然后在服务器上再进行950轮。总共1000发。这还包括一个由“当前哈希”计算的盐

    def hash(self, pw, loops = 50):
        pw = pw.strip()
    
        for i in range(loops):
            salt_len = re.sub(r'[a-f]', '', pw)
    
            try:
                salt_start = int(salt_len[0:0+1])
            except ValueError:
                salt_start = 0
    
            try:
                salt_len = int(salt_len[2:2+1])
            except ValueError:
                salt_len = 0    
    
            salt = pw[salt_start:salt_start+salt_len]
            pw = hashlib.sha512(pw.encode('utf-8') + salt.encode('utf-8')).hexdigest()
        return pw
    

    这是上述算法的一个版本,用于从散列中的第一个数字中使用salt计算散列

  2. # 2 楼答案

    你的建议存在严重的安全漏洞。如果在浏览器上计算哈希值,然后发送到服务器(没有密码),则服务器无法相信浏览器实际计算了哈希值。黑客可能只是读取了散列值文件,然后构造了一个程序来发送散列值。安全性来自服务器(一个受信任的环境),它拥有无法从散列中猜到的密码,然后向自己证明密码产生了散列

    如果您同时发送哈希和密码,那么您还没有解决密码以明文形式可用的问题

    如果你多次散列密码,似乎有一种方法。您可以在浏览器上对密码进行一次(或多次)散列,并将其用于服务器上的后续散列调用。多次散列似乎很正常(尽管尚不清楚这到底在多大程度上提高了安全性)。关键是浏览器将保留一个中间值,该值不会告诉您用户键入的密码。但是,它仍然会告诉您需要发送到服务器以验证用户身份的值。该值实际上是密码的代理,在调用服务器时可用作密码。但是这不是用户输入的密码

    最后一种方法似乎是可行的:使用非对称加密。服务器提供salt值和公钥。密码使用公钥加密,公钥只能由服务器上持有的私钥解密。因为salt值在每个会话中都会发生变化,所以存储在内存中的加密值本身在另一个会话中不可用。服务器解密该值,提取salt,给它一个密码,然后进行密码验证