MCPcopy Create free account
hub / github.com/secdev/scapy / receive_session_setup_response

Method receive_session_setup_response

scapy/layers/smbclient.py:537–601  ·  view source on GitHub ↗
(self, pkt)

Source from the content-addressed store, hash-verified

535
536 @ATMT.receive_condition(SENT_SESSION_REQUEST)
537 def receive_session_setup_response(self, pkt):
538 if (
539 SMBSession_Null in pkt
540 or SMBSession_Setup_AndX_Response_Extended_Security in pkt
541 or SMBSession_Setup_AndX_Response in pkt
542 ):
543 # SMB1
544 if SMBSession_Null in pkt:
545 # Likely an error
546 raise self.NEGOTIATED()
547 # Logging
548 if pkt.Status != 0 and pkt.Status != 0xC0000016:
549 # Not SUCCESS nor MORE_PROCESSING_REQUIRED: log
550 self.ErrorStatus = pkt.sprintf("%SMB2_Header.Status%")
551 self.debug(
552 lvl=1,
553 msg=conf.color_theme.red(
554 pkt.sprintf("SMB Session Setup Response: %SMB2_Header.Status%")
555 ),
556 )
557 if self.SMB2:
558 self.update_smbheader(pkt)
559 # Cases depending on the response packet
560 if (
561 SMBSession_Setup_AndX_Response_Extended_Security in pkt
562 or SMB2_Session_Setup_Response in pkt
563 ):
564 # The server assigns us a SessionId
565 self.smb_header.SessionId = pkt.SessionId
566 # SMB1 extended / SMB2
567 if pkt.Status == 0: # Authenticated
568 if SMB2_Session_Setup_Response in pkt:
569 # [MS-SMB2] sect 3.2.5.3.1
570 if pkt.SessionFlags.IS_GUEST:
571 # "If the security subsystem indicates that the session
572 # was established by a guest user, Session.SigningRequired
573 # MUST be set to FALSE and Session.IsGuest MUST be set to TRUE."
574 self.session.IsGuest = True
575 self.session.SigningRequired = False
576 elif self.session.Dialect >= 0x0300:
577 if pkt.SessionFlags.ENCRYPT_DATA or self.REQUIRE_ENCRYPTION:
578 self.session.EncryptData = True
579 self.session.SigningRequired = False
580 raise self.AUTHENTICATED(pkt.SecurityBlob)
581 else:
582 if SMB2_Header in pkt:
583 # If required, compute sessions
584 self.session.computeSMBSessionPreauth(
585 bytes(pkt[SMB2_Header]), # session response
586 )
587 # Ongoing auth
588 raise self.NEGOTIATED(pkt.SecurityBlob)
589 elif SMBSession_Setup_AndX_Response_Extended_Security in pkt:
590 # SMB1 non-extended
591 pass
592 elif SMB2_Error_Response in pkt:
593 # Authentication failure
594 self.session.sspcontext.clifailure()

Callers

nothing calls this directly

Calls 8

NEGOTIATEDMethod · 0.95
update_smbheaderMethod · 0.95
AUTHENTICATEDMethod · 0.95
AUTH_FAILEDMethod · 0.95
debugMethod · 0.80
sprintfMethod · 0.45
clifailureMethod · 0.45

Tested by

no test coverage detected