Skip to content

Commit 28bc001

Browse files
committed
Formating
1 parent 631107d commit 28bc001

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

nxc/helpers/pfx.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
from minikerberos.common.target import KerberosTarget
6868
from minikerberos.common.ccache import CCACHE
6969

70-
from impacket.krb5.ccache import CCache
70+
from impacket.krb5.ccache import CCache as impacket_CCache
7171

7272

7373
class myPKINIT(PKINIT):
@@ -164,7 +164,6 @@ def build_asreq(self, domain=None, cname=None, kdcopts=None):
164164
kdc_req_body_data["etype"] = [18, 17] # 23 breaks...
165165
kdc_req_body = KDC_REQ_BODY(kdc_req_body_data)
166166

167-
168167
checksum = hashlib.sha1(kdc_req_body.dump()).digest()
169168

170169
authenticator = {}
@@ -173,7 +172,6 @@ def build_asreq(self, domain=None, cname=None, kdcopts=None):
173172
authenticator["nonce"] = secrets.randbits(31)
174173
authenticator["paChecksum"] = checksum
175174

176-
177175
dp = {}
178176
dp["p"] = self.diffie.p
179177
dp["g"] = self.diffie.g
@@ -187,7 +185,6 @@ def build_asreq(self, domain=None, cname=None, kdcopts=None):
187185
spki["algorithm"] = keys.PublicKeyAlgorithm(pka)
188186
spki["public_key"] = self.diffie.get_public_key()
189187

190-
191188
authpack = {}
192189
authpack["pkAuthenticator"] = PKAuthenticator(authenticator)
193190
authpack["clientPublicValue"] = keys.PublicKeyInfo(spki)
@@ -233,7 +230,6 @@ def sign_authpack_native(self, data, wrap_signed=False):
233230
"serial_number": self.certificate.serial_number,
234231
})
235232

236-
237233
si["digest_algorithm"] = algos.DigestAlgorithm(da)
238234
si["signed_attrs"] = [
239235
cms.CMSAttribute({"type": "content_type", "values": ["1.3.6.1.5.2.3.1"]}), # indicates that the encap_content_info's authdata struct (marked with OID '1.3.6.1.5.2.3.1' is signed )
@@ -304,7 +300,6 @@ def truncate_key(value, keysize):
304300
elif etype == Enctype.RC4:
305301
raise NotImplementedError("RC4 key truncation documentation missing. it is different from AES")
306302

307-
308303
key = Key(cipher.enctype, t_key)
309304
enc_data = as_rep["enc-part"]["cipher"]
310305
logging.info("AS-REP encryption key (you might need this later):")
@@ -355,7 +350,7 @@ def printPac(self, data, key=None):
355350
nthash = hexlify(credstruct["NtPassword"]).decode("utf-8")
356351

357352
buff = buff[len(infoBuffer):]
358-
353+
359354
if not found:
360355
logging.info("Did not find the PAC_CREDENTIAL_INFO in the PAC. Are you sure your TGT originated from a PKINIT operation?")
361356
return nthash
@@ -451,7 +446,7 @@ def dump(self):
451446
reqBody["till"] = KerberosTime.to_asn1(now)
452447
reqBody["nonce"] = random.getrandbits(31)
453448
seq_set_iter(reqBody, "etype",
454-
(int(cipher.enctype), int(constants.EncryptionTypes.rc4_hmac.value)))
449+
(int(cipher.enctype), int(constants.EncryptionTypes.rc4_hmac.value)))
455450

456451
myTicket = ticket.to_asn1(TicketAsn1())
457452
seq_set_iter(reqBody, "additional-tickets", (myTicket,))
@@ -480,12 +475,11 @@ def dump(self):
480475
# application session key), encrypted with the service key
481476
# (section 5.4.2)
482477

483-
484478
# S4USelf + U2U uses this other key
485479
plainText = cipher.decrypt(sessionKey, 2, cipherText)
486480
specialkey = Key(18, unhexlify(self.__asrep_key))
487481
return self.printPac(plainText, specialkey)
488-
482+
489483

490484
def pfx_auth(self):
491485
"""Handles the authentication using a PFX or PEM file"""
@@ -524,9 +518,9 @@ def pfx_auth(self):
524518
ccache_minikerberos = CCACHE()
525519
ccache_minikerberos.add_tgt(res.native, encasrep)
526520
ccache_minikerberos.to_file(log_ccache)
527-
self.logger.info(f"Saved TGT to file { log_ccache }")
528-
self.logger.info(f"Using Kerberos Cache { log_ccache }")
529-
ccache = CCache.loadFile(log_ccache)
521+
self.logger.info(f"Saved TGT to file {log_ccache}")
522+
self.logger.info(f"Using Kerberos Cache {log_ccache}")
523+
ccache = impacket_CCache.loadFile(log_ccache)
530524
principal = f"krbtgt/{self.domain.upper()}@{self.domain.upper()}"
531525
creds = ccache.getCredential(principal)
532526
if creds is not None:
@@ -539,4 +533,4 @@ def pfx_auth(self):
539533
self.kerberos_login(self.domain, username, "", nthash, "", self.kdcHost, False)
540534

541535
self.logger.info("Successfully authenticated using Certificate")
542-
return True
536+
return True

0 commit comments

Comments
 (0)