Пример #1
0
        public void PerformSMBTest_Port445_Exists()
        {
            TcpListener tcpListener = SMBServiceFakeHelper.CreateSMBService(SMBDirectHostPort);

            try
            {
                SMBServiceFakeHelper.PerformSingleSMBServiceListen(tcpListener);
                SpoofDetectionResult result = SMBTester.PerformSMBTest(IPAddress.Parse(RemoteServerAddress), LocalServerAddress);
                Assert.IsTrue(result.Detected);
                Assert.AreEqual(ConfidenceLevel.Medium, result.Confidence);
                Assert.AreEqual(Protocol.SMB, result.Protocol);
                Assert.IsNull(result.ErrorMessage);
                Assert.AreEqual("Open", result.Response);
                Assert.AreEqual(RemoteServerAddress, result.Endpoint.Address.ToString());
                Assert.AreEqual(SMBDirectHostPort, result.Endpoint.Port);
            }
            catch (SocketException ex)
            {
                //If there is already a service, we can't run this test. Just pass the test.
                if (ex.Message == "Only one usage of each socket address (protocol/network address/port) is normally permitted")
                {
                    return;
                }
                throw;
            }
            finally
            {
                tcpListener.Stop();
            }
        }
Пример #2
0
        public void PerformSMBTest_NoService()
        {
            //This test is pointless if we're already running an SMB server, so establish that first
            //There's obvious race conditions here, but you shouldn't really be messing with an SMB service while in middle of running SMB tests...
            TcpListener tcpListener = SMBServiceFakeHelper.CreateSMBService(NBOverTCPPort);

            try
            {
                SMBServiceFakeHelper.PerformSingleSMBServiceListen(tcpListener);
            }
            catch (SocketException ex)
            {
                if (ex.Message == "Only one usage of each socket address (protocol/network address/port) is normally permitted")
                {
                    return;
                }
                throw;
            }
            finally
            {
                tcpListener.Stop();
            }
            tcpListener = SMBServiceFakeHelper.CreateSMBService(SMBDirectHostPort);
            try
            {
                SMBServiceFakeHelper.PerformSingleSMBServiceListen(tcpListener);
            }
            catch (SocketException ex)
            {
                if (ex.Message == "Only one usage of each socket address (protocol/network address/port) is normally permitted")
                {
                    return;
                }
                throw;
            }
            finally
            {
                tcpListener.Stop();
            }


            //Now attempt to connect to service that doesn't exist
            SpoofDetectionResult result = SMBTester.PerformSMBTest(IPAddress.Parse(RemoteServerAddress), LocalServerAddress);

            Assert.IsFalse(result.Detected);
            Assert.AreEqual(ConfidenceLevel.FalsePositive, result.Confidence);
            Assert.AreEqual(Protocol.SMB, result.Protocol);
            Assert.AreEqual(String.Format("No connection could be made because the target machine actively refused it {0}:{1}", RemoteServerAddress, SMBDirectHostPort), result.ErrorMessage);
            Assert.IsNull(result.Response);
            Assert.AreEqual(RemoteServerAddress, result.Endpoint.Address.ToString());
            Assert.AreEqual(SMBDirectHostPort, result.Endpoint.Port);
        }