public FSDetector (DetectLogger logger, string targetSUT, AccountCredential accountCredential, SecurityPackageType securityPackageType) { sutName = targetSUT; Credential = accountCredential; SecurityPackageType = securityPackageType; logWriter = logger; logWriter.AddLog(DetectLogLevel.Information, string.Format("SutName: {0}", sutName)); logWriter.AddLog(DetectLogLevel.Information, string.Format("DomainName: {0}", Credential.DomainName)); logWriter.AddLog(DetectLogLevel.Information, string.Format("UserName: {0}", Credential.AccountName)); logWriter.AddLog(DetectLogLevel.Information, string.Format("UserPassword: {0}", Credential.Password)); logWriter.AddLog(DetectLogLevel.Information, string.Format("SecurityPackageType: {0}", SecurityPackageType.ToString())); logWriter.AddLineToLog(DetectLogLevel.Information); }
public static bool DetectClient(DomainInfo domain, ComputerInfo client, DetectLogger logWriter) { logWriter.AddLog(DetectLogLevel.Warning, string.Format("===== Detect Client/Driver in Domain {0} =====", domain.Name)); string ip = client.IPv4 != null ? client.IPv4 : client.IPv6; try { string computerName = Dns.GetHostEntry(ip).HostName; computerName = computerName.Split('.')[0]; } catch { logWriter.AddLog(DetectLogLevel.Error, "Failed", false, LogStyle.StepFailed); logWriter.AddLineToLog(DetectLogLevel.Information); return(false); } logWriter.AddLog(DetectLogLevel.Warning, "Success", false, LogStyle.StepPassed); logWriter.AddLineToLog(DetectLogLevel.Information); return(true); }
public static bool DetectDC(DomainInfo domain, Server dc, DetectLogger logWriter) { logWriter.AddLog(DetectLogLevel.Warning, string.Format("===== Detect DC in Domain {0} =====", domain.Name)); DirectoryContext context = new DirectoryContext(DirectoryContextType.Domain, domain.Name, domain.Admin, domain.AdminPassword); string hostName = DomainController.FindOne(context).Name; var hostEntry = Dns.GetHostEntry(hostName); try { string computerName = hostEntry.HostName; computerName = computerName.Split('.')[0]; dc.ComputerName = computerName; dc.FQDN = ServerHelper.GetDCAttribute(computerName, "dNSHostName", domain.Name, domain.Admin, domain.AdminPassword); dc.IsWindows = ServerHelper.FetchPlatformInfo(computerName, logWriter); } catch { logWriter.AddLog(DetectLogLevel.Warning, "Failed", false, LogStyle.StepFailed); logWriter.AddLineToLog(DetectLogLevel.Information); return(false); } if (dc.FQDN == null) { logWriter.AddLog(DetectLogLevel.Warning, "Failed", false, LogStyle.StepFailed); logWriter.AddLineToLog(DetectLogLevel.Information); return(false); } try { dc.NetBIOS = ServerHelper.GetDCAttribute(dc.ComputerName, "sAMAccountName", domain.Name, domain.Admin, domain.AdminPassword);//DC01$: NetBIOS name dc.DefaultServiceName = "krbtgt/" + domain.Name.ToUpper(); dc.ServiceSalt = domain.Name.ToUpper() + "host" + dc.FQDN.ToLower(); } catch { logWriter.AddLog(DetectLogLevel.Warning, "Failed", false, LogStyle.StepFailed); logWriter.AddLineToLog(DetectLogLevel.Information); return(false); } try { domain.FunctionalLevel = ServerHelper.GetDomainFunctionalLevel(domain.Name, domain.Admin, domain.AdminPassword); } catch { logWriter.AddLog(DetectLogLevel.Warning, "Failed", false, LogStyle.StepFailed); logWriter.AddLineToLog(DetectLogLevel.Information); return(false); } logWriter.AddLog(DetectLogLevel.Warning, "Success", false, LogStyle.StepPassed); logWriter.AddLineToLog(DetectLogLevel.Information); return(true); }
public static bool FetchPlatformInfo(string computerName, DetectLogger logWriter) { bool isWindows = true; try { ManagementObjectCollection resultCollection = QueryWmiObject(computerName, "SELECT * FROM Win32_OperatingSystem"); foreach (ManagementObject result in resultCollection) { isWindows = (ConvertPlatform(result["Caption"].ToString()) != Platform.NonWindows); logWriter.AddLog(DetectLogLevel.Information, "Platform: " + ConvertPlatform(result["Caption"].ToString())); break; } } catch { } return(isWindows); }
/// <summary> /// Runs property autodetection. /// </summary> /// <returns>Return true if the function is succeeded.</returns> public bool RunDetection(DetectContext context) { logWriter.ApplyDetectContext(context); try { if (context.Token.IsCancellationRequested) { return(false); } if (!DetectSUTIPAddress()) { return(false); } if (context.Token.IsCancellationRequested) { return(false); } using (var detector = new RDPDetector(detectionInfo, logWriter)) { if (!detector.DetectRDPFeature()) { return(false); } } return(true); } catch (Exception ex) { logWriter.AddLog(DetectLogLevel.Warning, "Failed", false, LogStyle.StepFailed); logWriter.AddLog(DetectLogLevel.Error, ex.Message); 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 { logWriter.AddLog(DetectLogLevel.Information, "Establish RDP connection with SUT..."); StartRDPListening(detectInfo.RDPServerPort); triggerClientRDPConnect(detectInfo.TriggerMethod); EstablishRDPConnection(); // Set RDP Version SetRdpVersion(); CheckSupportedFeatures(); CheckSupportedProtocols(); } catch (Exception e) { logWriter.AddLog(DetectLogLevel.Information, "Exception occured when establishing RDP connection: " + e.Message); logWriter.AddLog(DetectLogLevel.Information, "" + e.StackTrace); if (e.InnerException != null) { logWriter.AddLog(DetectLogLevel.Information, "**" + e.InnerException.Message); logWriter.AddLog(DetectLogLevel.Information, "**" + e.InnerException.StackTrace); } logWriter.AddLog(DetectLogLevel.Warning, "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. logWriter.AddLog(DetectLogLevel.Warning, "Finished", false, LogStyle.StepPassed); return(true); }
/// <summary> /// Run auto detection properly. /// </summary> /// <returns>Return true if the function succeeded.</returns> public bool RunDetection(DetectContext context) { logWriter.ApplyDetectContext(context); try { if (context.Token.IsCancellationRequested) { return(false); } logWriter.AddLog(DetectLogLevel.Information, "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(); logWriter.AddLog(DetectLogLevel.Warning, "Finished", false, LogStyle.StepPassed); if (context.Token.IsCancellationRequested) { return(false); } if (!DetectSUTIPAddress()) { return(false); } using (var detector = new RDPDetector(detectionInfo, logWriter)) { if (!detector.DetectRDPFeature(config)) { return(false); } } return(true); } catch (Exception ex) { logWriter.AddLog(DetectLogLevel.Warning, "Failed", false, LogStyle.StepFailed); logWriter.AddLog(DetectLogLevel.Information, String.Format("RunDetection() threw exception: {0}", ex)); logWriter.AddLog(DetectLogLevel.Information, ex.StackTrace); return(false); } }
public NetworkInfo DetectSUTConnection() { NetworkInfo networkInfo = new NetworkInfo(); IPAddress address; //Detect SUT IP address by SUT name //If SUT name is an ip address, skip to resolve, use the ip address directly try { if (IPAddress.TryParse(sutName, out address)) { networkInfo.SUTIpList = new List <IPAddress>(); networkInfo.SUTIpList.Add(address); } else //DNS resolve the SUT IP address by SUT name { IPAddress[] addList = Dns.GetHostAddresses(sutName); if (null == addList) { logWriter.AddLog(DetectLogLevel.Error, string.Format("The SUT name {0} is incorrect.", SUTName)); } networkInfo.SUTIpList = new List <IPAddress>(); logWriter.AddLog(DetectLogLevel.Information, "IP addresses returned from Dns.GetHostAddresses:"); foreach (var item in addList) { logWriter.AddLog(DetectLogLevel.Information, item.ToString()); if (item.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { networkInfo.SUTIpList.Add(item); } } if (networkInfo.SUTIpList.Count == 0) { logWriter.AddLog(DetectLogLevel.Error, string.Format("No available IP address resolved for target SUT {0}.", SUTName)); } } DetermineSUTIPAddress(networkInfo.SUTIpList.ToArray()); return(networkInfo); } catch { logWriter.AddLog(DetectLogLevel.Error, string.Format("Detect Target SUT connection failed with SUT name: {0}.", SUTName)); return(null); } }
/// <summary> /// Establish a RDP connection to detect RDP feature /// </summary> /// <returns>Return true if detection succeeded.</returns> public bool DetectRDPFeature(Configs config) { try { logWriter.AddLog(DetectLogLevel.Information, "Establish RDP connection with SUT..."); Initialize(config); ConnectRDPServer(); try { bool status = EstablishRDPConnection( config, requestedProtocol, SVCNames, CompressionType.PACKET_COMPR_TYPE_NONE, false, true, false, false, true, true, false); if (!status) { logWriter.AddLog(DetectLogLevel.Warning, "Failed", false, LogStyle.StepFailed); return(false); } } catch (Exception e) { logWriter.AddLog(DetectLogLevel.Information, string.Format("ErrorMessage:{0}{1}StackTrace:{2}", e.Message, Environment.NewLine, e.StackTrace)); logWriter.AddLog(DetectLogLevel.Warning, "Failed", false, LogStyle.StepFailed); return(false); } logWriter.AddLog(DetectLogLevel.Warning, "Finished", false, LogStyle.StepPassed); CheckSupportedFeatures(); CheckSupportedProtocols(); config.RDPEDYCSupported = detectInfo.IsSupportRDPEDYC.ToString(); config.RDPELESupported = detectInfo.IsSupportRDPELE.ToString(); SetRdpVersion(config); } catch (Exception e) { logWriter.AddLog(DetectLogLevel.Information, string.Format("Exception occured when establishing RDP connection.{1} ErrorMessage:{0}{1}StackTrace:{2}", e.Message, Environment.NewLine, e.StackTrace)); if (e.InnerException != null) { logWriter.AddLog(DetectLogLevel.Information, string.Format("ErrorMessage:{0}{1}StackTrace:{2}", e.InnerException.Message, Environment.NewLine, e.InnerException.StackTrace)); } logWriter.AddLog(DetectLogLevel.Warning, "Failed", false, LogStyle.StepFailed); return(false); } // Disconnect ClientInitiatedDisconnect(); Disconnect(); logWriter.AddLog(DetectLogLevel.Warning, "Finished", true, LogStyle.StepPassed); return(true); }