示例#1
0
        public bool GetRemoteAdapters()
        {
            DetectorUtil.WriteLog("Get the remote adapters...");

            bool result = false;

            var ipList = GetIPAdressOfSut();

            // try all reachable SUT IP address
            foreach (var ip in ipList)
            {
                result = GetRemoteNetworkInterfaceInformation(ip);
                if (result)
                {
                    break;
                }
            }

            if (result)
            {
                DetectorUtil.WriteLog("Finished", false, LogStyle.StepPassed);
                return(true);
            }
            else
            {
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                return(false);
            }
        }
 private IPAddress GetHostIP(string hostname)
 {
     try
     {
         IPHostEntry host = Dns.GetHostEntry(hostname);
         foreach (IPAddress ip in host.AddressList)
         {
             if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
             {
                 DetectorUtil.WriteLog("Parse the host name or the ip address as: " + ip.ToString());
                 return(ip);
             }
         }
     }
     catch (Exception e)
     {
         DetectorUtil.WriteLog("Exception occured when parsing the host name or the ip address: " + e.Message);
         DetectorUtil.WriteLog("" + e.StackTrace);
         if (e.InnerException != null)
         {
             DetectorUtil.WriteLog("**" + e.InnerException.Message);
             DetectorUtil.WriteLog("**" + e.InnerException.StackTrace);
         }
         DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
     }
     return(null);
 }
        public bool CheckSmbDialect()
        {
            DetectorUtil.WriteLog("Check the supported SMB dialects of SUT...");

            bool result = false;

            var dialects = new DialectRevision[] { DialectRevision.Smb30, DialectRevision.Smb302, DialectRevision.Smb311 };

            var ipList = GetIPAdressOfSut();

            // try all reachable SUT IP address
            foreach (var ip in ipList)
            {
                var supportedDialects = TryNegotiateDialects(ip, dialects);
                if (supportedDialects.Length > 0)
                {
                    DetectionInfo.SupportedSmbDialects = supportedDialects;
                    DetectorUtil.WriteLog(String.Format("SMB dialects supported by SUT: {0}", String.Join(",", supportedDialects)));
                    result = true;
                    break;
                }
            }

            if (result)
            {
                DetectorUtil.WriteLog("Finished", false, LogStyle.StepPassed);
                return(true);
            }
            else
            {
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                return(false);
            }
        }
示例#4
0
        private bool CheckSMBDReadWrite(DialectRevision[] dialects, Channel_Values channel)
        {
            try
            {
                using (var client = new SMBDClient(DetectionInfo.ConnectionTimeout))
                {
                    var config = DetectionInfo.SMBDClientCapability;

                    RdmaAdapterInfo rdmaAdapterInfo;

                    client.ConnectOverRDMA(DetectionInfo.DriverRdmaNICIPAddress, DetectionInfo.SUTRdmaNICIPAddress, DetectionInfo.SMBDPort, config.MaxReceiveSize, out rdmaAdapterInfo);

                    client.SMBDNegotiate(
                        config.CreditsRequested,
                        config.ReceiveCreditMax,
                        config.PreferredSendSize,
                        config.MaxReceiveSize,
                        config.MaxFragmentedSize
                        );

                    client.Smb2Negotiate(dialects);

                    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 length = client.CalculateSMBDMaxReadWriteSize();

                    var buffer = Smb2Utility.CreateRandomByteArray((int)length);

                    client.SMBDWrite(treeId, fileId, channel, buffer, 0, DetectionInfo.Endian);

                    var readBuffer = new byte[length];

                    client.SMBDRead(treeId, fileId, channel, out readBuffer, 0, length, DetectionInfo.Endian);

                    if (!Enumerable.SequenceEqual(buffer, readBuffer))
                    {
                        throw new InvalidOperationException("The data is inconsistent for write and read!");
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                DetectorUtil.WriteLog(String.Format("CheckSMBDReadWrite threw exception: {0}", ex));
                return(false);
            }
        }
        private bool ProcessLicenseSequence(Configs config, TimeSpan timeout)
        {
            try
            {
                TS_LICENSE_PDU licensePdu = rdpeleClient.ExpectPdu(timeout);

                if (licensePdu.preamble.bMsgType == bMsgType_Values.ERROR_ALERT)
                {
                    // If the target machine is a personal terminal server, whether the client sends the license or not,
                    // the server always sends a license error message with the error code STATUS_VALID_CLIENT and the state transition code ST_NO_TRANSITION.
                    if (dwErrorCode_Values.STATUS_VALID_CLIENT != licensePdu.LicensingMessage.LicenseError.Value.dwErrorCode)
                    {
                        DetectorUtil.WriteLog($"A license error message with the error code STATUS_VALID_CLIENT should be received, but the real error code is {licensePdu.LicensingMessage.LicenseError.Value.dwErrorCode}.");
                    }
                    return(false);
                }

                DetectorUtil.WriteLog("Start RDP license procedure");
                if (bMsgType_Values.LICENSE_REQUEST != licensePdu.preamble.bMsgType)
                {
                    DetectorUtil.WriteLog($"A LICENSE_REQUEST message should be received from server, but the real message type is {licensePdu.preamble.bMsgType}");
                }

                rdpeleClient.SendClientNewLicenseRequest(
                    KeyExchangeAlg.KEY_EXCHANGE_ALG_RSA, (uint)Client_OS_ID.CLIENT_OS_ID_WINNT_POST_52 | (uint)Client_Image_ID.CLIENT_IMAGE_ID_MICROSOFT, config.ServerUserName, config.ClientName);
                licensePdu = rdpeleClient.ExpectPdu(timeout);
                if (bMsgType_Values.PLATFORM_CHALLENGE != licensePdu.preamble.bMsgType)
                {
                    DetectorUtil.WriteLog($"A PLATFORM_CHALLENGE message should be received from server, but the real message type is {licensePdu.preamble.bMsgType}");
                    return(false);
                }

                Random             random     = new Random();
                CLIENT_HARDWARE_ID clientHWID = new CLIENT_HARDWARE_ID
                {
                    PlatformId = (uint)Client_OS_ID.CLIENT_OS_ID_WINNT_POST_52 | (uint)Client_Image_ID.CLIENT_IMAGE_ID_MICROSOFT,
                    Data1      = (uint)random.Next(),
                    Data2      = (uint)random.Next(),
                    Data3      = (uint)random.Next(),
                    Data4      = (uint)random.Next()
                };
                rdpeleClient.SendClientPlatformChallengeResponse(clientHWID);
                licensePdu = rdpeleClient.ExpectPdu(timeout);
                if (bMsgType_Values.NEW_LICENSE != licensePdu.preamble.bMsgType)
                {
                    DetectorUtil.WriteLog($"A NEW_LICENSE message should be received from server, but the real message type is {licensePdu.preamble.bMsgType}");
                    return(false);
                }
                DetectorUtil.WriteLog("End RDP license procedure");
                return(true);
            }
            catch (Exception e)
            {
                DetectorUtil.WriteLog("RDP license procedure throws exception: " + e.Message);
                return(false);
            }
        }
        private void CheckSupportedProtocols()
        {
            // Notify the UI for detecting protocol supported finished
            DetectorUtil.WriteLog("Check specified protocols support...");
            bool serverSupportUDPFECR = false;
            bool serverSupportUDPFECL = false;

            if (connectResponsePdu.mcsCrsp.gccPdu.serverMultitransportChannelData != null)
            {
                if (connectResponsePdu.mcsCrsp.gccPdu.serverMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECR))
                {
                    serverSupportUDPFECR = true;
                }
                if (connectResponsePdu.mcsCrsp.gccPdu.serverMultitransportChannelData.flags.HasFlag(MULTITRANSPORT_TYPE_FLAGS.TRANSPORTTYPE_UDPFECL))
                {
                    serverSupportUDPFECL = true;
                }
            }
            detectInfo.IsSupportRDPEMT = serverSupportUDPFECR || serverSupportUDPFECL;

            if (detectInfo.IsSupportRDPEMT)
            {
                DetectorUtil.WriteLog("Detect RDPEMT supported");
            }
            else
            {
                DetectorUtil.WriteLog("Detect RDPEMT unsupported");
            }

            rdpedycClient = new RdpedycClient(rdpbcgrClient, rdpbcgrClient.Context, false);

            try
            {
                DynamicVirtualChannel channel = rdpedycClient.ExpectChannel(timeout, DYVNAME_RDPEDYC, DynamicVC_TransportType.RDP_TCP);
                if (channel != null)
                {
                    detectInfo.IsSupportRDPEDYC = true;
                }
                rdpedycClient.CloseChannel((ushort)channel.ChannelId);
            }
            catch
            {
                detectInfo.IsSupportRDPEDYC = false;
            }

            if (detectInfo.IsSupportRDPEDYC)
            {
                DetectorUtil.WriteLog("Detect RDPEDYC supported");
            }
            else
            {
                DetectorUtil.WriteLog("Detect RDPEDYC unsupported");
            }

            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);
        }
        private void CheckSupportedFeatures()
        {
            DetectorUtil.WriteLog("Check specified features support...");

            detectInfo.IsSupportAutoReconnect = SupportAutoReconnect();
            detectInfo.IsSupportFastPathInput = SupportFastPathInput();

            // Notify the UI for detecting feature supported finished
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);
        }
示例#8
0
        private bool PingSUT()
        {
            DetectorUtil.WriteLog("Ping Target SUT...");

            Ping        pingSender = new Ping();
            PingOptions options    = new PingOptions();

            // Use the default TtL value which is 128,
            // but change the fragmentation behavior.
            options.DontFragment = true;

            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "0123456789ABCDEF0123456789ABCDEF";

            byte[]    buffer = Encoding.ASCII.GetBytes(data);
            IPAddress address;

            if (!IPAddress.TryParse(config.ServerName, out address))
            {
                address = Dns.GetHostEntry(config.ServerName).AddressList.First();
            }
            int              timeout = 5000;
            bool             result  = false;
            List <PingReply> replies = new List <PingReply>();

            try
            {
                for (int i = 0; i < 4; i++)
                {
                    replies.Add(pingSender.Send(address, timeout, buffer, options));
                }
            }
            catch (Exception ex)
            {
                DetectorUtil.WriteLog(String.Format("PingSUT() threw exception: {0}", ex));

                return(false);
            }
            foreach (var reply in replies)
            {
                result |= (reply.Status == IPStatus.Success);
            }
            if (result)
            {
                DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);
                return(true);
            }
            else
            {
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                DetectorUtil.WriteLog("Target SUT has no response.");
                return(false);
            }
        }
        /// <summary>
        /// Establish a RDP connection to detect RDP feature
        /// </summary>
        /// <returns></returns>
        public bool DetectRDPFeature()
        {
            // Establish a RDP connection with RDP client
            try
            {
                DetectorUtil.WriteLog("Establish RDP connection with SUT...");

                StartRDPListening();
                triggerClientRDPConnect(detectInfo.TriggerMethod);
                EstablishRDPConnection();
                // Set RDP Version
                SetRdpVersion();

                CheckSupportedFeatures();

                CheckSupportedProtocols();
            }
            catch (Exception e)
            {
                DetectorUtil.WriteLog("Exception occured when establishing RDP connection: " + e.Message);
                DetectorUtil.WriteLog("" + e.StackTrace);
                if (e.InnerException != null)
                {
                    DetectorUtil.WriteLog("**" + e.InnerException.Message);
                    DetectorUtil.WriteLog("**" + e.InnerException.StackTrace);
                }
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                return(false);
            }
            finally
            {
                // Trigger client to close the RDP connection
                TriggerClientDisconnectAll(detectInfo.TriggerMethod);

                if (this.rdpedycServer != null)
                {
                    this.rdpedycServer.Dispose();
                    this.rdpedycServer = null;
                }
                if (this.rdpbcgrServerStack != null)
                {
                    this.rdpbcgrServerStack.Dispose();
                    this.rdpbcgrServerStack = null;
                }
            }

            // Notify the UI for establishing RDP connection successfully.
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);



            return(true);
        }
        /// <summary>
        /// Establish a RDP connection to detect RDP feature
        /// </summary>
        /// <returns>Return true if detection succeeded.</returns>
        public bool DetectRDPFeature(Configs config)
        {
            try
            {
                DetectorUtil.WriteLog("Establish RDP connection with SUT...");

                Initialize(config);
                ConnectRDPServer();

                bool status = EstablishRDPConnection(
                    config, requestedProtocol, SVCNames,
                    CompressionType.PACKET_COMPR_TYPE_NONE,
                    false,
                    true,
                    false,
                    false,
                    false,
                    true,
                    true);
                if (!status)
                {
                    DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                    return(false);
                }

                DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);

                CheckSupportedFeatures();
                CheckSupportedProtocols();
                SetRdpVersion(config);
            }
            catch (Exception e)
            {
                DetectorUtil.WriteLog("Exception occured when establishing RDP connection: " + e.Message);
                DetectorUtil.WriteLog("" + e.StackTrace);
                if (e.InnerException != null)
                {
                    DetectorUtil.WriteLog("**" + e.InnerException.Message);
                    DetectorUtil.WriteLog("**" + e.InnerException.StackTrace);
                }
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                return(false);
            }


            // Disconnect
            ClientInitiatedDisconnect();
            Disconnect();

            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);
            return(true);
        }
示例#11
0
 private IEnumerable <IPAddress> GetIPAdressOfSut()
 {
     try
     {
         var result = Dns.GetHostAddresses(DetectionInfo.SUTName).Where(ipAddress => ipAddress.AddressFamily == AddressFamily.InterNetwork);
         return(result);
     }
     catch (Exception ex)
     {
         DetectorUtil.WriteLog(String.Format("Cannot get SUT IP addresses: {0}.", ex));
         return(new IPAddress[0]);
     }
 }
        private void CheckSupportedProtocols()
        {
            DetectorUtil.WriteLog("Check specified protocols support...");

            detectInfo.IsSupportRDPEFS = false;
            if (mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData != null && mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData.channelCount > 0)
            {
                List <CHANNEL_DEF> channels = mscConnectionInitialPDU.mcsCi.gccPdu.clientNetworkData.channelDefArray;
                foreach (CHANNEL_DEF channel in channels)
                {
                    if (channel.name.ToUpper().Contains("RDPDR"))
                    {
                        detectInfo.IsSupportRDPEFS = true;
                        break;
                    }
                }
            }

            // Create Dynamic Virtual Channels to detect protocols supported
            detectInfo.IsSupportRDPEDISP = (CreateEDYCChannel(RDPDetector.RdpedispChannelName));

            if (detectInfo.IsSupportRDPEGFX != null && detectInfo.IsSupportRDPEGFX.Value)
            {
                detectInfo.IsSupportRDPEGFX = CreateEDYCChannel(RDPDetector.RdpegfxChannelName);
            }

            detectInfo.IsSupportRDPEI = (CreateEDYCChannel(RDPDetector.rdpeiChannelName));

            detectInfo.IsSupportRDPEUSB = (CreateEDYCChannel(RDPDetector.RdpeusbChannelName));

            detectInfo.IsSupportRDPEVOR = (CreateEDYCChannel(RDPDetector.RdpegtChannelName) &&
                                           CreateEDYCChannel(RDPDetector.RdpevorControlChannelName) &&
                                           CreateEDYCChannel(RDPDetector.RdpevorDataChannelName));


            if (detectInfo.IsSupportStaticVirtualChannel != null && detectInfo.IsSupportStaticVirtualChannel.Value &&
                ((detectInfo.IsSupportTransportTypeUdpFECR != null && detectInfo.IsSupportTransportTypeUdpFECR.Value) ||
                 (detectInfo.IsSupportTransportTypeUdpFECL != null && detectInfo.IsSupportTransportTypeUdpFECL.Value)))
            {
                detectInfo.IsSupportRDPEMT  = true;
                detectInfo.IsSupportRDPEUDP = true;
            }
            else
            {
                detectInfo.IsSupportRDPEMT  = false;
                detectInfo.IsSupportRDPEUDP = false;
            }
            // Notify the UI for detecting protocol supported finished
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);
            DetectorUtil.WriteLog("Check specified protocols support finished.");
        }
        private bool PingSUT()
        {
            DetectorUtil.WriteLog("Ping Target SUT...");

            Ping        pingSender = new Ping();
            PingOptions options    = new PingOptions();

            // Use the default TtL value which is 128,
            // but change the fragmentation behavior.
            options.DontFragment = true;

            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "0123456789ABCDEF0123456789ABCDEF";

            byte[]           buffer  = Encoding.ASCII.GetBytes(data);
            int              timeout = 5000;
            bool             result  = false;
            List <PingReply> replys  = new List <PingReply>();

            try
            {
                for (int i = 0; i < 4; i++)
                {
                    replys.Add(pingSender.Send(config.ServerName, timeout, buffer, options));
                }
            }
            catch
            {
                DetectorUtil.WriteLog("Error", false, LogStyle.Error);

                //return false;
                throw;
            }
            foreach (var reply in replys)
            {
                result |= (reply.Status == IPStatus.Success);
            }
            if (result)
            {
                DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);
                return(true);
            }
            else
            {
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                DetectorUtil.WriteLog("Taget SUT don't respond.");
                return(false);
            }
        }
示例#14
0
        public static bool VerifyCertExist(string filename, string stepname)
        {
            string path = FilePath(filename);

            if (File.Exists(path))
            {
                DetectorUtil.WriteLog(stepname + " success", true, LogStyle.StepPassed);
                return(true);
            }
            else
            {
                DetectorUtil.WriteLog(stepname + " failed", false, LogStyle.StepFailed);
                return(false);
            }
        }
示例#15
0
        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 void SetRdpVersion(Configs config)
        {
            DetectorUtil.WriteLog("Detect RDP version...");

            config.Version = DetectorUtil.GetPropertyValue("RDP.Version");
            if (connectResponsePdu.mcsCrsp.gccPdu.serverCoreData != null)
            {
                TS_UD_SC_CORE_version_Values rdpVersion = connectResponsePdu.mcsCrsp.gccPdu.serverCoreData.version;
                if (rdpVersion == TS_UD_SC_CORE_version_Values.V1)
                {
                    config.Version = "4.0";
                }
                else if (rdpVersion == TS_UD_SC_CORE_version_Values.V2)
                {
                    config.Version = "8.1";
                }
                else if (rdpVersion == TS_UD_SC_CORE_version_Values.V3)
                {
                    config.Version = "10.0";
                }
                else if (rdpVersion == TS_UD_SC_CORE_version_Values.V4)
                {
                    config.Version = "10.1";
                }
                else if (rdpVersion == TS_UD_SC_CORE_version_Values.V5)
                {
                    config.Version = "10.2";
                }
                else if (rdpVersion == TS_UD_SC_CORE_version_Values.V6)
                {
                    config.Version = "10.3";
                }
                else if (rdpVersion == TS_UD_SC_CORE_version_Values.V7)
                {
                    config.Version = "10.4";
                }
                else if (rdpVersion == TS_UD_SC_CORE_version_Values.V8)
                {
                    config.Version = "10.5";
                }
                else if (rdpVersion == TS_UD_SC_CORE_version_Values.V9)
                {
                    config.Version = "10.6";
                }
            }
            DetectorUtil.WriteLog("Passed", false, LogStyle.StepPassed);
            DetectorUtil.WriteLog("Detect RDP version finished.");
        }
 private void TcpTcpConnection(string ipAddr, int port)
 {
     try
     {
         using (TcpClient c = new TcpClient())
         {
             c.Connect(ipAddr, port);
             DetectorUtil.WriteLog(string.Format("TCP connection to {0}:{1} successful.", ipAddr, port), false, LogStyle.StepPassed);
         }
     }
     catch (Exception e)
     {
         DetectorUtil.WriteLog(string.Format("TCP connection to {0}:{1} failed!", ipAddr, port), false, LogStyle.StepFailed);
         throw new Exception(string.Format("TCP connection to {0}:{1} failed: {2}", ipAddr, port, e.Message));
     }
 }
        public bool RunDetection()
        {
            // set config if properties changed
            config.FullDomainName      = properties["Full Qualified Domain Name"];
            config.DomainAdminUsername = properties["Domain Administrator Username"];
            config.DomainAdminPwd      = properties["Domain Administrator Password"];

            config.DomainNC     = "DC=" + config.FullDomainName.Replace(".", ",DC=");
            config.PartitionsNC = "CN=Partitions,CN=Configuration,DC=" + config.FullDomainName.Replace(".", ",DC=");

            config.PDCOperatingSystem = properties["Primary DC Operating System"];
            config.PDCComputerName    = properties["Primary DC Computer Name"];
            config.PDCIP = properties["Primary DC IP Address"];

            config.ClientOperatingSystem = properties["Client Computer Operating System"];
            config.ClientOSVersion       = properties["Client Operating System Version"];
            config.ClientComputerName    = properties["Client Computer Name"];
            config.ClientIP            = properties["Client IP Address"];
            config.ClientAdminUsername = properties["Client Administrator Username"];
            config.ClientAdminPwd      = properties["Client Administrator Password"];

            config.TriggerDisabled  = properties["Enable Offline Capture Testing"];
            config.LocalCapFilePath = properties["Capture File Path"];

            // run detection and set config if any mis-settings on IP according to the computer name resolve result
            IsMessageAnalyzerInstalled();

            if (bool.Parse(config.TriggerDisabled))
            {
                DetectorUtil.WriteLog("Offline Capture Testing Enabled, Ping Domain Skipped.", false, LogStyle.StepSkipped);
                DetectorUtil.WriteLog("Offline Capture Testing Enabled, Ping Primary Domain Controller Skipped.", false, LogStyle.StepSkipped);
                DetectorUtil.WriteLog("Offline Capture Testing Enabled, Tcp Connection Check Skipped.", false, LogStyle.StepSkipped);
                DetectorUtil.WriteLog("Offline Capture Testing Enabled, Ping Client Computer Skipped.", false, LogStyle.StepSkipped);
                VerifyCapturePath(config.LocalCapFilePath);
            }
            else
            {
                Pinghost(config.FullDomainName, "Ping Domain");
                config.PDCIP = Pinghost(config.PDCComputerName, "Ping Primary Domain Controller");
                TcpTcpConnection(config.PDCIP, 389);
                config.ClientIP = Pinghost(config.ClientComputerName, "Ping Client Computer");
                DetectorUtil.WriteLog(string.Format("Offline Capture Testing Disabled, Verify Capture Path Skipped."), false, LogStyle.StepSkipped);
            }

            return(true);
        }
示例#19
0
        /// <summary>
        /// Write a log message.
        /// </summary>
        /// <param name="level">Log level. Will throw exception when using LogLevel.Error</param>
        /// <param name="msg">Log message.</param>
        /// <param name="startNewLine">Start a new line before this message when to UI. True by default.</param>
        /// <param name="style">The style of the message</param>
        public void AddLog(LogLevel level, string msg, bool startNewLine = true, LogStyle style = LogStyle.Default)
        {
            switch (level)
            {
            case LogLevel.Information:
            case LogLevel.Warning:
                DetectorUtil.WriteLog(msg, startNewLine, style);
                break;

            case LogLevel.Error:
                AddLog(LogLevel.Information, msg);
                // PTM will handle the exception and pop up a dialog box to user.
                throw new Exception(msg);

            default:
                break;
            }
        }
        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 void VerifyCapturePath(string path)
 {
     try
     {
         if (Directory.Exists(path))
         {
             DetectorUtil.WriteLog(string.Format("Verify Offline Capture Path: {0} successful! The path exists.", path), false, LogStyle.StepPassed);
         }
         else
         {
             DetectorUtil.WriteLog(string.Format("Verify Offline Capture Path: {0} failed! The Path doesn't exist.", path), false, LogStyle.StepFailed);
         }
     }
     catch (Exception e)
     {
         DetectorUtil.WriteLog(string.Format("Verify Offline Capture Path: {0} failed!", path), false, LogStyle.StepFailed);
         throw new Exception(string.Format("Verify Offline Capture Path: {0} failed: {1}", path, e.Message));
     }
 }
示例#22
0
        public bool GetLocalAdapters()
        {
            DetectorUtil.WriteLog("Check the local adapters...");

            string[] error;

            var output = ExecutePowerShellCommand(@"..\etc\MS-SMBD\Scripts\GetLocalNetworkAdapters.ps1", out error);


            bool result = true;

            if (output.Length != 0)
            {
                FilterNetworkInterfaces(output);
                result = true;
            }
            else
            {
                DetectorUtil.WriteLog("Failed to detect any network interface!");
                result = false;
            }



            if (result)
            {
                DetectorUtil.WriteLog("Finished", false, LogStyle.StepPassed);
                return(true);
            }
            else
            {
                if (error != null)
                {
                    foreach (var item in error)
                    {
                        DetectorUtil.WriteLog(item.ToString());
                    }
                }
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                return(false);
            }
        }
示例#23
0
        /// <summary>
        /// Write a log message.
        /// </summary>
        /// <param name="msg">Log message.</param>
        /// <param name="level">Log level.</param>
        /// <param name="startNewLine">Start a new line before this message when to UI. True by default.</param>
        /// <param name="style">The style of the message</param>
        public void AddLog(LogLevel level, string msg, bool startNewLine = true, LogStyle style = LogStyle.Default)
        {
            switch (level)
            {
            case LogLevel.Information:
                DetectorUtil.WriteLog("[" + DateTime.Now + "]" + msg);
                break;

            case LogLevel.Warning:
                DetectorUtil.WriteLog(msg, startNewLine, style);
                break;

            case LogLevel.Error:
                AddLog(LogLevel.Information, msg);
                throw new Exception(msg);

            default:
                break;
            }
        }
示例#24
0
        public bool CheckSMBDCapability(out RdmaAdapterInfo rdmaAdapterInfo, out bool rdmaChannelV1Supported, out bool rdmaChannelV1InvalidateSupported)
        {
            rdmaAdapterInfo                  = null;
            rdmaChannelV1Supported           = false;
            rdmaChannelV1InvalidateSupported = false;

            if (DetectionInfo.SUTRdmaNICIPAddress == null || DetectionInfo.DriverRdmaNICIPAddress == null)
            {
                DetectorUtil.WriteLog("Check the supported SMBD capabilities of SUT skipped since not available.", true, LogStyle.StepSkipped);
                return(false);
            }

            DetectorUtil.WriteLog("Check the supported SMBD capabilities of SUT...");

            bool result = CheckSMBDNegotiate(out rdmaAdapterInfo);

            if (result)
            {
                if (CheckSMBDReadWriteRDMAV1())
                {
                    result = true;
                    rdmaChannelV1Supported = true;
                    if (CheckSMBDReadWriteRDMAV1Invalidate())
                    {
                        rdmaChannelV1InvalidateSupported = true;
                    }
                }
            }


            if (result)
            {
                DetectorUtil.WriteLog("Finished", false, LogStyle.StepPassed);
                return(true);
            }
            else
            {
                DetectorUtil.WriteLog("Failed", false, LogStyle.StepFailed);
                return(false);
            }
        }
示例#25
0
 public static bool VerifyDomainAccount(string domain, string account, string password, string stepname)
 {
     try
     {
         DetectorUtil.WriteLog(
             string.Format("{0}: {1}\n{2} Password: {3}", stepname, domain, account, password),
             true, LogStyle.Default);
         Utility.LdapBind(domain, new System.Net.NetworkCredential(account, password, domain));
         DetectorUtil.WriteLog(
             string.Format("{0}: {1}\n{2} is verified.", stepname, domain, account),
             true, LogStyle.StepPassed);
     }
     catch (Exception e)
     {
         DetectorUtil.WriteLog(
             string.Format("{0} failed: {1}", stepname, e.Message),
             false, LogStyle.StepFailed);
         return(false);
     }
     return(true);
 }
示例#26
0
 public bool VerifyMachineAccount(string domain, string account, string password)
 {
     try
     {
         DetectorUtil.WriteLog(
             string.Format("Verify machine account: {0}\\{1}$ Password: {2}", domain, account, password),
             true, LogStyle.Default);
         Utility.LdapBind(domain, new System.Net.NetworkCredential(account + "$", password, domain));
         DetectorUtil.WriteLog(
             string.Format("Machine account: {0}\\{1} is verified.", domain, account),
             true, LogStyle.Default);
     }
     catch (Exception e)
     {
         DetectorUtil.WriteLog(
             string.Format("Error. Message: {0}", e.Message),
             true, LogStyle.Default);
         return(false);
     }
     return(true);
 }
示例#27
0
        /// <summary>
        /// Run auto detection properly.
        /// </summary>
        /// <returns>Return true if the function succeeded.</returns>
        public bool RunDetection()
        {
            try
            {
                DetectorUtil.WriteLog("Detect Client HostName...");

                // set config if properties changed
                config.ServerName   = properties[RDPValueDetector.ServerName];
                config.ServerDomain = properties[RDPValueDetector.ServerDomain];
                if (config.ServerDomain != null && config.ServerDomain.Length == 0)
                {
                    config.ServerDomain = config.ServerName;
                }
                config.ServerPort         = properties[RDPValueDetector.ServerPort];
                config.ServerUserName     = properties[RDPValueDetector.ServerUserName];
                config.ServerUserPassword = properties[RDPValueDetector.ServerUserPassword];
                config.ClientName         = Dns.GetHostName();

                DetectorUtil.WriteLog("Finished!", false, LogStyle.StepPassed);

                if (!PingSUT())
                {
                    return(false);
                }

                using (var detector = new RDPDetector(detectionInfo))
                {
                    if (!detector.DetectRDPFeature(config))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                DetectorUtil.WriteLog(String.Format("RunDetection() threw exception: {0}", ex));
                return(false);
            }
        }
示例#28
0
        private bool DetectSUTIPAddress()
        {
            DetectorUtil.WriteLog("===== Detect Target SUT IP Address=====", true, LogStyle.Default);

            try
            {
                IPAddress address;
                //Detect SUT IP address by SUT name
                //If SUT name is an ip address, skip to resolve, use the ip address directly
                if (IPAddress.TryParse(detectionInfo.SUTName, out address))
                {
                    DetectorUtil.WriteLog("Finished", true, LogStyle.StepPassed);
                    return(true);
                }
                else //DNS resolve the SUT IP address by SUT name
                {
                    IPAddress[] addList = Dns.GetHostAddresses(detectionInfo.SUTName);

                    if (null == addList)
                    {
                        DetectorUtil.WriteLog(string.Format("The SUT name {0} cannot be resolved.", detectionInfo.SUTName), true, LogStyle.Error);
                        DetectorUtil.WriteLog("Failed", true, LogStyle.StepFailed);
                        return(false);
                    }
                    else
                    {
                        DetectorUtil.WriteLog(string.Format("The SUT name {0} can be resolved as :", addList.ToString()), true, LogStyle.Default);
                        DetectorUtil.WriteLog("Finished", true, LogStyle.StepPassed);
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                DetectorUtil.WriteLog(ex.Message, true, LogStyle.StepFailed);
                DetectorUtil.WriteLog("Failed", true, LogStyle.StepFailed);
                return(false);
            }
        }
        private string Pinghost(string hostname, string stepname)
        {
            Ping ping = new Ping();

            IPAddress[] ipAddr        = null;
            uint        actualIpIndex = 0;

            try
            {
                ipAddr = Dns.GetHostAddresses(hostname);
                foreach (var ip in ipAddr)
                {
                    // Break if current IP is not loopback addr (127.0.0.1 or ::1)
                    // Otherwise increment actualIpIndex
                    if (!IPAddress.IsLoopback(ip))
                    {
                        break;
                    }
                    actualIpIndex += 1;
                }
            }
            catch (SocketException e)
            {
                DetectorUtil.WriteLog(stepname + " failed!", false, LogStyle.StepFailed);
                throw new Exception(string.Format("Cannot resolve host name {0}.\r\n{1}", hostname, e.Message));
            }
            try
            {
                ping.Send(ipAddr[actualIpIndex]);
            }
            catch (PingException e)
            {
                DetectorUtil.WriteLog(stepname + " failed!", false, LogStyle.StepFailed);
                throw new Exception(string.Format("Ping {0} error.\r\n{1}", hostname, e.Message));
            }

            DetectorUtil.WriteLog(stepname + " successful.", false, LogStyle.StepPassed);
            return(ipAddr[actualIpIndex].ToString());
        }
示例#30
0
        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);
            }
        }