Skip to main content

Overview

The impacket.krb5.kerberosv5 module implements core Kerberos v5 protocol functions for requesting tickets, performing authentication, and handling Kerberos errors. This is the primary interface for Kerberos operations.

Module Location

Source: impacket/krb5/kerberosv5.py

Core Functions

getKerberosTGT

Request Ticket Granting Ticket (TGT) from KDC.
Parameters:
  • clientName: Principal object for client
  • password: Cleartext password (str)
  • domain: Kerberos realm (str)
  • lmhash: LM hash (bytes, usually empty)
  • nthash: NT hash (bytes, for pass-the-hash)
  • aesKey: AES key (bytes, 16 or 32 bytes)
  • kdcHost: KDC hostname/IP (str, optional)
  • requestPAC: Include PAC request (bool, default True)
  • serverName: Override server name (Principal, optional)
  • kerberoast_no_preauth: Allow no pre-auth (bool, default False)
Returns: Tuple of (tgt, cipher, oldSessionKey, sessionKey)
  • tgt: Encoded AS-REP message (bytes)
  • cipher: Cipher class for decryption
  • oldSessionKey: Client key used for AS-REP
  • sessionKey: TGS session key (Key object)
Example:
Pass-the-Hash Example:
Pass-the-Key Example:

getKerberosTGS

Request service ticket (TGS) from KDC.
Parameters:
  • serverName: Target service Principal object
  • domain: Kerberos realm (str)
  • kdcHost: KDC hostname/IP (str)
  • tgt: TGT from getKerberosTGT (bytes)
  • cipher: Cipher class from getKerberosTGT
  • sessionKey: TGT session key (Key object)
  • renew: Renew ticket instead of requesting new (bool)
Returns: Tuple of (tgs, cipher, oldSessionKey, sessionKey)
  • tgs: Encoded TGS-REP message (bytes)
  • cipher: Cipher class for service ticket
  • oldSessionKey: TGT session key
  • sessionKey: Service session key (Key object)
Example:
Renew Ticket Example:

getKerberosType1

Generate GSS-API/SPNEGO authentication token.
Parameters:
  • username: Username (str)
  • password: Password (str)
  • domain: Kerberos realm (str)
  • lmhash: LM hash (bytes)
  • nthash: NT hash (bytes)
  • aesKey: AES key (bytes)
  • TGT: Cached TGT dict (optional)
  • TGS: Cached TGS dict (optional)
  • targetName: Target hostname (str)
  • kdcHost: KDC hostname/IP (str, optional)
  • useCache: Use credential cache (bool, default True)
Returns: Tuple of (cipher, sessionKey, blob)
  • cipher: Cipher class
  • sessionKey: Service session key
  • blob: SPNEGO NegTokenInit blob (bytes)
Example:
With Cached Tickets:

getKerberosType3

Process AP-REP response for mutual authentication.
Parameters:
  • cipher: Cipher class from Type1
  • sessionKey: Session key from Type1
  • auth_data: Server response (SPNEGO NegTokenResp bytes)
Returns: Tuple of (cipher, sessionKey2, resp)
  • cipher: Updated cipher class
  • sessionKey2: Subsession key
  • resp: SPNEGO response blob
Example:

sendReceive

Send Kerberos message to KDC and receive response.
Parameters:
  • data: Encoded Kerberos message (bytes)
  • host: Target domain (str)
  • kdcHost: KDC hostname/IP (str, optional)
  • port: KDC port (int, default 88)
Returns: Response bytes or raises KerberosError Example:
Custom Port:

Error Handling

KerberosError Exception

Raised for Kerberos protocol errors.
Example:
Common Error Codes:

SessionKeyDecryptionError

Raised when AS-REP decryption fails.
Attributes:
  • message: Error description
  • asRep: AS-REP message
  • cipher: Cipher used
  • key: Decryption key
  • cipherText: Failed ciphertext
Example:

Advanced Operations

Ticket Manipulation

Extract Ticket from TGT

Modify Ticket SPN

S4U Extensions

S4U2Self (Service for User to Self)

Obtain ticket on behalf of user:

S4U2Proxy (Service for User to Proxy)

Use S4U2Self ticket to access another service:

Kerberoasting

Request service tickets for cracking:

ASREPRoasting

Request TGT without pre-authentication:

Complete Examples

Full Authentication Flow

Credential Cache Integration

Multi-Realm Authentication

Security Considerations

Clock Skew

KDC rejects requests with > 5 minute clock difference:

Credential Protection

Replay Protection

Authenticators include timestamps and nonces:

See Also