Spring Security会话中的纯文本密码

时间:2016-10-18 00:29:28

标签: security grails spring-security

我正在使用一个使用优秀的Spring Security插件的Grails应用程序。通过Oracle Access Manager进行身份验证,以保护应用程序URL。所以我只使用PreAuth过滤器,从不必担心密码。到现在为止。

我们需要集成另一个应用程序(管理冷冻器样本并需要用户访问管理,以便用户不会看到其他人的样本)并使用LDAP。所述应用程序公开了一个API,该API接收用户名密码并根据用户的访问权返回数据(没有代表用户功能)。

问题是 我需要向用户询问他们的密码并向该服务发送纯文本密码。因此散列和编码需要是可逆的,我不能只比较哈希码。有关如何以最佳方式管理此问题的任何建议吗?

我正在考虑使用在服务器上创建的随机盐(并且每隔6小时循环一次),对密码进行编码并将其设置在短生命cookie中,并在调用外部服务时在服务器上对其进行解码。这样,潜在的攻击者将需要来自服务器内存的数据和来自用户系统的cookie,并且我不会在任何地方存储纯文本密码。只是一个天真的尝试。非常愿意接受建议。

1 个答案:

答案 0 :(得分:0)

所以我攻击了我的一个应用程序,就像这样:

在User类中:( Spring Security User.groovy)

static transients = ['springSecurityService', 'rawPassword']

//To bypass facebook users who log in via facebook
//we will back up original hashed password string
//log them in then save old password has by calling user.rawPassword=oldHash
//this will update underlying password with string hash value
void setRawPassword(String p) {
    password=p
}

然后在相关服务中

//Get old password hash
def oldPassword=user?.password
        String authPassword
        if (oldPassword) {
            def uid = user.password + new UID().toString() + prng.nextLong() + System.currentTimeMillis()
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hash = digest.digest(uid.getBytes("UTF-8"));
            def token1 = hash.encodeBase64()
            user.password = token1
            //Generate a random password
            authPassword = token1
            //Update user Password to be random Password
            UsernamePasswordAuthenticationToken uat1 = new UsernamePasswordAuthenticationToken(user.username, authPassword, null)
            uat1.setDetails(user)
            SecurityContext context = SecurityContextHolder.getContext()
            //Re-setAuthentication of springSecurity using new Password
            context.setAuthentication(uat1)
            if (oldPassword) {
                //Now we are authenticated let's set back the original Hash as the hash we collected in oldPassword 
                //just before doing the hack
                user.rawPassword = oldPassword
                user.save(flush: true)
            }
            springSecurityService.reauthenticate user.username
        }

对于用户进行身份验证而不改变其设置密码(最终)在过程中更改并再次更改后,这是一个丑陋的黑客攻击..

我不推荐它,但它可能比你概述的更容易选择

相关问题