Skip to content

Add CertificateTrace support to LDAP Schannel authentication#21469

Draft
Pushpenderrathore wants to merge 2 commits into
rapid7:masterfrom
Pushpenderrathore:feature/ldap-schannel-trace-staging
Draft

Add CertificateTrace support to LDAP Schannel authentication#21469
Pushpenderrathore wants to merge 2 commits into
rapid7:masterfrom
Pushpenderrathore:feature/ldap-schannel-trace-staging

Conversation

@Pushpenderrathore
Copy link
Copy Markdown

@Pushpenderrathore Pushpenderrathore commented May 16, 2026

Summary

Follow-up to #21198. Extends the CertificateTrace facility (introduced there for PKINIT) to the LDAP Schannel authentication path so operators can inspect the client certificate used for an LDAPS bind.

When LDAP::Auth=SCHANNEL and LDAP::CertFile points at a PKCS12, the certificate is rendered through CertificateTracePresenter and printed by the module instance before the LDAP bind. Verbosity is controlled by the existing CertificateTrace advanced option (off / metadata / full).

Two files changed:

  • lib/msf/core/exploit/remote/ldap.rb wires the dispatcher into get_connect_opts, with a nil-pfx guard for the CertFile-not-set path.
  • spec/lib/msf/core/exploit/remote/ldap_spec.rb 7 new examples covering both the cert-loaded and no-cert paths so the guard is not dead code in CI.

Dependency

Stacked on #21198. Draft until that lands the CertificateTracePresenter commit shown in the diff here is the same one under review there and will collapse out once #21198 merges into master.

Verification

Run the LDAP spec (no DB required):

BUNDLER_VERSION=4.0.9 SPEC_HELPER_LOAD_METASPLOIT=false bundle exec rspec \
  spec/lib/msf/core/exploit/remote/ldap_spec.rb \
  --format documentation

Expected: 16 examples, 0 failures (9 pre-existing + 7 new for the cert trace paths).

Rubocop on the changed lib file:

bundle exec rubocop lib/msf/core/exploit/remote/ldap.rb

Expected: clean on lines I touched.

Test plan

  • Spec run: 16 examples, 0 failures
  • Rubocop: no new offenses on ldap.rb
  • Manual: in msfconsole, with a Schannel-eligible module, set LDAP::Auth=SCHANNEL, LDAP::CertFile=<path to PKCS12>, CertificateTrace=full observe the certificate dump in module output before the LDAP bind
  • Manual: with LDAP::CertFile unset, confirm the trace path is skipped silently (nil-pfx guard)

Introduces an opt-in certificate trace facility for Kerberos PKINIT
authentication. Operators enable it via the CertificateTrace advanced
option (off / metadata / full / csr); when active, the client certificate
submitted to the KDC during send_request_tgt_pkinit is rendered through
CertificateTracePresenter and printed by the module instance.

The presenter is a pure string builder. The dispatcher
(certificate_trace in kerberos/client.rb) selects the verbosity, builds
the string, and calls print_line on the including module. Tracing is
nil-safe at every layer: bad PKCS12 input yields nil from the presenter
and the dispatcher no-ops.
Extends the CertificateTrace facility (introduced in the cert presenter PR)
to the LDAP Schannel auth path. Operators enable it via the CertificateTrace
advanced option (off / metadata / full), gated on LDAP::Auth == SCHANNEL.

When LDAP::CertFile loads a PKCS12 inside get_connect_opts, the certificate
is rendered through CertificateTracePresenter and printed by the module
instance before the LDAP bind. The nil-pfx guard is exercised by spec so
the CertFile-not-set path is not dead code.
@github-actions
Copy link
Copy Markdown

Thanks for your pull request! As part of our landing process, we manually verify that all modules work as expected.

We've added the additional-testing-required label to indicate that additional testing is required before this pull request can be merged.
For maintainers, this means visiting here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants