如何让 ldap 评估明文密码与 DES 存储密码

How to make ldap evaluate clear text password vs DES stored password

我在 CentoS 6.9

上使用 openldap slapd 2.4.40 和 postgresql9.2.23 作为后备sql

LDAP uiduserPassword 的用户和密码通过 DES 编码存储在 postgresql 中。

原始明文为JacicFk5

DES encoded/encrypted 文本是 IfjFxsltK/MPE 存储在数据库中。

我可以通过存储的密码看到 ldapseach 结果的用户信息。

ldapsearch -x  -b "dc=example,dc=com" -D uid="HDZZZ0R0N,ou=people,dc=example,dc=com" -w IfjFxsltK/MPE '(&(uid= HDZZZ0R0N)(objectClass=*))'          
# extended LDIF
#
# LDAPv3
# base <dc=example,dc=com> with scope subtree
# filter: (&(uid= HDZZZ0R0N)(objectClass=*))
# requesting: ALL
#

# user01, people, example.com
dn: uid= HDZZZ0R0N,ou=people,dc=example,dc=com
objectClass: inetOrgPerson
cn:: W+aOkl3lia/nlKPnianjg6Hjg7Pjg4bjg4rjg7PjgrnvvIgzNu+8iVNURw==
sn:: W+aOkl3lia/nlKPnianjg6Hjg7Pjg4bjg4rjg7PjgrnvvIgzNu+8iVNURw==
uid: HDZZZ0R0N
userPassword:: SWZqRnhzbHRLL01QRQ==

但是我无法通过原始明文密码进行ldapsearch

ldapsearch -x -b "dc=example,dc=com" -D uid="HDZZZ0R0N,ou=people,dc=example,dc=com" -w JacicFk5 '(&(uid= HDZZZ0R0N)(objectClass=*))'
ldap_bind: Invalid credentials (49)

有谁告诉我如何让 ldapsearch 通过明文解析给定的密码并通过 DES 编码解析存储的密码?

我想知道如何从 ldapseach 命令行将纯文本 JacicFk5 哈希 IfjFxsltK/MPE 并使其匹配数据库中的 IfjFxsltK/MPE 作为 userPassowrd.

是否有适合 ldap.confslapd.conf 的指令?

我检查了以下内容。

echo "SWZqRnhzbHRLL01QRQ==" |perl -MMIME::Base64 -ne 'print decode_base64($_) . "\n"'

它returnsIfjFxsltK/MPE

perl -e 'print("userPassword: {crypt}".crypt("JacicFk5","If")."\n");'

它returnsuserPassword: {crypt}IfjFxsltK/MPE

还有一个信息。 我的 ldapseach 可以通过 ownclod 为存储在 AD 服务器中的用户解析密码文本。

您want/need拥有的是 LDAP简单身份验证。请先注意明文存储密码不安全

首先你需要测试你有什么授权机制supported/allowed。

一个例子:

tukanos@localhost:~# ldapsearch -H ldap:// -x -LLL -s base -b "" supportedSASLMechanisms
dn:
supportedSASLMechanisms: DIGEST-MD5
supportedSASLMechanisms: CRAM-MD5
supportedSASLMechanisms: NTLM

现在您想通过 ldapmodify 更改配置。您准备一个带有配置的 LDIF 文件(LDIF 代表 LDAP 数据可互换格式)。

准备你的配置文件你可以命名它olcSaslSecProps.ldif:

dn: cn=config
replace: olcSaslSecProps
olcSaslSecProps: noanonymous,minssf=0,passcred

属性的含义:

noanonymous ... no anonymous connection allowed
minssf=0 ... that defines your effective encryption strength (0 ... no encryption)
passcred ... that would allow password to work as for credentials

引用OpenLDAP security considerations

Security Strength Factors

The server uses Security Strength Factors (SSF) to indicate the relative strength of protection. A SSF of zero (0) indicates no protections are in place. A SSF of one (1) indicates integrity protection are in place. A SSF greater than one (>1) roughly correlates to the effective encryption key length. For example, DES is 56, 3DES is 112, and AES 128, 192, or 256.

A number of administrative controls rely on SSFs associated with TLS and SASL protection in place on an LDAP session.

security controls disallow operations when appropriate protections are not in place. For example:

    security ssf=1 update_ssf=112

requires integrity protection for all operations and encryption protection, 3DES equivalent, for update operations (e.g. add, delete, modify, etc.). See slapd.conf(5) for details.

现在应用 LDIF 文件:

ldapmodify -Y EXTERNAL -H ldapi:// -f ./olcSaslSecProps.ldif

现在重新启动 slapd 守护程序:

systemctl restart slapd

如果您现在检查您的配置,您应该得到 LOGINPLAIN:

ldapsearch -H ldap:// -x -LLL -s base -b "" supportedSASLMechanisms
dn:
supportedSASLMechanisms: PLAIN
supportedSASLMechanisms: LOGIN

现在您的搜索应该可以使用简单的测试密码:

ldapsearch -x  -b "dc=example,dc=com" -D uid="HDZZZ0R0N,ou=people,dc=example,dc=com" -w JacicFk5 '(&(uid= HDZZZ0R0N)(objectClass=*))'