public BuildSearchString() { ldapInfo = Searcher.LdapInfo; CreateLDAPSearchString(); CreateSMBSearchString(); }
public void Init() { _logger.Debug($"Connecting to {DomainController}"); var RootDSE = GetDirectoryEntry("rootDSE"); //Test Connection try { RootDSE.RefreshCache(); } catch (Exception e) { _logger.Error($"Unable to connect to LDAP://{DomainController}:{Port}/rootDSE"); _logger.Trace(e.Message); Environment.Exit(1); } _logger.Debug("Connected. Enumerating root DSE"); string RootDN = RootDSE.Properties["defaultNamingContext"].Value.ToString(); string ForestDN = RootDSE.Properties["rootDomainNamingContext"].Value.ToString(); DomainName = RootDN.Replace("DC=", "").Replace(",", "."); string ForestName = ForestDN.Replace("DC=", "").Replace(",", "."); string domainFunc = (Enum.Parse(typeof(Functionality), RootDSE.Properties["domainFunctionality"].Value.ToString())).ToString(); string forestFunc = (Enum.Parse(typeof(Functionality), RootDSE.Properties["forestFunctionality"].Value.ToString())).ToString(); string dcFunc = (Enum.Parse(typeof(Functionality), RootDSE.Properties["domainControllerFunctionality"].Value.ToString())).ToString(); //BasicLDAPInfo.Add("RootDN", new List<string> { RootDN }); //BasicLDAPInfo.Add("ForestDN", new List<string> { ForestDN }); BasicLDAPInfo.Add("DomainName", new List <string> { DomainName.ToUpper() }); BasicLDAPInfo.Add("ForestName", new List <string> { ForestName.ToUpper() }); BasicLDAPInfo.Add("DomainFunctionality", new List <string> { domainFunc }); BasicLDAPInfo.Add("ForestFunctionality", new List <string> { forestFunc }); BasicLDAPInfo.Add("DomainControllerFunctionality", new List <string> { dcFunc }); var domainEntry = GetResultEntry(new LDAPSearchString { DN = RootDN, Filter = "name=*", Scope = SearchScope.Base }); DomainSID = Helper.ConvertByteArrayToSID((byte[])domainEntry.Attributes["objectsid"][0]); LdapInfo = new LDAPInfo { RootDN = RootDN, ForestDN = ForestDN, ConfigDN = RootDSE.Properties["configurationNamingContext"].Value.ToString(), SchemaDN = RootDSE.Properties["schemaNamingContext"].Value.ToString(), DomainName = DomainName, ForestName = ForestName, TargetSearchBase = TargetSearchBase, DomainController = DomainController, DomainSID = DomainSID }; string[] attributeNames = new string[] { "serverName", "isSynchronized", "isGlobalCatalogReady", "dnsHostName", "ldapServiceName", "supportedLDAPVersion", "supportedSASLMechanisms", "namingContexts", "dsServiceName" }; foreach (string name in attributeNames) { List <string> valueCollection = new List <string>(); foreach (string value in RootDSE.Properties[name]) { valueCollection.Add(value); } BasicLDAPInfo.Add(name, valueCollection); } _logger.Debug("Enumerated"); RootDSE.Dispose(); }