Impacket badsuccessor.py
委任管理サービスアカウント(dMSA)を作成・変更・削除し、関連する AD 属性を調べます。
| 項目 | 内容 |
|---|---|
| 実装 | examples/badsuccessor.py |
| カテゴリ | Active Directory / LDAP / アカウント管理 |
| 規模 | 747 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/badsuccessor.py -h で確認できます。
| 引数 | 説明 |
|---|---|
account | Account used to authenticate to DC. |
-dmsa-name | Name of dMSA to add. If omitted, a random dMSA-[A-Z0-9]{8} will be used. |
-action | Action to perform: add (requires -target-ou), delete (requires -dmsa-name, -target-ou), modify (requires -dmsa-name, -target-ou and -target-account), or search a dMSA.(選択肢: add, delete, modify, search、既定値: search) |
-target-ou | Specific OU to check for dMSA creation capabilities (e.g., “OU=weakOU,DC=domain,DC=local”) |
-principals-allowed | Username allowed to retrieve the managed password. If omitted, current username will be used. |
-target-account | Target user or computer account DN to set for msDS-ManagedAccountPrecededByLink (can target Domain Controllers, Domain Admins, Protected Users, etc.)(既定値: Administrator) |
-dns-hostname | DNS hostname for the dMSA. If omitted, will be generated as dmsaname.domain. |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-method | Method of adding the computer. LDAPS has some certificate requirements and isn’t always available.(選択肢: LDAP, LDAPS、既定値: LDAPS) |
-port | Destination port to connect to. LDAP defaults to 389, LDAPS to 636.(選択肢: 389, 636) |
-baseDN | Set baseDN for LDAP. If ommited, the domain part (FQDN) specified in the account parameter will be used. |
-hashes | NTLM hashes, format is LMHASH:NTHASH |
-no-pass | don’t ask for password (useful for -k) |
-k | Use Kerberos authentication. Grabs credentials from ccache file (KRB5CCNAME) based on account parameters. If valid credentials cannot be found, it will use the ones specified in the command line |
-aesKey | AES key to use for Kerberos Authentication (128 or 256 bits) |
-dc-host | Hostname of the domain controller to use. If ommited, the domain part (FQDN) specified in the account parameter will be used |
-dc-ip | IP of the domain controller to use. Useful if you can’t translate the FQDN. |
詳細な処理フロー
Section titled “詳細な処理フロー”LDAP session を作成後、action に応じて OU の探索、アカウント存在確認、security descriptor 構築、dMSA object の追加または属性変更へ進みます。SID を名前へ解決し、許可 principal や対象 account を検証してから書き込みます。
仕組みの詳細
Section titled “仕組みの詳細”このコマンドは dMSA object を通常の user/computer と同じように追加するのでは
なく、dMSA 固有の schema 属性と、移行対象 account との関連を構築します。
search_ous() と check_account_exists() が配置先と参照先を先に検証し、
build_security_descriptor() が dMSA を利用できる principal の SID を
access control structure へ変換します。
add_dmsa() は objectClass、account 名、DNS host 名、managed account に必要な
属性をまとめて作成します。modify_dmsa() は既存 object に対して対象 account
や許可 principal を更新します。追加と更新を分けるのは、LDAP add と modify で
失敗単位が異なり、既存 object の予期しない属性を消さないためです。
SID 除外、OU 選択、名前自動生成は単なる表示補助ではなく、誤った privileged
principal や保護 container を対象にしないための guard です。Windows Server
の schema/機能レベルに依存するため、noSuchAttribute や
objectClassViolation を一般的な認証失敗として扱わず、対象 DC が dMSA を
理解しているかまで切り分けます。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
BADSUCCESSOR | 34 | __init__()、run()、delete_dmsa()、check_account_exists()、search_ous()、is_excluded_sid()、resolve_sid_to_name()、generate_dmsa_name()、convert_sid_to_string()、build_security_descriptor()、add_dmsa()、modify_dmsa() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.examples | logger |
impacket.examples.utils | init_ldap_session, parse_identity, parse_target |
impacket.ldap | ldaptypes |
外部パッケージ(直接使用)
Section titled “外部パッケージ(直接使用)”| import 名 | 配布パッケージ | 経路・宣言状態 |
|---|---|---|
ldap3 | ldap3 | 直接 import、宣言済み |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”ldap3、impacket.ldap.ldaptypes、init_ldap_session を使用し、処理は BADSUCCESSOR が所有します。schema/機能レベル依存が強いため、属性名、objectClass、SID 除外規則を変更する場合は対応する Windows Server 世代で確認してください。
- 構文:
python -m py_compile examples/badsuccessor.py - CLI:
python examples/badsuccessor.py -h - 関連テスト:
tests/SMB_RPC/test_ldap.py

