Skip to content

kerberos: check the AP-REP timestamp in KerberosSSP initiator - #5305

Open
musthaf-bughunter wants to merge 2 commits into
secdev:masterfrom
musthaf-bughunter:kerberos-initiator-aprep-time
Open

musthaf-bughunter wants to merge 2 commits into
secdev:masterfrom
musthaf-bughunter:kerberos-initiator-aprep-time

Conversation

@musthaf-bughunter

Copy link
Copy Markdown
Contributor

Description

KerberosSSP.GSS_Init_sec_context decrypts the AP-REP with the ticket session key and accepts it without comparing its ctime/cusec to the authenticator it sent (kerberos.py#L5838-L5845), which RFC4120 sect 3.2.5 requires. The ticket session key is the same for every AP-REQ made with a given service ticket (ST=/KEY=, ccache, Ticketer), so an AP-REP recorded from an earlier exchange completes mutual authentication of a later one. The client then uses the old subkey and sequence number, so a man-in-the-middle can impersonate the server and replay its old signed or sealed messages.

cli = KerberosSSP(UPN="User1@DOMAIN.LOCAL", SPN="cifs/dc1", ST=st, KEY=tktkey)
srv = KerberosSSP(SPN="cifs/dc1", KEY=srvkey)
c1, tok, _ = cli.GSS_Init_sec_context(None, req_flags=GSS_C_FLAGS.GSS_C_MUTUAL_FLAG)
_, old_ap_rep, _ = srv.GSS_Accept_sec_context(None, tok)
# later: new AP-REQ with the same ticket, answered with the old AP-REP
c2, tok, _ = cli.GSS_Init_sec_context(None, req_flags=GSS_C_FLAGS.GSS_C_MUTUAL_FLAG)
_, _, status = cli.GSS_Init_sec_context(c2, old_ap_rep)
assert status == GSS_S_COMPLETE  # before this patch

The patch stores the authenticator time in the context and returns GSS_S_DEFECTIVE_TOKEN when the AP-REP does not match, except in passive mode. The IAKERB test fed a captured AP-REP to an AP-REQ built with the mocked 2024 date, so that step now mocks the capture time. A regression test is added to kerberos.uts.

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.99%. Comparing base (4cef323) to head (eeecf0a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5305   +/-   ##
=======================================
  Coverage   78.99%   78.99%           
=======================================
  Files         375      375           
  Lines       98802    98807    +5     
=======================================
+ Hits        78044    78050    +6     
+ Misses      20758    20757    -1     
Files with missing lines Coverage Δ
scapy/layers/kerberos.py 72.34% <100.00%> (+0.12%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread scapy/layers/kerberos.py Resolved

@gpotter2 gpotter2 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR ! some minor comments

Comment thread test/scapy/layers/kerberos.uts Resolved
@gpotter2 gpotter2 self-assigned this Nov 22, 2026
@gpotter2
gpotter2 force-pushed the kerberos-initiator-aprep-time branch from 0ce4870 to 7a5daa0 Compare November 27, 2026 10:37
@gpotter2

Copy link
Copy Markdown
Member

Hi, sorry but tests don't pass.

@musthaf-bughunter

Copy link
Copy Markdown
Contributor Author

Looks like the test jobs never ran on that push: the commit validity check fails first and it gates the rest of the matrix. It's flagging the missing AI-Assisted trailer on the second commit rather than anything in the tests. Locally kerberos.uts is 104/104 with the new test included, and the only test failure on the earlier full run was the "Connect to google.com" case in tlsclientserver.uts.

RFC4120 sect 3.2.5 requires the client to check that the AP-REP ctime
and cusec match the authenticator it sent. Without this, an AP-REP
recorded for an earlier AP-REQ made with the same ticket completes
mutual authentication.

AI-Assisted: yes (Claude Opus 5.5)
@gpotter2
gpotter2 force-pushed the kerberos-initiator-aprep-time branch from 7a5daa0 to ead521e Compare November 30, 2026 13:53
@gpotter2

Copy link
Copy Markdown
Member

You are indeed missing the AI tag, check CONTRIBUTING.md: you'll need to edit the commit message, rebase and push force

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants