Skip to content

Reauth after STATUS_NETWORK_SESSION_EXPIRED #292

Merged
cdelafuente-r7 merged 2 commits intorapid7:masterfrom
jheysel-r7:fix/lib/smb_relay_ruby_client_support
Mar 24, 2026
Merged

Reauth after STATUS_NETWORK_SESSION_EXPIRED #292
cdelafuente-r7 merged 2 commits intorapid7:masterfrom
jheysel-r7:fix/lib/smb_relay_ruby_client_support

Conversation

@jheysel-r7
Copy link
Copy Markdown
Contributor

@jheysel-r7 jheysel-r7 commented Feb 12, 2026

This PR makes a small change to attempt to re-authenticate when the client receives the STATUS_NETWORK_SESSION_EXPIRED error. This is how Window's net use client responds to the error.
https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb/6ab6ca20-b404-41fd-b91a-2ed39e3762ea

The smb_relay Metasploit module makes it possible relay an authentication request to multiple targets, by making use of the SMB error STATUS_NETWORK_SESSION_EXPIRED. The relay server first tricks the client into thinking it's authentication attempt was successful, and then throws the error code STATUS_NETWORK_SESSION_EXPIRED which forces the client to re-authenticate and allows the relay server to relay to as many targets as it would like by sending that error code repeatedly.

It seems like this minor detail was never implemented in ruby_smb, nor was it implemented in python's smbprotocol implementation as seen here python smb issue. This is why the smb_relay could never relay authentication from any client other than net use.

Testing

See the metasploit-framework PR for testing instructions

# to re-authenticate, which makes relaying ntlm authentication to multiple targets possible. This block ensures
# ruby_smb behaves in the same manner as 'net use'.
if smb2_header && smb2_header.nt_status == WindowsError::NTStatus::STATUS_NETWORK_SESSION_EXPIRED
session_setup(self.username, self.password, self.domain, local_workstation: self.local_workstation, ntlm_flags: NTLM::DEFAULT_CLIENT_FLAGS)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We'll want to test what happens here if the authentication mechanism is Kerberos. If it can't proceed and we received a STATUS_NETWORK_SESSION_EXPIRED then raising that as an exception (which it might already do, I haven't checked) would be a good idea.

@cdelafuente-r7 cdelafuente-r7 moved this from In Progress to Waiting on Contributor in Metasploit Kanban Mar 23, 2026
@cdelafuente-r7
Copy link
Copy Markdown
Contributor

Thank you @jheysel-r7 ! This has been tested with rapid7/metasploit-framework#20967 and I confirmed the client re-authenticates when receiving the STATUS_NETWORK_SESSION_EXPIRED error (see the PR description for a detailed output of msfconsole). I'll go ahead and land it.

@cdelafuente-r7 cdelafuente-r7 merged commit 157f579 into rapid7:master Mar 24, 2026
14 checks passed
@github-project-automation github-project-automation bot moved this from Waiting on Contributor to Done in Metasploit Kanban Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants