Impacket owneredit.py
LDAP オブジェクトのセキュリティ記述子から所有者を読み取り、指定した SID に変更します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/owneredit.py |
| カテゴリ | Active Directory / LDAP / アカウント管理 |
| 規模 | 281 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/owneredit.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 |
-new-owner | sAMAccountName |
-new-owner-sid | Security IDentifier |
-new-owner-dn | Distinguished Name |
-target | sAMAccountName |
-target-sid | Security IDentifier |
-target-dn | Distinguished Name |
-action | Action to operate on the owner attribute(選択肢: read, write、既定値: read) |
詳細な処理フロー
Section titled “詳細な処理フロー”対象と新 owner を名前/SID/DN から解決し、owner security information を要求して descriptor を取得します。read は現在 owner を表示し、write は owner field のみを書き換えて LDAP modify します。
仕組みの詳細
Section titled “仕組みの詳細”security descriptor の owner は DACL の ACE とは別 field です。このコマンドは
LDAP security descriptor control で owner 部分を要求し、対象 object と
新 owner principal をそれぞれ name、SID、DN のいずれかから解決します。
read は現在 owner SID を可能なら account 名へ変換して表示します。
write は取得した descriptor の owner field を新 SID に置き換え、owner
security information の control mask で LDAP modify します。DACL 全体を再構築
しないのは、対象外の ACE/SACL/group を壊さず、server に「owner だけ変更する」
意図を伝えるためです。新 owner に指定できることと、呼び出し元が owner を変更
する権限を持つことは別の検査です。
SID 解決失敗、object 検索結果 0 件/複数件、WRITE_OWNER 不足を区別する必要が
あります。また owner 変更は後続の ACL 編集権限へ影響し得るため、成功時は
対象 DN、旧 owner、新 owner を秘密情報を含まない形で追跡できるようにします。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
OwnerEdit | 111 | __init__()、read()、write()、search_target_principal_security_descriptor()、resolveSID() |
parse_args() | 213 | モジュール関数 |
main() | 250 | モジュール関数 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.examples | logger, utils |
impacket.ldap | ldaptypes |
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、security descriptor control を使用します。OwnerEdit は DACL を扱う dacledit と似ていますが、変更対象を owner に限定します。control mask と未変更部分の descriptor を保持してください。
- 構文:
python -m py_compile examples/owneredit.py - CLI:
python examples/owneredit.py -h - 関連テスト:
tests/SMB_RPC/test_ldap.py

