Skip to main content

Overview

The impacket.krb5.asn1 module implements all ASN.1 (Abstract Syntax Notation One) structures defined in RFC 4120 and Microsoft extensions from [MS-KILE]. These structures represent Kerberos protocol messages, tickets, and data types encoded using Distinguished Encoding Rules (DER).

Module Location

Source: impacket/krb5/asn1.py

Basic Data Types

Primitive Types

Int32

32-bit signed integer used throughout Kerberos messages.
Range: -2,147,483,648 to 2,147,483,647

UInt32

32-bit unsigned integer for nonces and sequence numbers.

Microseconds

Microsecond values for timestamps.
Range: 0 to 999,999

KerberosString

UTF-8 encoded general string.

Realm

Kerberos realm name (domain).

KerberosTime

Generalized time format: YYYYMMDDHHMMSSz

KerberosFlags

Bit string for flags (32 bits minimum).

Principal Names

PrincipalName

Represents a Kerberos principal identity.
Fields:
  • name-type: Principal type (NT_PRINCIPAL, NT_SRV_INST, etc.)
  • name-string: Sequence of name components
Example:
Common Name Types:
  • NT_PRINCIPAL = 1: User principal (user@REALM)
  • NT_SRV_INST = 2: Service with instance (krbtgt/REALM)
  • NT_SRV_HST = 3: Service with host (host/server.domain)
  • NT_ENTERPRISE = 10: UPN format

Encryption Structures

EncryptionKey

Cryptographic key with type identifier.
Fields:
  • keytype: Encryption algorithm identifier
  • keyvalue: Raw key bytes
Example:
Key Types:
  • 1: DES-CBC-CRC
  • 3: DES-CBC-MD5
  • 16: DES3-CBC-SHA1
  • 17: AES128-CTS-HMAC-SHA1-96
  • 18: AES256-CTS-HMAC-SHA1-96
  • 23: RC4-HMAC

EncryptedData

Encrypted data with algorithm and optional version.
Fields:
  • etype: Encryption type
  • kvno: Key version number (optional)
  • cipher: Encrypted ciphertext
Example:

Checksum

Integrity checksum for messages.
Fields:
  • cksumtype: Checksum algorithm
  • checksum: Checksum value
Checksum Types:
  • 12: HMAC-SHA1-DES3
  • 15: HMAC-SHA1-96-AES128
  • 16: HMAC-SHA1-96-AES256
  • -138: HMAC-MD5 (0xffffff76)

Ticket Structures

Ticket

Kerberos ticket for service access.
Fields:
  • tkt-vno: Ticket version (always 5)
  • realm: Service realm
  • sname: Service principal name
  • enc-part: Encrypted ticket contents
Example:

EncTicketPart

Decrypted ticket contents (encrypted in ticket).
Key Fields:
  • flags: Ticket flags (forwardable, renewable, etc.)
  • key: Session key for client-service communication
  • crealm: Client realm
  • cname: Client principal name
  • authtime: Initial authentication time
  • starttime: Ticket valid start time
  • endtime: Ticket expiration time
  • renew-till: Renewable until time
  • authorization-data: MS-PAC and other authz data

TicketFlags

Bit flags controlling ticket behavior.
Common Flags:
  • Bit 1: forwardable - Can be forwarded to another service
  • Bit 2: forwarded - Ticket was forwarded
  • Bit 3: proxiable - Can be used to obtain proxy
  • Bit 8: renewable - Can be renewed
  • Bit 9: initial - Initial authentication
  • Bit 10: pre-authent - Pre-authentication used

Request Structures

AS-REQ (Authentication Service Request)

Initial authentication request for TGT.
Inherits from KDC_REQ:
Fields:
  • pvno: Protocol version (5)
  • msg-type: Message type (10 for AS-REQ)
  • padata: Pre-authentication data
  • req-body: Request body
Example:

KDC_REQ_BODY

Request body for AS-REQ and TGS-REQ.
Key Fields:
  • kdc-options: Request options (forwardable, renewable, etc.)
  • cname: Client name (AS-REQ only)
  • realm: Target realm
  • sname: Service name
  • till: Requested expiration time
  • nonce: Random nonce for replay protection
  • etype: Acceptable encryption types

TGS-REQ (Ticket Granting Service Request)

Request for service ticket.
TGS-REQ Pre-auth Data:

PA_DATA

Pre-authentication data.
Common PA Types:
  • 1: PA-TGS-REQ (AP-REQ for TGS)
  • 2: PA-ENC-TIMESTAMP (encrypted timestamp)
  • 11: PA-ETYPE-INFO (salt information)
  • 19: PA-ETYPE-INFO2 (extended salt info)
  • 128: PA-PAC-REQUEST (request PAC)
  • 129: PA-FOR-USER (S4U2Self)
Example:

Response Structures

AS-REP (Authentication Service Reply)

TGT response from KDC.
Inherits from KDC_REP:
Fields:
  • pvno: Protocol version (5)
  • msg-type: Message type (11 for AS-REP)
  • crealm: Client realm
  • cname: Client name
  • ticket: The TGT
  • enc-part: Encrypted part (session key, times, etc.)
Example:

EncASRepPart

Decrypted AS-REP encrypted part.
Inherits from EncKDCRepPart:
Critical Fields:
  • key: Session key for TGS-REQ
  • nonce: Must match request nonce
  • flags: Ticket flags granted
  • authtime: Authentication time
  • endtime: TGT expiration
  • srealm: Server realm
  • sname: Server name (krbtgt/REALM)

TGS-REP (Ticket Granting Service Reply)

Service ticket response.
Similar to AS-REP but:
  • msg-type: 13
  • ticket: Service ticket (not TGT)
  • Encrypted with TGS session key

EncTGSRepPart

Decrypted TGS-REP encrypted part.
Key usage: 8 (TGS session key)

Application Protocol

AP-REQ (Application Request)

Client authentication to service.
Fields:
  • pvno: 5
  • msg-type: 14
  • ap-options: Request options
  • ticket: Service ticket from TGS-REP
  • authenticator: Encrypted authenticator
AP Options:
  • Bit 2: mutual-required - Request AP-REP
Example:

Authenticator

Proof of session key possession.
Fields:
  • crealm: Client realm
  • cname: Client name
  • cksum: Checksum of application data (optional)
  • cusec: Microseconds of ctime
  • ctime: Current time
  • subkey: Optional session subkey
  • seq-number: Sequence number
Key Usage: 11 (for encryption)

AP-REP (Application Reply)

Mutual authentication response.
Fields:
  • pvno: 5
  • msg-type: 15
  • enc-part: Encrypted EncAPRepPart

EncAPRepPart

Decrypted AP-REP contents.
Key Usage: 12

Error Messages

KRB_ERROR

Error response from KDC or service.
Critical Fields:
  • stime: Server time
  • error-code: Kerberos error code
  • e-text: Human-readable error
  • e-data: Additional error data
Example:

Microsoft Extensions

KERB_PA_PAC_REQUEST

Request PAC in ticket.
Usage:

PA_FOR_USER_ENC

S4U2Self protocol data.
Purpose: Request ticket on behalf of user

PA_S4U_X509_USER

S4U with certificate.

ETYPE_INFO2

Extended encryption type info.
Usage: Provides salt for string-to-key conversion

Helper Functions

seq_set

Set component and return it for chaining.

seq_set_iter

Set sequence from iterable.

seq_append

Append to sequence component.

Encoding/Decoding

Encoding to DER

Decoding from DER

Complete Example

Building AS-REQ

See Also