【问题标题】:LDAP Authenticated Bind Issue - PHP, Apache, WindowsLDAP 身份验证绑定问题 - PHP、Apache、Windows
【发布时间】:2013-04-09 09:31:10
【问题描述】:

我在对服务器执行经过身份验证的绑定时遇到问题。这些问题似乎不在代码中,但可能是服务器问题。

你知道的;

  • 在 Apache/PHP 中启用了 LDAP
  • 我以 user@domain.com 的身份连接
  • 域控制器正在运行 LDAP,并且在防火墙中有一个条目 (Windows Server 2008 R2)
  • 我可以执行匿名绑定

我可以使用这个脚本匿名绑定;

$ldapconn = ldap_connect("machinename.domain.com")
    or die("Could not connect to LDAP server.");

if ($ldapconn) {

    // binding anonymously
    $ldapbind = ldap_bind($ldapconn);

    if ($ldapbind) {
        echo "LDAP bind anonymous successful...";
    } else {
        echo "LDAP bind anonymous failed...";
    }

}

但是,当我尝试使用此脚本进行经过身份验证的绑定时,它失败了。

// Authenticated Bind
$ldaprdn  = 'username@domain.com';     // ldap rdn or dn
$ldappass = 'password';  // associated password

// connect to ldap server
$ldapconn = ldap_connect("machinename.domain.com")
    or die("Could not connect to LDAP server.");

if ($ldapconn) {

    // binding to ldap server
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

    // verify binding
    if ($ldapbind) {
        echo "LDAP bind successful...";
    } else {
        echo "LDAP bind failed...";
    }

}

我哪里错了?

【问题讨论】:

  • 使用已知的好工具,例如ldapsearch在编写任何代码之前验证 bindDN 和 bindPassword。

标签: php windows apache ldap


【解决方案1】:

可能您的 LDAP 需要 DN 作为登录名。要检索 DN,请先搜索用户 uid

$search = ldap_search($ldapconn, $baseDn, $filter, $attributes);

if ($search) {
    $entries = ldap_get_entries($ldapconn, 'uid=' . $ldaprdn);// Here $ldaprdn is the email
    if (is_array($entries)) {
        $ldaprdn = $entries[0]['dn']; // Get the DN of the user
    }
}

$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

// ....

注意:您应该转义 $ldaprdn 以避免 LDAP 注入攻击。

【讨论】:

    【解决方案2】:

    好的,经过大量调查,我使用 ldap_errno()ldap_error() 打开了错误信息,发现它带回了错误“需要强(er)身份验证”,发现了两种可能的解决方案;

    调整组策略设置

    • 协商签名(网络安全:LDAP 客户端签名要求)
    • 无签名要求(域控制器:LDAP 服务器签名要求)

    • 结果:成功绑定,当我输入错误的用户名或密码并按预期抛出“无效凭据”时。

    启用 LDAP over SSL (LDAPS)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      • 2013-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多