public void TreeDisconnect(uint treeId) { ulong mid = (ulong)Interlocked.Increment(ref MessageId); SMB2Header smb2Header = new SMB2Header(ESMB2Command.TREE_DISCONNECT, SMB2HeaderFlags.None, mid, treeId, SessionId); SMB2Body smb2Body = new LogoffAndTreeDisconnect(); SMB2Message smb2Message = new SMB2Message(smb2Header, smb2Body); SMBTransport.SendDatas(smb2Message.DumpBinary()); var sm = GetMessage(mid); if (sm.SMB2Header.Status != NTStateType.Success) { throw new Exception("TreeDisconnect Status error:" + sm.SMB2Header.Status); } }
public void SessionLogoff() { if (IsBuildSession) { ulong mid = (ulong)Interlocked.Increment(ref MessageId); SMB2Header smb2Header = new SMB2Header(ESMB2Command.LOGOFF, SMB2HeaderFlags.None, mid, 0, SessionId); SMB2Body smb2Body = new LogoffAndTreeDisconnect(); SMB2Message smb2Message = new SMB2Message(smb2Header, smb2Body); SMBTransport.SendDatas(smb2Message.DumpBinary()); var sm = GetMessage(mid); if (sm.SMB2Header.Status != NTStateType.Success) { throw new Exception("SessionLogoff Status error:" + sm.SMB2Header.Status); } IsBuildSession = false; } }
public static SMB2Body CreateSMB2Body(byte[] vs, int offset, ESMB2Command eSMB2Command, SMB2HeaderFlags smb2HeaderFlags, NTStateType ntState) { SMB2Body sMB2Body = null; if (smb2HeaderFlags.HasFlag(SMB2HeaderFlags.ServerToRedir)) { if (ntState == NTStateType.Success || ntState == NTStateType.MoreProcessingRequired || ntState == NTStateType.LogonFailure) { switch (eSMB2Command) { case ESMB2Command.NEGOTIATE: sMB2Body = NegotiateResponse.Parser(vs, offset); break; case ESMB2Command.SESSION_SETUP: sMB2Body = SessionSetupResponse.Parser(vs, offset); break; case ESMB2Command.TREE_CONNECT: sMB2Body = TreeConnectResponse.Parser(vs, offset); break; case ESMB2Command.LOGOFF: case ESMB2Command.TREE_DISCONNECT: sMB2Body = LogoffAndTreeDisconnect.Parser(vs, offset); break; case ESMB2Command.CREATE: sMB2Body = CreateResponse.Parser(vs, offset); break; case ESMB2Command.CLOSE: sMB2Body = CloseResponse.Parser(vs, offset); break; case ESMB2Command.WRITE: sMB2Body = WriteResponse.Parser(vs, offset); break; case ESMB2Command.READ: sMB2Body = ReadResponse.Parser(vs, offset); break; case ESMB2Command.IOCTL: sMB2Body = IOCTLResponse.Parser(vs, offset); break; default: throw new Exception("UnKnow SMB2 Command"); } } else { sMB2Body = ErrorResponse.Parser(vs, offset); } } else { throw new NotImplementedException(); } return(sMB2Body); }