Impacket Get-GPPPassword.py
ローカルまたは SMB 共有上の Group Policy Preferences XML を探し、cpassword を抽出・復号します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/Get-GPPPassword.py |
| カテゴリ | SMB / MSRPC / NTLM |
| 規模 | 310 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/Get-GPPPassword.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | [[domain/]username[:password]@] |
-xmlfile | Group Policy Preferences XML files to parse |
-share | SMB Share(既定値: SYSVOL) |
-base-dir | Directory to search in (Default: /) |
-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. If omitted it will use the domain part (FQDN) specified in the target parameter |
-target-ip | IP Address of the target machine. If omitted it will use whatever was specified as target. This is useful when target is the NetBIOS name and you cannot resolve it |
-port | Destination port to connect to SMB Server(選択肢: 139, 445、既定値: 445) |
詳細な処理フロー
Section titled “詳細な処理フロー”-xmlfile 時は local file を読み、それ以外は SMB session を確立して share/base directory を再帰探索します。候補 XML の encoding を判定し DOM parse、各 preference element から field を抽出し、既知 AES key で base64 cpassword を復号して表示します。
仕組みの詳細
Section titled “仕組みの詳細”Group Policy Preferences の一部 XML は、属性 cpassword に共有の既知 AES key
で暗号化された password を保持していました。このコマンドは XML を見つける
工程と、その属性を解釈・復号する工程を分離しています。local -xmlfile と
remote SYSVOL/share 探索は同じ parser へ入力 byte 列を渡します。
SMB 経路では share と base directory から directory entry を再帰的に辿り、
GPP で使われる XML 名/extension を候補にします。取得 byte 列は必ず UTF-8
とは限らないため charset_normalizer で encoding を推定して DOM に渡します。
XML element type により username、newName、changed、path 等の属性位置が違い、
parse_xmlfile_content() が共通 record へ正規化します。
cpassword は base64 padding を補い、固定 AES key/IV と CBC で復号し、
PKCS#7 padding を除いて Unicode password に戻します。XML が読めること、
cpassword が存在すること、復号後 text が妥当であることは別段階です。
アクセス不能 directory、壊れた XML、一部 record の復号失敗で探索全体を
止めないようにします。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
GetGPPasswords | 40 | __init__()、list_shares()、find_cpasswords()、parse_xmlfile_content()、parse()、decrypt_password()、show() |
parse_args() | 209 | モジュール関数 |
parse_target() | 237 | モジュール関数 |
init_smb_session() | 260 | モジュール関数 |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.examples | logger, utils |
impacket.smbconnection | SMB2_DIALECT_002, SMB2_DIALECT_21, SMBConnection, SMB_DIALECT, SessionError |
外部パッケージ(直接使用)
Section titled “外部パッケージ(直接使用)”| import 名 | 配布パッケージ | 経路・宣言状態 |
|---|---|---|
Cryptodome | pycryptodomex | 直接 import、宣言済み |
charset_normalizer | charset_normalizer | 直接 import、宣言済み |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
- オプションによりローカルファイルを作成または更新します。既存ファイルの扱いと秘密情報を含む出力の権限を確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”SMBConnection、Cryptodome.Cipher.AES、charset_normalizer、XML DOM に依存します。GetGPPasswords の find_cpasswords()、parse_xmlfile_content()、decrypt_password() が I/O、parse、crypto を分離しています。
- 構文:
python -m py_compile examples/Get-GPPPassword.py - CLI:
python examples/Get-GPPPassword.py -h - このコマンド専用のテストは見つかりません。共有モジュールのテストと、必要に応じて隔離環境での動作確認を選びます。

