Impacket dacledit.py
LDAP オブジェクトの DACL を読み取り、ACE の追加・削除・復元を行います。対象は名前、SID、DN で指定できます。
| 項目 | 内容 |
|---|---|
| 実装 | examples/dacledit.py |
| カテゴリ | Active Directory / LDAP / アカウント管理 |
| 規模 | 779 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/dacledit.py -h で確認できます。
| 引数 | 説明 |
|---|---|
identity | domain.local/username[:password] |
-ldaps / -use-ldaps | Use LDAPS instead of LDAP |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-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 target 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-ip | IP Address of the domain controller or KDC (Key Distribution Center) for Kerberos. If omitted it will use the domain part (FQDN) specified in the identity parameter |
-dc-host | Hostname of the domain controller or KDC (Key Distribution Center) for Kerberos. If omitted, -dc-ip will be used |
-principal | sAMAccountName |
-principal-sid | Security IDentifier |
-principal-dn | Distinguished Name |
-target | sAMAccountName |
-target-sid | Security IDentifier |
-target-dn | Distinguished Name |
-action | Action to operate on the DACL(選択肢: read, write, remove, backup, restore、既定値: read) |
-file | Filename/path (optional for -action backup, required for -restore)) |
-ace-type | The ACE Type (access allowed or denied) that must be added or removed (default: allowed)(選択肢: allowed, denied) |
-rights | Rights to write/remove in the target DACL (default: FullControl)(選択肢: FullControl, ResetPassword, WriteMembers, DCSync, Custom) |
-rights-guid | Manual GUID representing the right to write/remove |
-mask | Force access mask, possible values: readwrite, write, self, allext, 0xXXXXX. Useful with -rights Custom or —rights-guid where the mask is different of read+write. |
-inheritance | Enable the inheritance in the ACE flag with CONTAINER_INHERIT_ACE and OBJECT_INHERIT_ACE. Useful when target is a Container or an OU, ACE will be inherited by objects within the container/OU (except objects with adminCount=1) |
関連技術: LDAP と AD セキュリティ記述子 の ACE 型、GUID、SD control。impacket.acl は使いません。
詳細な処理フロー
Section titled “詳細な処理フロー”LDAP bind 後に対象 DN と principal SID を解決し、security descriptor control 付きで descriptor を取得します。read は ACE を解析表示し、write / remove は rights と inheritance から ACE を構築・変更して LDAP modify します。変更前の descriptor は backup JSON に保存でき、restore で戻せます。
仕組みの詳細
Section titled “仕組みの詳細”LDAP object の DACL は ACE の並びであり、単純な「権限名の集合」ではありません。
このコマンドは security descriptor control を付けて binary descriptor を取得し、
各 ACE を type、trustee SID、access mask、object GUID、inheritance flag に
分解します。read はこの構造を人が読める権限へ写像する処理です。
write では FullControl、DCSync などの高水準指定を一つ以上の ACE と
GUID/mask へ展開し、既存 DACL へ追加します。remove は同じ条件に合う ACE
だけを除きます。object-specific ACE は GUID と mask の組み合わせが意味を持つ
ため、SID が同じという理由だけで削除してはいけません。継承を有効にした場合は
container 自身と子 object で適用範囲が変わります。
backup / restore は表示結果ではなく元の binary descriptor を JSON に
保持します。これは未知 ACE や順序を失わず戻すためです。変更処理では canonical
ACE ordering、descriptor control flags、owner/group/SACL の非対象部分を保持し、
LDAP modify が失敗したときに「local object だけ変更済み」という状態を外へ
漏らさない設計が必要です。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
RIGHTS_GUID | 130 | 構造体/定数定義 |
ACE_FLAGS | 140 | 構造体/定数定義 |
OBJECT_ACE_FLAGS | 154 | 構造体/定数定義 |
ACCESS_MASK | 163 | 構造体/定数定義 |
SIMPLE_PERMISSIONS | 198 | 構造体/定数定義 |
ALLOWED_OBJECT_ACE_MASK_FLAGS | 211 | 構造体/定数定義 |
DACLedit | 220 | __init__()、read()、write()、remove()、backup()、restore()、search_target_principal_security_descriptor()、get_user_info()、resolveSID()、parseDACL()、parsePerms()、parseACE() ほか |
parse_args() | 699 | モジュール関数 |
main() | 741 | モジュール関数 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.examples | logger, utils |
impacket.ldap | ldaptypes |
impacket.msada_guids | EXTENDED_RIGHTS, SCHEMA_OBJECTS |
impacket.uuid | bin_to_string, string_to_bin |
impacket.examples.utils | init_ldap_session, parse_identity |
外部パッケージ(直接使用)
Section titled “外部パッケージ(直接使用)”| import 名 | 配布パッケージ | 経路・宣言状態 |
|---|---|---|
ldap3 | ldap3 | 直接 import、宣言済み |
ldapdomaindump | ldapdomaindump | 直接 import、宣言済み |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”ldap3、ldapdomaindump、ldaptypes、msada_guids に依存します。DACLedit が解決、解析、変更を担います。ACE 順序、object-specific GUID、継承 flag、backup の binary 表現を壊さないことが重要です。
- 構文:
python -m py_compile examples/dacledit.py - CLI:
python examples/dacledit.py -h - 関連テスト:
tests/SMB_RPC/test_ldap.py

