LDAP绑定似乎返回true,空密码

时间:2015-01-10 06:02:39

标签: php ldap

我有这个代码根据LDAP目录验证我的用户。如果密码不正确,则返回false,但如果密码为空,则会对用户进行身份验证。有什么想法可能会发生吗?

if (@ldap_bind($ds, $user_dn, $password) || sha1($password) == '484h84h4hf4Ffwj49393393j93j') 
{
    $valid = true;
}
else $valid = false;

1 个答案:

答案 0 :(得分:4)

如果提供空密码,则它向目录服务器指示您正在执行匿名简单绑定。 RFC 2251第4.2.2节中描述了此行为:

 If no authentication is to be performed, then the simple
 authentication option MUST be chosen, and the password be of zero
 length.  (This is often done by LDAPv2 clients.)  Typically the DN is
 also of zero length.

这可能是LDAP客户端中非常常见的安全漏洞,因为如果他们不验证用户提供了非空密码但是尝试使用非空DN和空密码进行绑定,那么他们可以看到它成功,当服务器没有以提供的DN指定的用户绑定,而是匿名绑定时。由于这是LDAP客户端中常见的安全问题,因此某些服务器拒绝具有非空DN但空密码的绑定请求,并且最新的LDAPv3规范鼓励了这种行为,如RFC 4513第5.1.2节所述:

 An LDAP client may use the unauthenticated authentication mechanism
 of the simple Bind method to establish an anonymous authorization
 state by sending a Bind request with a name value (a distinguished
 name in LDAP string form [RFC4514] of non-zero length) and specifying
 the simple authentication choice containing a password value of zero
 length.

 The distinguished name value provided by the client is intended to be
 used for trace (e.g., logging) purposes only.  The value is not to be
 authenticated or otherwise validated (including verification that the
 DN refers to an existing directory object).  The value is not to be
 used (directly or indirectly) for authorization purposes.

 Unauthenticated Bind operations can have significant security issues
 (see Section 6.3.1).  In particular, users intending to perform
 Name/Password Authentication may inadvertently provide an empty
 password and thus cause poorly implemented clients to request
 Unauthenticated access.  Clients SHOULD be implemented to require
 user selection of the Unauthenticated Authentication Mechanism by
 means other than user input of an empty password.  Clients SHOULD
 disallow an empty password input to a Name/Password Authentication
 user interface.  Additionally, Servers SHOULD by default fail
 Unauthenticated Bind requests with a resultCode of
 unwillingToPerform.

听起来你的服务器并没有这样做。如果它可以选择这样做,那么我强烈建议打开它。但无论如何,使用简单绑定操作验证用户凭据的设计良好的LDAP客户端应该在尝试使用它绑定到服务器之前,绝对验证用户是否提供了非空字符串。