首页 文章

使用Python和ldap3重置Active Directory密码

提问于
浏览
0

我似乎遇到了在AD中重置密码的经典错误,即使我在网上找到的所有内容都指向我应该是金色的事实 .

代码优先 .

from ldap3 import *

username = '<account with the proper permissions>'
password = '<totally@realpassword>'

server = Server('<fqdn of server>', use_ssl=True, get_info=ALL)
conn = Connection(server, user='<domain>\\' + username, password=password, authentication=NTLM, auto_bind=True)

print(conn)

user_dn = 'CN=Test,OU=US,OU=NA,OU=Employees,OU=Users,DC=domain,DC=com'
new_pass = 'U^mod2olla'

r = conn.extend.microsoft.modify_password(user_dn, new_pass)

print(conn.result)

这似乎是通过SSL实例化与LDAP服务器的连接的正确方法,如此连接打印输出所证实:

ldaps://ldap.domain.com:636 - ssl - user: domain.com\samaccountname - not lazy - bound - open - <local: IP:62368 - remote: IP:636> - tls not started - listening - SyncStrategy - internal decoder

但我仍然收到此错误:

{'result': 53, 'description': 'unwillingToPerform', 'dn': '', 'message': '0000001F: SvcErr: DSID-031A1248, problem 5003 (WILL_NOT_PERFORM), data 0\n\x00', 'referrals': None, 'type': 'modifyResponse'}

从我的谷歌搜索,这通常意味着密码没有正确编码,或者根据LDAP服务器连接不够安全 .

我此时迷路了 . 思考?

@cannatag如果你在外面......我需要你:)

我的研究链接:

https://github.com/cannatag/ldap3/issues/130

Python 3.5, ldap3 and modify_password()

Unable to change user's password via ldap3 Python3

Changing Active Directory user password in Python 3.x

2 回答

  • 0

    您需要绑定到AD作为域管理员 .

    之后搜索userdn并修改

    我正在使用c.modify(user_dn,{“userAccountControl”:( MODIFY_REPLACE,512)})来确保用户可以登录(如果锁定或密码已泄露,我们无法更改密码)

    admin = CONF['admin']['user']
    passwdadm = CONF['admin']['pass']
    with connect_ldap(authentication=SIMPLE, user=admin, password=passwdadm) as c:
        c.bind()
        user_dn = find_user_dn(c, username)
        c.modify(user_dn,{"userAccountControl":(MODIFY_REPLACE,512)})
        print(c.result)
        c.unbind()
    
    with connect_ldap(authentication=SIMPLE, user=admin, password=passwdadm) as c:
        c.bind()
        user_dn = find_user_dn(c, username)
        c.extend.microsoft.modify_password(user_dn, new_pass, old_pass)
        print(c.result)
        c.unbind()
    
  • 0

    不幸的是,我认为没有与代码相关的问题 .

    我和我们的一些域管理员聊天,他们向我确认我用LDAPS连接的服务器实际上是F5,LDAPS在那里终止 . 这意味着在没有特定证书和IP的情况下,无法与任何单个域控制器 Build LDAPS连接 . 这样做对我的系统来说不可扩展或不现实,所以我不打算使用这种方法在AD中重置密码 .

    如果有人发现自己处于类似的情况,我建议从Linux查看PowerShell远程处理 . 现在可以在Linux上运行本机PowerShell并在Windows Server上打开会话以在本地执行命令 . 目前您需要PS 6.0测试版 .

相关问题