public bool ConnectToShare(string serverIp, string clientIp) { try { using (var client = new SMBDClient(DetectionInfo.ConnectionTimeout)) { client.Connect(IPAddress.Parse(serverIp), IPAddress.Parse(clientIp)); client.Smb2Negotiate(DetectionInfo.SupportedSmbDialects); client.Smb2SessionSetup(DetectionInfo.Authentication, DetectionInfo.DomainName, DetectionInfo.SUTName, DetectionInfo.UserName, DetectionInfo.Password); string path = Smb2Utility.GetUncPath(DetectionInfo.SUTName, DetectionInfo.ShareFolder); uint treeId; client.Smb2TreeConnect(path, out treeId); FILEID fileId; client.CreateRandomFile(treeId, out fileId); uint fileLength = client.CalculateSmb2MaxReadWriteSize(); var buffer = Smb2Utility.CreateRandomByteArray((int)fileLength); client.Smb2Write(treeId, fileId, 0, buffer); byte[] output; client.Smb2Read(treeId, fileId, 0, fileLength, out output); bool result = Enumerable.SequenceEqual(buffer, output); if (!result) { DetectorUtil.WriteLog("The content of read and write is inconsistent."); } return(result); } } catch (Exception ex) { DetectorUtil.WriteLog(String.Format("ConnectToShare threw exception: {0}", ex)); return(false); } }
private bool TryNegotiateDialect(IPAddress ip, DialectRevision dialect) { try { using (var client = new SMBDClient(DetectionInfo.ConnectionTimeout)) { client.Connect(ip, IPAddress.Parse(DetectionInfo.DriverNonRdmaNICIPAddress)); client.Smb2Negotiate(new DialectRevision[] { dialect }); return(true); } } catch (Exception ex) { DetectorUtil.WriteLog(String.Format("TryNegotiateDialect threw exception: {0}", ex)); return(false); } }
private bool GetRemoteNetworkInterfaceInformation(IPAddress ip) { try { using (var client = new SMBDClient(DetectionInfo.ConnectionTimeout)) { client.Connect(ip, IPAddress.Parse(DetectionInfo.DriverNonRdmaNICIPAddress)); client.Smb2Negotiate(new DialectRevision[] { DialectRevision.Smb30, DialectRevision.Smb302, DialectRevision.Smb311 }); client.Smb2SessionSetup(DetectionInfo.Authentication, DetectionInfo.DomainName, DetectionInfo.SUTName, DetectionInfo.UserName, DetectionInfo.Password); uint treeId; string ipcPath = Smb2Utility.GetIPCPath(DetectionInfo.SUTName); client.Smb2TreeConnect(ipcPath, out treeId); byte[] input; byte[] output; client.IoCtl(treeId, CtlCode_Values.FSCTL_QUERY_NETWORK_INTERFACE_INFO, FILEID.Invalid, IOCTL_Request_Flags_Values.SMB2_0_IOCTL_IS_FSCTL, out input, out output); var networkInterfaces = Smb2Utility.UnmarshalNetworkInterfaceInfoResponse(output); var remoteInterfaces = ParseRemoteNetworkInterfaceInformation(networkInterfaces); FilterNetworkInterfaces(remoteInterfaces); return(true); } } catch (Exception ex) { DetectorUtil.WriteLog(String.Format("GetRemoteNetworkInterfaceInformation failed for {0}: {1}.", ip.ToString(), ex.ToString())); return(false); } }