Skip to content

Instantly share code, notes, and snippets.

@syshack
Created March 21, 2016 11:25
Show Gist options
  • Save syshack/098056a63c95d0a58e1b to your computer and use it in GitHub Desktop.
Save syshack/098056a63c95d0a58e1b to your computer and use it in GitHub Desktop.
chanegadpasswd.py
#!/usr/bin/env python
# coding=utf-8
import ldap
server = 'ldaps://ad.xxx.com'
l = ldap.initialize(server,trace_level=2)
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
dn = "[email protected]"
pw = "xxxxxxxxxx"
l.bind_s(dn,pw)
newdn = 'CN=syshack,CN=Users,DC=xxx,DC=com'
mod_attrs = [(ldap.MOD_REPLACE,'unicodePwd',''.join(('"', "xxxxxxxxxxxxxx", '"')).encode('utf-16').lstrip('\377\376'))]
l.modify_s(newdn, mod_attrs)
l.unbind_s()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment