3030import secrets
3131import hashlib
3232import datetime
33- import logging
3433import random
3534import base64
3635
4746from minikerberos .pkinit import PKINIT , DirtyDH
4847from minikerberos .protocol .constants import NAME_TYPE , PaDataType
4948from minikerberos .protocol .encryption import Enctype , _enctype_table , Key
50- from minikerberos .protocol .asn1_structs import KDC_REQ_BODY , PrincipalName , KDCOptions , EncASRepPart , AS_REQ , PADATA_TYPE , \
51- PA_PAC_REQUEST
49+ from minikerberos .protocol .asn1_structs import KDC_REQ_BODY , PrincipalName , KDCOptions , EncASRepPart , AS_REQ , PADATA_TYPE , PA_PAC_REQUEST
5250from minikerberos .protocol .rfc4556 import PKAuthenticator , AuthPack , PA_PK_AS_REP , KDCDHKeyInfo , PA_PK_AS_REQ
5351
5452from pyasn1 .codec .der import decoder , encoder
7068from impacket .krb5 .ccache import CCache as impacket_CCache
7169
7270from nxc .paths import NXC_PATH
71+ from nxc .logger import nxc_logger
7372
7473
7574class myPKINIT (PKINIT ):
@@ -304,8 +303,8 @@ def truncate_key(value, keysize):
304303
305304 key = Key (cipher .enctype , t_key )
306305 enc_data = as_rep ["enc-part" ]["cipher" ]
307- logging .info ("AS-REP encryption key (you might need this later):" )
308- logging .info (hexlify (t_key ).decode ("utf-8" ))
306+ nxc_logger .info ("AS-REP encryption key (you might need this later):" )
307+ nxc_logger .info (hexlify (t_key ).decode ("utf-8" ))
309308 dec_data = cipher .decrypt (key , 3 , enc_data )
310309 encasrep = EncASRepPart .load (dec_data ).native
311310 cipher = _enctype_table [int (encasrep ["key" ]["keytype" ])]
@@ -327,34 +326,27 @@ def printPac(self, data, key=None):
327326 for _bufferN in range (pacType ["cBuffers" ]):
328327 infoBuffer = PAC_INFO_BUFFER (buff )
329328 data = pacType ["Buffers" ][infoBuffer ["Offset" ] - 8 :][:infoBuffer ["cbBufferSize" ]]
330- if logging .getLogger ().level == logging .DEBUG :
331- print ("TYPE 0x%x" % infoBuffer ["ulType" ])
329+ nxc_logger .debug (f"TYPE 0x{ infoBuffer ['ulType' ]} " )
332330 if infoBuffer ["ulType" ] == 2 :
333331 found = True
334332 credinfo = PAC_CREDENTIAL_INFO (data )
335- if logging .getLogger ().level == logging .DEBUG :
336- credinfo .dump ()
337333 newCipher = _enctype_table [credinfo ["EncryptionType" ]]
338334 out = newCipher .decrypt (key , 16 , credinfo ["SerializedData" ])
339335 type1 = TypeSerialization1 (out )
340336 # I'm skipping here 4 bytes with its the ReferentID for the pointer
341337 newdata = out [len (type1 ) + 4 :]
342338 pcc = PAC_CREDENTIAL_DATA (newdata )
343- if logging .getLogger ().level == logging .DEBUG :
344- pcc .dump ()
345339 for cred in pcc ["Credentials" ]:
346340 credstruct = NTLM_SUPPLEMENTAL_CREDENTIAL (b"" .join (cred ["Credentials" ]))
347- if logging .getLogger ().level == logging .DEBUG :
348- credstruct .dump ()
349341
350- logging .info ("Recovered NT Hash" )
351- logging .info (hexlify (credstruct ["NtPassword" ]).decode ("utf-8" ))
342+ nxc_logger .info ("Recovered NT Hash" )
343+ nxc_logger .info (hexlify (credstruct ["NtPassword" ]).decode ("utf-8" ))
352344 nthash = hexlify (credstruct ["NtPassword" ]).decode ("utf-8" )
353345
354346 buff = buff [len (infoBuffer ):]
355347
356348 if not found :
357- logging .info ("Did not find the PAC_CREDENTIAL_INFO in the PAC. Are you sure your TGT originated from a PKINIT operation?" )
349+ nxc_logger .info ("Did not find the PAC_CREDENTIAL_INFO in the PAC. Are you sure your TGT originated from a PKINIT operation?" )
358350 return nthash
359351
360352 def __init__ (self , username , domain , kdcHost , key , tgt ):
@@ -399,10 +391,8 @@ def dump(self):
399391 authenticator ["cusec" ] = now .microsecond
400392 authenticator ["ctime" ] = KerberosTime .to_asn1 (now )
401393
402- if logging .getLogger ().level == logging .DEBUG :
403- logging .debug ("AUTHENTICATOR" )
404- print (authenticator .prettyPrint ())
405- print ("\n " )
394+ nxc_logger .debug ("AUTHENTICATOR" )
395+ nxc_logger .debug (authenticator .prettyPrint () + "\n " )
406396
407397 encodedAuthenticator = encoder .encode (authenticator )
408398
@@ -452,23 +442,18 @@ def dump(self):
452442
453443 myTicket = ticket .to_asn1 (TicketAsn1 ())
454444 seq_set_iter (reqBody , "additional-tickets" , (myTicket ,))
455- if logging .getLogger ().level == logging .DEBUG :
456- logging .debug ("Final TGS" )
457- print (tgsReq .prettyPrint ())
458- if logging .getLogger ().level == logging .DEBUG :
459- logging .debug ("Final TGS" )
460- print (tgsReq .prettyPrint ())
445+ nxc_logger .debug ("Final TGS" )
446+ nxc_logger .debug (tgsReq .prettyPrint ())
461447
462448 message = encoder .encode (tgsReq )
463- logging .info ("Requesting ticket to self with PAC" )
449+ nxc_logger .info ("Requesting ticket to self with PAC" )
464450
465451 r = sendReceive (message , self .__domain , self .__kdcHost )
466452
467453 tgs = decoder .decode (r , asn1Spec = TGS_REP ())[0 ]
468454
469- if logging .getLogger ().level == logging .DEBUG :
470- logging .debug ("TGS_REP" )
471- print (tgs .prettyPrint ())
455+ nxc_logger .debug ("TGS_REP" )
456+ nxc_logger .debug (tgs .prettyPrint ())
472457
473458 cipherText = tgs ["ticket" ]["enc-part" ]["cipher" ]
474459
0 commit comments