internal Boolean CreateRequest(Byte[] ShareAccess) { treeId = recieve.Skip(40).Take(4).ToArray(); SMB2Header header = new SMB2Header(); header.SetCommand(new Byte[] { 0x05, 0x00 }); header.SetCreditsRequested(new Byte[] { 0x01, 0x00 }); header.SetMessageID(++messageId); header.SetProcessID(processId); header.SetTreeId(treeId); header.SetSessionID(sessionId); SMB2CreateRequest createRequest = new SMB2CreateRequest(); createRequest.SetFileName("svcctl"); createRequest.SetShareAccess(ShareAccess); Byte[] bData = createRequest.GetRequest(); if (signing) { header.SetFlags(new Byte[] { 0x08, 0x00, 0x00, 0x00 }); header.SetSignature(sessionKey, ref bData); } Byte[] bHeader = header.GetHeader(); Boolean returnValue = Send(bHeader, bData); guidFileHandle = recieve.Skip(0x0084).Take(16).ToArray(); return(returnValue); }
//////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// internal override Boolean CreateRequest(String folder) { treeId = recieve.Skip(40).Take(4).ToArray(); SMB2Header header = new SMB2Header(); header.SetCommand(new Byte[] { 0x05, 0x00 }); header.SetCreditsRequested(new Byte[] { 0x01, 0x00 }); header.SetMessageID(++messageId); header.SetProcessID(processId); header.SetTreeId(treeId); header.SetSessionID(sessionId); SMB2CreateRequest createRequest = new SMB2CreateRequest(); if (!String.IsNullOrEmpty(folder)) { createRequest.SetFileName(folder); } createRequest.SetExtraInfo(1, 0); createRequest.SetCreateOptions(new Byte[] { 0x00, 0x00, 0x20, 0x00 }); createRequest.SetAccessMask(new Byte[] { 0x89, 0x00, 0x12, 0x00 }); createRequest.SetShareAccess(new Byte[] { 0x05, 0x00, 0x00, 0x00 }); Byte[] bData = createRequest.GetRequest(); if (signing) { header.SetFlags(new Byte[] { 0x08, 0x00, 0x00, 0x00 }); header.SetSignature(sessionKey, ref bData); } Byte[] bHeader = header.GetHeader(); NetBIOSSessionService sessionService = new NetBIOSSessionService(); sessionService.SetHeaderLength(bHeader.Length); sessionService.SetDataLength(bData.Length); Byte[] bSessionService = sessionService.GetNetBIOSSessionService(); Byte[] bSend = Combine.combine(Combine.combine(bSessionService, bHeader), bData); streamSocket.Write(bSend, 0, bSend.Length); streamSocket.Flush(); streamSocket.Read(recieve, 0, recieve.Length); if (GetStatus(recieve.Skip(12).Take(4).ToArray())) { guidFileHandle = recieve.Skip(0x0084).Take(16).ToArray(); return(true); } return(false); }
//////////////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////// internal virtual Boolean FindRequest(String folder) { treeId = recieve.Skip(40).Take(4).ToArray(); //////////////////////////////////////////////////////////////////////////////// SMB2Header header = new SMB2Header(); header.SetCommand(new Byte[] { 0x05, 0x00 }); header.SetCreditsRequested(new Byte[] { 0x01, 0x00 }); header.SetMessageID(++messageId); header.SetProcessID(processId); header.SetTreeId(treeId); header.SetSessionID(sessionId); SMB2CreateRequest createRequest = new SMB2CreateRequest(); if (!String.IsNullOrEmpty(folder)) createRequest.SetFileName(folder); createRequest.SetExtraInfo(1, 0); createRequest.SetAccessMask(new Byte[] { 0x81, 0x00, 0x10, 0x00 }); createRequest.SetShareAccess(new Byte[] { 0x07, 0x00, 0x00, 0x00 }); Byte[] bData = createRequest.GetRequest(); header.SetChainOffset(bData.Length); if (signing) { header.SetFlags(new Byte[] { 0x0c, 0x00, 0x00, 0x00 }); header.SetSignature(sessionKey, ref bData); } else { header.SetFlags(new Byte[] { 0x00, 0x00, 0x00, 0x00 }); } Byte[] bHeader = header.GetHeader(); //////////////////////////////////////////////////////////////////////////////// SMB2Header header2 = new SMB2Header(); header2.SetCommand(new Byte[] { 0x0e, 0x00 }); header2.SetCreditsRequested(new Byte[] { 0x01, 0x00 }); header2.SetMessageID(++messageId); header2.SetProcessID(processId); header2.SetTreeId(treeId); header2.SetSessionID(sessionId); header2.SetChainOffset(new Byte[] { 0x68, 0x00, 0x00, 0x00 }); SMB2FindFileRequestFile requestFile = new SMB2FindFileRequestFile(); requestFile.SetPadding(new Byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); Byte[] bData2 = requestFile.GetRequest(); if (signing) { header2.SetFlags(new Byte[] { 0x0c, 0x00, 0x00, 0x00 }); header2.SetSignature(sessionKey, ref bData2); } else { header2.SetFlags(new Byte[] { 0x04, 0x00, 0x00, 0x00 }); } Byte[] bHeader2 = header2.GetHeader(); //////////////////////////////////////////////////////////////////////////////// SMB2Header header3 = new SMB2Header(); header3.SetCommand(new Byte[] { 0x0e, 0x00 }); header3.SetCreditsRequested(new Byte[] { 0x01, 0x00 }); header3.SetMessageID(++messageId); header3.SetProcessID(processId); header3.SetTreeId(treeId); header3.SetSessionID(sessionId); SMB2FindFileRequestFile requestFile2 = new SMB2FindFileRequestFile(); requestFile2.SetOutputBufferLength(new Byte[] { 0x80, 0x00, 0x00, 0x00 }); Byte[] bData3 = requestFile2.GetRequest(); if (signing) { header3.SetFlags(new Byte[] { 0x0c, 0x00, 0x00, 0x00 }); header3.SetSignature(sessionKey, ref bData3); } else { header3.SetFlags(new Byte[] { 0x04, 0x00, 0x00, 0x00 }); } Byte[] bHeader3 = header3.GetHeader(); //////////////////////////////////////////////////////////////////////////////// NetBIOSSessionService sessionService = new NetBIOSSessionService(); sessionService.SetHeaderLength(bHeader.Length + bHeader2.Length + bHeader3.Length); sessionService.SetDataLength(bData.Length + bData2.Length + bData3.Length); Byte[] bSessionService = sessionService.GetNetBIOSSessionService(); Byte[] bSend = Combine.combine(Combine.combine(bSessionService, bHeader), bData); bSend = Combine.combine(bSend, Combine.combine(bHeader2, bData2)); bSend = Combine.combine(bSend, Combine.combine(bHeader3, bData3)); streamSocket.Write(bSend, 0, bSend.Length); streamSocket.Flush(); streamSocket.Read(recieve, 0, recieve.Length); if (GetStatus(recieve.Skip(12).Take(4).ToArray())) return true; else return false; }