コンテンツにスキップ

カテゴリ目次へ戻る / コマンド全体目次へ戻る

LDAP オブジェクトの DACL を読み取り、ACE の追加・削除・復元を行います。対象は名前、SID、DN で指定できます。

項目内容
実装examples/dacledit.py
カテゴリActive Directory / LDAP / アカウント管理
規模779 行
配布setup.py の scripts=examples/*.py によりスクリプトとしてインストール

オプションの最新の定義は python examples/dacledit.py -h で確認できます。

引数説明
identitydomain.local/username[:password]
-ldaps / -use-ldapsUse LDAPS instead of LDAP
-tsAdds timestamp to every logging output
-debugTurn DEBUG output ON
-hashesNTLM hashes, format is LMHASH:NTHASH
-no-passdon’t ask for password (useful for -k)
-kUse 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
-aesKeyAES key to use for Kerberos Authentication (128 or 256 bits)
-dc-ipIP 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-hostHostname of the domain controller or KDC (Key Distribution Center) for Kerberos. If omitted, -dc-ip will be used
-principalsAMAccountName
-principal-sidSecurity IDentifier
-principal-dnDistinguished Name
-targetsAMAccountName
-target-sidSecurity IDentifier
-target-dnDistinguished Name
-actionAction to operate on the DACL(選択肢: read, write, remove, backup, restore、既定値: read)
-fileFilename/path (optional for -action backup, required for -restore))
-ace-typeThe ACE Type (access allowed or denied) that must be added or removed (default: allowed)(選択肢: allowed, denied)
-rightsRights to write/remove in the target DACL (default: FullControl)(選択肢: FullControl, ResetPassword, WriteMembers, DCSync, Custom)
-rights-guidManual GUID representing the right to write/remove
-maskForce access mask, possible values: readwrite, write, self, allext, 0xXXXXX. Useful with -rights Custom or —rights-guid where the mask is different of read+write.
-inheritanceEnable 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 は使いません。

LDAP bind 後に対象 DN と principal SID を解決し、security descriptor control 付きで descriptor を取得します。read は ACE を解析表示し、write / remove は rights と inheritance から ACE を構築・変更して LDAP modify します。変更前の descriptor は backup JSON に保存でき、restore で戻せます。

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 だけ変更済み」という状態を外へ 漏らさない設計が必要です。

シンボル位置責務を追う入口
RIGHTS_GUID130構造体/定数定義
ACE_FLAGS140構造体/定数定義
OBJECT_ACE_FLAGS154構造体/定数定義
ACCESS_MASK163構造体/定数定義
SIMPLE_PERMISSIONS198構造体/定数定義
ALLOWED_OBJECT_ACE_MASK_FLAGS211構造体/定数定義
DACLedit220__init__()、read()、write()、remove()、backup()、restore()、search_target_principal_security_descriptor()、get_user_info()、resolveSID()、parseDACL()、parsePerms()、parseACE() ほか
parse_args()699モジュール関数
main()741モジュール関数
モジュール使用する主な名前
impacketversion
impacket.exampleslogger, utils
impacket.ldapldaptypes
impacket.msada_guidsEXTENDED_RIGHTS, SCHEMA_OBJECTS
impacket.uuidbin_to_string, string_to_bin
impacket.examples.utilsinit_ldap_session, parse_identity
import 名配布パッケージ経路・宣言状態
ldap3ldap3直接 import、宣言済み
ldapdomaindumpldapdomaindump直接 import、宣言済み
  • 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
  • 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。

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