Impacket getST.py
TGS の取得、S4U2self/S4U2proxy、U2U、チケット更新を扱い、得たサービスチケットを ccache に保存します。
| 項目 | 内容 |
|---|---|
| 実装 | examples/getST.py |
| カテゴリ | Kerberos / チケット処理 |
| 規模 | 918 行 |
| 配布 | setup.py の scripts=examples/*.py によりスクリプトとしてインストール |
CLI と入力
Section titled “CLI と入力”オプションの最新の定義は python examples/getST.py -h で確認できます。
| 引数 | 説明 |
|---|---|
identity | [domain/]username[:password] |
-spn | SPN (service/server) of the target service the service ticket will be generated for |
-altservice | New sname/SPN to set in the ticket |
-dmsa | Use DMSA (Delegated Managed Service Accounts) |
-impersonate | target username that will be impersonated (thru S4U2Self) for quering the ST. Keep in mind this will only work if the identity provided in this scripts is allowed for delegation to the SPN specified |
-additional-ticket | include a forwardable service ticket in a S4U2Proxy request for RBCD + KCD Kerberos only |
-ts | Adds timestamp to every logging output |
-debug | Turn DEBUG output ON |
-u2u | Request User-to-User ticket |
-self | Only do S4U2self, no S4U2proxy |
-force-forwardable | Force the service ticket obtained through S4U2Self to be forwardable. For best results, the -hashes and -aesKey values for the specified -identity should be provided. This allows impresonation of protected users and bypass of “Kerberos-only” constrained delegation restrictions. See CVE-2020-17049 |
-renew | Sets the RENEW ticket option to renew the TGT used for authentication. Set -spn to ‘krbtgt/DOMAINFQDN’ |
-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 use the domain part (FQDN) specified in the target parameter |
関連技術: Kerberos の TGS、S4U2self/S4U2proxy、U2U、PAC。S4U は getKerberosTGS ではなくこのファイル側です。
詳細な処理フロー
Section titled “詳細な処理フロー”password/hash/AES/既存 ccache から TGT を確保し、オプションに応じて通常 TGS、impersonation、additional-ticket、dMSA、renew の経路へ分岐します。KDC 応答を検証し、-altservice 等の必要な調整を施して saveTicket() で ccache を書き出します。
仕組みの詳細
Section titled “仕組みの詳細”このコマンドは service ticket 取得の複数経路を一つの CLI にまとめています。
通常経路では TGT とその session key を準備し、目的 SPN の TGS-REQ を送ります。
ccache の TGT は要求したユーザー名とドメインが一致する場合だけ使い、
一致しなければ警告して新しい TGT を要求します。
-impersonate では S4U2self で別 user の identity を表す evidence ticket を
得て、必要なら S4U2proxy で最終 service ticket に交換します。
S4U2proxy では evidence ticket、delegation 対象 SPN、PAC option、ticket
flags の組み合わせが KDC の authorization 判定に使われます。
-additional-ticket は外部から渡された evidence ticket を使う経路、
-u2u は別 ticket の session key を利用する経路、-renew は renewable
ticket の期間更新経路です。これらは request ASN.1 の field と key usage が
異なるため、単一の「TGS request」関数へ無理に畳み込んでいません。
応答の client/service principal、flags、session key、暗号種別を確認してから
CCache credential を作ります。-altservice は保存前に service principal
表現を調整しますが、暗号化済み ticket の鍵自体を変えるものではありません。
-force-forwardable などの flag 操作では、ticket encrypted part を復号・
再暗号化できる key が本当にあるかを先に検証する必要があります。
主要な実装要素
Section titled “主要な実装要素”| シンボル | 位置 | 責務を追う入口 |
|---|---|---|
GETST | 81 | __init__()、saveTicket()、doS4U2ProxyWithAdditionalTicket()、doS4U()、run() |
Impacket 内部
Section titled “Impacket 内部”| モジュール | 使用する主な名前 |
|---|---|
impacket | version |
impacket.examples | logger |
impacket.examples.utils | parse_identity |
impacket.krb5 | ccache, constants, crypto, types |
impacket.krb5.asn1 | AP_REQ, AS_REP, Authenticator, EncTGSRepPart, EncTicketPart, KERB_DMSA_KEY_PACKAGE, PA_FOR_USER_ENC, PA_PAC_OPTIONS, PA_S4U_X509_USER, S4UUserID, TGS_REP, TGS_REQ, Ticket, seq_set, seq_set_iter |
impacket.krb5.ccache | CCache, Credential |
impacket.krb5.crypto | Cksumtype, Enctype, Key, _AES256CTS, _HMACMD5, _enctype_table, _get_checksum_profile, string_to_key |
impacket.krb5.constants | ApplicationTagNumbers, TicketFlags, encodeFlags |
impacket.krb5.kerberosv5 | getKerberosTGS, getKerberosTGT, sendReceive |
impacket.krb5.types | KerberosTime, Principal, Ticket |
impacket.ntlm | compute_nthash |
impacket.winregistry | hexdump |
外部パッケージ(直接使用)
Section titled “外部パッケージ(直接使用)”| import 名 | 配布パッケージ | 経路・宣言状態 |
|---|---|---|
pyasn1 | pyasn1 | 直接 import、宣言済み |
six | six | 直接 import、宣言済み |
出力・副作用・必要権限
Section titled “出力・副作用・必要権限”- 照会や認証の試行が中心です。実行回数が多いと監査ログやアカウントロック、対象の負荷に影響します。
- オプションによりローカルファイルを作成または更新します。既存ファイルの扱いと秘密情報を含む出力の権限を確認してください。
失敗経路と後始末
Section titled “失敗経路と後始末”- 失敗時は、名前解決、接続、認証、サービスの状態、権限のどこで止まったかを、プロトコルのステータスから切り分けます。
実装を変更するとき
Section titled “実装を変更するとき”krb5.asn1 / constants / crypto / kerberosv5 / ccache、pyasn1、NT hash helper に依存します。中心は GETST.run()、doS4U()、doS4U2ProxyWithAdditionalTicket() です。ticket flags と session key の対応を崩さないでください。
- 構文:
python -m py_compile examples/getST.py - CLI:
python examples/getST.py -h - 関連テスト:
tests/SMB_RPC/test_ntlm.py - 関連テスト:
tests/misc/test_ccache.py - 関連テスト:
tests/misc/test_crypto.py - 関連テスト:
tests/misc/test_krb5_crypto.py - 関連テスト:
tests/misc/test_krb5_gssapi.py - 関連テスト:
tests/misc/test_winregistry.py

