Impacket changepasswd.py
Kerberos kpasswd、SAMR、LDAP のいずれかを使い、本人によるパスワード変更または管理者によるリセットを行います。
| 項目 | 内容 |
|---|---|
| 実装 | examples/changepasswd.py |
| カテゴリ | Active Directory / LDAP / アカウント管理 |
| 規模 | 975 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/changepasswd.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
-ts | adds timestamp to every logging output |
-debug | turn DEBUG output ON |
-newpass | new password |
-newhashes | new NTLM hashes, format is NTHASH or LMHASH:NTHASH |
-hashes | NTLM hashes, format is NTHASH or LMHASH:NTHASH |
-no-pass | Don’t ask for password (useful for Kerberos, -k) |
-altuser | Alternative username |
-altpass | Alternative password |
-althash / -althashes | Alternative NT hash, format is NTHASH or LMHASH:NTHASH |
-protocol / -p | Protocol to use for password change/reset(選択肢: smb-samr, rpc-samr, kpasswd, ldap、既定値: smb-samr) |
-reset / -admin | Try to reset the password with privileges (may bypass some password policies) |
-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, for Kerberos. If omitted it will use the domain part (FQDN) specified in the target parameter |
詳細な処理フロー
Section titled “詳細な処理フロー”parse_args() が対象資格情報、新 password/hash、代替管理資格情報を検証し、-protocol から KPassword、SmbPassword、RpcPassword、LdapPassword を選択します。PasswordHandler の共通インターフェースが change/set を分離し、各 backend が認証、対象解決、protocol 固有 request を実行します。
仕組みの詳細
Section titled “仕組みの詳細”「password を変更する」と「password を reset する」は別操作です。change は
通常、対象本人の旧 credential を証明して新しい値へ移行します。reset は管理者
など別 principal の権限で対象 account の値を設定します。PasswordHandler
はこの二つを changePassword() と setPassword() に分け、各 protocol
backend が対応する wire operation を実装します。
Kerberos backend は kpasswd service へ AP-REQ を含む要求を送り、SAMR backend
は SMB named pipe または TCP RPC 上で user handle/password method を選びます。
LDAP backend は対象 DN を検索し、TLS で保護された接続上の unicodePwd modify
へ変換します。password と NT hash のどちらを受け取れるか、旧 credential が
必要かは backend ごとに違います。
-altuser 系は操作主体と変更対象を分離します。ここを一組の credential として
上書きすると、reset と self-change の意味が壊れます。また password policy
違反、旧 password 不一致、access denied、secure channel 不足は利用者が取る
べき対応が異なるため、protocol 固有 status を保持したまま上位へ返します。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
PasswordHandler | 137 | __init__()、changePassword()、setPassword() |
KPassword | 251 | 構造体/定数定義 |
SamrPassword | 321 | rpctransport()、authenticate()、connect()、hSamrOpenUser()、hSamrUnicodeChangePasswordUser2()、hSamrChangePasswordUser()、hSamrSetInformationUser() |
RpcPassword | 566 | rpctransport() |
SmbPassword | 591 | rpctransport() |
LdapPassword | 596 | connect()、encodeLdapPassword()、findTargetDN() |
parse_args() | 743 | モジュール関数 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.dcerpc.v5 | epm, samr, transport |
impacket.krb5 | kerberosv5, kpasswd |
impacket.ldap | ldap, ldapasn1 |
impacket.examples | logger |
impacket.examples.utils | EMPTY_LM_HASH, parse_target |
外部パッケージ(直接使用)
Section titled “外部パッケージ(直接使用)”| import 名 | 配布パッケージ | 経路・宣言状態 |
|---|---|---|
OpenSSL | pyOpenSSL | 直接 import、宣言済み |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 対象の状態を変更する操作があります。変更前に対象名や SID、パスを確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”krb5.kpasswd / kerberosv5、dcerpc.v5.samr、ldap / ldapasn1、OpenSSL に依存します。reset と change は必要権限も wire operation も異なるため、共通化で意味を混ぜないことが重要です。
- 構文:
python -m py_compile examples/changepasswd.py - CLI:
python examples/changepasswd.py -h - 関連テスト:
tests/SMB_RPC/test_ldap.py - 関連テスト:
tests/misc/test_dcerpc_v5_ndr.py - 関連テスト:
tests/misc/test_krb5_crypto.py - 関連テスト:
tests/misc/test_krb5_gssapi.py

