Repository navigation
Add a PKINIT client implementing RFC 4556, RFC 5349, RFC 4557 and RFC 8070 - #2260
Conversation
|
Dang I implemented this a few months ago https://github.com/ThatTotallyRealMyth/impacket/tree/add-pku2u-protocol while waiting for the wrap up of #2213 : ( but your implementation is defo better and more complete so kudos :3 |
b6bc48c to
f524ea9
Compare
|
Tested on goad lab, all good, @anadrianmanrique if you have time on this one 🙏 Every ✅ below is a TGT that I then used for a TGS-REQ and an SMB login (including the referral to the child domain):
|
|
I've checked the new commits, but I think I found a problem with
Suggested fix (fail closed with a clear message): with open(options.ca_cert, 'rb') as fd:
trustedCAs = readPEMCertificates(fd.read())
+ if not trustedCAs:
+ logging.critical('-ca-cert %s is not a PEM file (DER is not supported, convert it with: '
+ 'openssl x509 -inform DER -in %s -out ca.pem)' % (options.ca_cert, options.ca_cert))
+ sys.exit(1)Another option would be to accept DER in |
Thanks! It’s fixed. |
|
Retested on GOAD, LGTM 👍 |
|
Malformed KDC replies containing oversized ASN.1 lengths could raise an uncaught OverflowError with pyasn1 0.6.1, which was still permitted by the project’s dependency requirements. CI OverflowError was added to PARSE_ERRORS so that these malformed inputs would consistently raise PKINITError. A deterministic regression test was also added. |
|
RSA PKINIT is exposed in getTGT.py, but the workflow is not complete Test target: • Windows Server 2022 DC The stock PR was tested with: python3 examples/getTGT.py The RSA workflow fails at three consecutive points.
The tested Windows KDC returned: The RSA request also needs to advertise CMS identifiers (13, 15, 11) for RSA key transport, 3DES content encryption and RSA/SHA-1 signatures.
After the CMS identifiers were added diagnostically, Windows returned PA-PK-AS-REP.encKeyPack. The client decrypts it and passes the result directly to verifySignedData() a pkinit.py lines 1261–1262 (https://github.com/azoxlpf/impacket/blob/54269e18bc6049b84370058eed8d8583f5dfbc6f/impacket/krb5/pkinit.py#L1261).
After correcting the CMS parsing boundary diagnostically, processing reached ReplyKeyPack.asChecksum. Windows returned checksum type 14, but the implementation only accepts the checksum mapped from the reply-key enctype at pkinit.py lines 1272–1279 (https://github.com/azoxlpf/impacket/blob/54269e18bc6049b84370058eed8d8583f5dfbc6f/impacket/krb5/pkinit.py#L1272). Processing stopped with: Why the tests do not catch thisThe mock KDC builds the RSA response at test_pkinit.py lines 251–300 (https://github.com/azoxlpf/impacket/blob/54269e18bc6049b84370058eed8d8583f5dfbc6f/tests/misc/test_pkinit.py#L251). It encrypts the complete ContentInfo returned by buildSignedData(), rather than the SignedData value used by the real Windows exchange. The RSA tests at test_pkinit.py lines 689–698 (https://github.com/azoxlpf/impacket/blob/54269e18bc6049b84370058eed8d8583f5dfbc6f/tests/misc/test_pkinit.py#L689) also do not reproduce Windows’ CMS negotiation or checksum-type-14 behavior. As a result, the tests pass even though the public RSA workflow fails against Microsoft AD. |
|
Changes: • getTGT.py (examples/getTGT.py:126): clarified RSA/CMS help text; no diagnostic option was added. • pkinit.py (impacket/krb5/pkinit.py:101): • test_pkinit.py (tests/misc/test_pkinit.py:61): |
|
The commit updated PKINIT certificate-path validation so that every matching trust anchor and intermediate certificate is evaluated instead of selecting the first certificate with a matching subject name. |
|
regression on GOAD for regular cert authentication, shadow creds and adcs wf passed ok. PR is ready to be merged now. |
Well, I think this is the biggest PR I have ever opened. It has been about six months of reading
RFCs, staring atWireshark, and quietly enjoying myself far more than is reasonable for someone decodingASN.1by hand 😆Here is the thing that started it. Every
PKINITimplementation I could find, doesPKINITand then immediately follows it with aU2Uexchange to pull the accountNT hashout of thePAC, and authenticates with that hash. It is a perfectly good trick: you get anNT hash, which is useful on its own, and the code is short. But it is not whatRFC 4556actually describes. The whole point ofPKINITis that theAS reply keycomes out of the certificate exchange itself, so theTGTyou get back is a normal, directly usableTGT. NoU2U, noNT hash, no second round trip.So this PR implements the real thing.
I tried to reference the
RFCsas much as I could throughout the code, section by section, so that any check or any odd looking piece of encoding can be traced back to the paragraph it comes from without having to take my word for it.Disclosure:
Claude Opus 4.6helped me understand some parts of the specification,find and fix bugs in my code, and build the test suite.