Impacket GetUserSPNs.py
LDAP からユーザーアカウントの SPN を列挙します。指定時には TGS も取得し、オフライン解析用の形式で出力します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/GetUserSPNs.py |
| カテゴリ | Kerberos / チケット処理 |
| 規模 | 541 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/GetUserSPNs.py -h で確認できます。
| 引数 | 説明 |
|---|---|
target | domain[/username[:password]] |
-target-domain | Domain to query/request if different than the domain of the user. Allows for Kerberoasting across trusts. |
-no-preauth | account that does not require preauth, to obtain Service Ticket through the AS |
-stealth | Removes the (servicePrincipalName=*) filter from the LDAP query for added stealth. May cause huge memory consumption / errors on large domains. |
-machine-only | Queries for machine accounts only, by adjusting `objectCategory=person` to `objectCategory=computer`. Active Directory may limit results to 1,000 objects by default. LDAP paging is required to retrieve more. |
-usersfile | File with user per line to test |
-request | Requests TGS for users and output them in JtR/hashcat format (default False) |
-request-user | Requests TGS for the SPN associated to the user specified (just the username, no domain needed) |
-request-machine | Requests TGS for the SPN associated to the machine specified. Example: `workstation01$` |
-save | Saves TGS requested to disk. Format is |
-outputfile | Output filename to write ciphers in JtR/hashcat format. Auto selects -request |
-no-rc4 | Does not force RC4-HMAC for the TGT |
-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 ommited it use the domain part (FQDN) specified in the target parameter. Ignoredif -target-domain is specified. |
-dc-host | Hostname of the domain controller to use. If ommited, the domain part (FQDN) specified in the account parameter will be used |
-ldaps / -use-ldaps | Use LDAPS instead of LDAP |
関連技術: Kerberos の TGS-REP enc-part、LDAP の SPN 検索。
詳細な処理フロー
Section titled “詳細な処理フロー”LDAP で SPN、UAC、delegation 属性を検索・表示します。-request / -request-user / -request-machine では TGT を用意し、各 SPN の TGS-REQ を KDC へ送信、応答 enctype ごとに文字列表現または ccache を生成します。-stealth や -usersfile は検索/request の入口を変えます。
仕組みの詳細
Section titled “仕組みの詳細”Kerberoasting の対象になるのは SPN 文字列そのものではなく、user account の
long-term key で暗号化された service ticket 部分です。最初の LDAP 検索では
servicePrincipalName を持つ account と UAC/delegation 属性を集め、どの
account がどの service identity を所有しているかを表示します。
ticket を要求する場合、呼び出し元の TGT を password/hash/AES/ccache から
用意し、対象 SPN ごとに TGS-REQ を送ります。KDC が返す TGS-REP の ticket
encrypted part は service account key で保護されており、enctype と checksum/
cipher の配置に合わせて hashcat/John 形式へ変換されます。-save は応答を
ccache credential として保存する別の出力経路です。
-no-rc4 は client が提示する enctype の選好を変え、-stealth や
-usersfile は LDAP の探索方法を変えます。KDC が実際に選んだ enctype が
最終的な出力形式を決めるため、要求側の希望だけで RC4/AES と断定してはいけません。
cross-domain では認証 domain、検索 domain、KDC の三者を明示的に分けます。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
GetUserSPNs | 54 | __init__()、printTable()、getUnixTime()、getTGT()、outputTGS()、run()、request_users_file_TGSs()、request_multiple_TGSs() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.dcerpc.v5.samr | UF_ACCOUNTDISABLE, UF_TRUSTED_FOR_DELEGATION, UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION |
impacket.examples | logger |
impacket.examples.utils | ldap_login, parse_identity |
impacket.krb5 | constants |
impacket.krb5.asn1 | AS_REP, TGS_REP |
impacket.krb5.ccache | CCache |
impacket.krb5.kerberosv5 | getKerberosTGS, getKerberosTGT |
impacket.krb5.types | Principal |
impacket.ldap | ldap, ldapasn1 |
impacket.ntlm | compute_lmhash, compute_nthash |
外部パッケージ(直接使用)
Section titled “外部パッケージ(直接使用)”| import 名 | 配布パッケージ | 経路・宣言状態 |
|---|---|---|
pyasn1 | pyasn1 | 直接 import、宣言済み |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
- オプションによりローカルファイルを作成または更新します。既存ファイルの扱いと秘密情報を含む出力の権限を確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”LDAP、krb5.kerberosv5 / ccache / asn1 / crypto、pyasn1、NTLM hash helper に依存します。LDAP record と TGS 出力形式は GetUserSPNs 内で分離されています。
- 構文:
python -m py_compile examples/GetUserSPNs.py - CLI:
python examples/GetUserSPNs.py -h - 関連テスト:
tests/SMB_RPC/test_ldap.py - 関連テスト:
tests/SMB_RPC/test_ntlm.py - 関連テスト:
tests/dcerpc/test_samr.py - 関連テスト:
tests/misc/test_ccache.py - 関連テスト:
tests/misc/test_krb5_crypto.py - 関連テスト:
tests/misc/test_krb5_gssapi.py

