Skip to content

Back to the Category Index / Back to the Command Index

A development proxy that relays Kerberos TCP traffic and observes or modifies requests and responses.

ItemDetails
Implementationexamples/kintercept.py
CategoryKerberos / Ticket Handling
Size296 lines
DistributionInstalled as a script through scripts=examples/*.py in setup.py

Check python examples/kintercept.py -h for the current option definitions.

ArgumentDescription
serverTarget server address.
--server-portTarget server port (default: 88).
--listen-portListening port (default: 88).
--listen-addrAddress to listen on.
--request-handlerRequest handler, for example s4u2else:user.
--reply-handlerReply handler, for example tgs-rep-user:user.
-tsAdd timestamps to log output.
-debugEnable debug logging.

A listening socket accepts connections, and InterceptConn forwards data asynchronously between the client and upstream KDC. It buffers Kerberos TCP length-prefixed frames, passes requests and replies through the specified handlers, and sends them to the other side. The included handlers modify parts of S4U2self requests and replies.

Kerberos over TCP consists of a four-byte network-order length followed by an ASN.1 message of that length. The proxy pairs a client connection with an upstream KDC connection and buffers both byte streams until a complete frame is available for a handler. One TCP read does not necessarily correspond to one Kerberos message.

Request and reply handlers observe or modify decoded messages, then place the re-encoded length and payload on the outbound queue. The included S4U handlers target specific request and reply fields, but unknown message types must pass through unchanged. Failing to update the ASN.1 or outer TCP length after a change can corrupt subsequent frames.

Each direction may be written asynchronously in part, so track the sent offset, EOF, and the peer’s half-close. The current asyncore dependency does not work on Python 3.12 or later. A move to selectors or asyncio must preserve buffering and backpressure behavior. The proxy does not generate KDC responses itself.

SymbolLocationEntry Point for Tracing Behavior
InterceptConn108__init__(), recv(), forward_data(), buffer_empty(), max_read_size(), readable(), handle_read(), handle_eof(), need_to_send_eof(), writable(), handle_write(), handle_close()
InterceptConnFactory220__init__(), produce()
InterceptServer233__init__(), intercept_conns(), handle_accept()
process_s4u2else_req()49Module function
mod_tgs_rep_user()95Module function
InterceptKRB5Tcp()189Module function
parse_args()264Module function
ModuleMain Names Used
impacketversion
impacket.krb5constants
impacket.krb5.cryptoCksumtype
impacket.krb5.asn1PA_FOR_USER_ENC, TGS_REP, TGS_REQ, seq_set
impacket.krb5.typesPrincipal
impacket.exampleslogger
Import NameDistribution PackageUsage / Declaration Status
pyasn1pyasn1Imported directly; declared dependency

Output, Side Effects, and Required Privileges

Section titled “Output, Side Effects, and Required Privileges”
  • Primarily queries and authentication attempts. Repeated runs can affect audit logs, account lockouts, and target load.
  • Starts a listening socket or long-running loop. Check the bind address, port, shutdown method, and shared state under concurrent connections.
  • On failure, use protocol status to determine whether name resolution, connection, authentication, service state, or permissions stopped the operation.
  • handle_close() handles cleanup. Check that new early returns and exception paths still reach it.
  • On Python 3.12 or later, importing asyncore fails. Treat this compatibility issue separately from network failures.
  • Ensure stop requests, client disconnects, partial reads and writes, and worker exceptions do not leave the entire listener in an inconsistent state.

This command depends on the former standard-library module asyncore, krb5.asn1, and pyasn1. asyncore was removed in Python 3.12, so the current implementation cannot be imported unchanged on the project’s supported Python 3.12/3.13. When replacing it, preserve InterceptConn partial read/write behavior and Kerberos TCP message boundaries; do not assume one recv returns one message.