示例#1
0
        public static bool SupportSMB2And3(string server, out SMBSecurityModeEnum securityMode)
        {
            bool tempResult = false;
            bool result     = false;

            securityMode = SMBSecurityModeEnum.NotTested;
            SMBSecurityModeEnum smbv2temp;

            foreach (int dialect in new int[] { 0x0202, 0x0210, 0x0300, 0x0302, 0x0311 })
            {
                try
                {
                    tempResult = Smb2Protocol.DoesServerSupportDialectWithSmbV2(server, dialect, out smbv2temp);
                    if (tempResult)
                    {
                        result       = true;
                        securityMode = CombineSecurityMode(securityMode, smbv2temp);
                    }
                }
                catch (SmbPortClosedException)
                {
                    break;
                }
                catch (Exception)
                {
                }
            }
            return(result);
        }
示例#2
0
        override protected string GetCsvData(string computer)
        {
            bool isPortOpened = true;
            bool SMBv1        = false;
            bool SMBv2_0x0202 = false;
            bool SMBv2_0x0210 = false;
            bool SMBv2_0x0300 = false;
            bool SMBv2_0x0302 = false;
            bool SMBv2_0x0311 = false;
            SMBSecurityModeEnum smbv1secmode = SMBSecurityModeEnum.NotTested;
            SMBSecurityModeEnum smbv2secmode = SMBSecurityModeEnum.NotTested;
            SMBSecurityModeEnum smbv2temp;

            try
            {
                try
                {
                    SMBv1 = Smb1Protocol.DoesServerSupportDialect(computer, "NT LM 0.12", out smbv1secmode);
                }
                catch (Smb1NotSupportedException)
                {
                }
                try
                {
                    SMBv2_0x0202 = Smb2Protocol.DoesServerSupportDialectWithSmbV2(computer, 0x0202, out smbv2secmode);
                    SMBv2_0x0210 = Smb2Protocol.DoesServerSupportDialectWithSmbV2(computer, 0x0210, out smbv2temp);
                    smbv2secmode = CombineSecurityMode(smbv2secmode, smbv2temp);
                    SMBv2_0x0300 = Smb2Protocol.DoesServerSupportDialectWithSmbV2(computer, 0x0300, out smbv2temp);
                    smbv2secmode = CombineSecurityMode(smbv2secmode, smbv2temp);
                    SMBv2_0x0302 = Smb2Protocol.DoesServerSupportDialectWithSmbV2(computer, 0x0302, out smbv2temp);
                    smbv2secmode = CombineSecurityMode(smbv2secmode, smbv2temp);
                    SMBv2_0x0311 = Smb2Protocol.DoesServerSupportDialectWithSmbV2(computer, 0x0311, out smbv2temp);
                    smbv2secmode = CombineSecurityMode(smbv2secmode, smbv2temp);
                }
                catch (Smb2NotSupportedException)
                {
                }
            }
            catch (SmbPortClosedException)
            {
                isPortOpened = false;
            }
            return(computer + "\t" + (isPortOpened ? "Yes" : "No") + "\t" + (SMBv1 ? "Yes" : "No")
                   + "\t" + ((smbv1secmode & SMBSecurityModeEnum.SmbSigningRequired) != 0 ? "Yes" : "No")
                   + "\t" + (SMBv2_0x0202 ? "Yes" : "No")
                   + "\t" + (SMBv2_0x0210 ? "Yes" : "No")
                   + "\t" + (SMBv2_0x0300 ? "Yes" : "No")
                   + "\t" + (SMBv2_0x0302 ? "Yes" : "No")
                   + "\t" + (SMBv2_0x0311 ? "Yes" : "No")
                   + "\t" + ((smbv2secmode & SMBSecurityModeEnum.SmbSigningRequired) != 0 ? "Yes" : "No"));
        }
示例#3
0
        public static bool DoesServerSupportDialectWithSmbV2(string server, int dialect, out SMBSecurityModeEnum securityMode)
        {
            Trace.WriteLine("Checking " + server + " for SMBV2 dialect 0x" + dialect.ToString("X2"));
            securityMode = SMBSecurityModeEnum.NotTested;
            TcpClient client = new TcpClient();

            client.ReceiveTimeout = 500;
            client.SendTimeout    = 500;
            try
            {
                client.Connect(server, 445);
            }
            catch (Exception)
            {
                throw new SmbPortClosedException(server);
            }
            try
            {
                NetworkStream stream = client.GetStream();

                var smb2 = new Smb2Protocol(stream, server);

                var negotiateresponse = smb2.SendNegotiateRequest(dialect);
                if ((negotiateresponse.SecurityMode & 1) != 0)
                {
                    securityMode = SMBSecurityModeEnum.SmbSigningEnabled;

                    if ((negotiateresponse.SecurityMode & 2) != 0)
                    {
                        securityMode |= SMBSecurityModeEnum.SmbSigningRequired;
                    }
                }
                else
                {
                    securityMode = SMBSecurityModeEnum.None;
                }

                Trace.WriteLine("Checking " + server + " for SMBV2 dialect 0x" + dialect.ToString("X2") + " = Supported");
                return(true);
            }
            catch (Exception)
            {
                throw new Smb2NotSupportedException(server);
            }
        }
示例#4
0
        public static List <Smb2Protocol.NetworkInfo> GetFCTL_QUERY_NETWORK_INFO(string server, NetworkCredential credential = null)
        {
            Trace.WriteLine("Checking " + server + " for GetFCTL_QUERY_NETWORK_INFO");
            TcpClient client = new TcpClient();

            client.ReceiveTimeout = 500;
            client.SendTimeout    = 500;
            try
            {
                client.Connect(server, 445);
            }
            catch (Exception)
            {
                Trace.WriteLine("Error with " + server + "(port closed)");
                return(null);
            }
            try
            {
                NetworkStream stream = client.GetStream();
                var           smb2   = new Smb2Protocol(stream, server);

                smb2.SendNegotiateRequest(0x0302);

                smb2.SendSessionSetupRequests(credential);

                smb2.SendTreeConnect("\\\\" + server + "\\IPC$");

                var o = smb2.GetNetworkInterfaceInfo();

                client.Close();

                return(o);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error with " + server + "(" + ex.Message + ")");
                return(null);
            }
        }