Ejemplo n.º 1
0
        private void ListAttributes(SearchResultCollection results, string[] attrs)
        {
            Dictionary <string, Object>[] attributedResults = new Dictionary <string, object> [results.Count];
            for (int i = 0; i < results.Count; i++)
            {
                attributedResults[i] = new Dictionary <string, object>();
                DirectoryEntry userEntry = results[i].GetDirectoryEntry();
                foreach (string key in attrs)
                {
                    attributedResults[i].Add(key, userEntry.Properties[key].Value);
                }
            }

            if (!this.m_json)
            {
                int formatLen = OutputFormatting.GetFormatLenSpecifier(attributedResults[0].Keys.ToArray <string>());
                foreach (Dictionary <string, Object> attributedResult in attributedResults)
                {
                    foreach (KeyValuePair <string, object> kvp in attributedResult)
                    {
                        OutputFormatting.PrintSuccess(String.Format("{0,-" + formatLen + "} : {1}", kvp.Key, kvp.Value.ToString()), 1);
                    }
                }
            }
            else
            {
                OutputFormatting.PrintJson(attributedResults);
            }
        }
Ejemplo n.º 2
0
        public SearchResultCollection GetCustomSearch(string query)
        {
            SearchResultCollection results = this.CustomSearch(query);

            if (results == null)
            {
                OutputFormatting.PrintError("Unable to carry out custom search");
                throw new Exception("Custom search came back null");
            }
            return(results);
        }
Ejemplo n.º 3
0
        public SearchResultCollection GetAllSpns()
        {
            SearchResultCollection results = this.CustomSearch("(servicePrincipalName=*)");

            if (results == null)
            {
                OutputFormatting.PrintError("Unable to obtain any Service Principal Names");
                throw new Exception("Custom search came back null");
            }
            return(results);
        }
Ejemplo n.º 4
0
        public SearchResultCollection GetAllGroups()
        {
            SearchResultCollection results = this.CustomSearch("(objectCategory=group)");

            if (results == null)
            {
                OutputFormatting.PrintError("Unable to obtain any groups");
                throw new Exception("Custom search came back null");
            }
            return(results);
        }
Ejemplo n.º 5
0
        public SearchResultCollection GetAllUsers()
        {
            SearchResultCollection results = this.CustomSearch("(&(objectClass=user)(objectCategory=person))");

            if (results == null)
            {
                OutputFormatting.PrintError("Unable to obtain any users");
                throw new Exception("Custom search came back null");
            }
            return(results);
        }
Ejemplo n.º 6
0
        public SearchResultCollection GetAllDomainAdmins()
        {
            string filter = String.Format("(&(objectCategory=user)(memberOf=CN=Domain Admins,CN=Users,{0}))", this.m_domainPath);
            SearchResultCollection results = this.CustomSearch(filter);

            if (results == null)
            {
                OutputFormatting.PrintError("Unable to get domain admins");
                throw new Exception("Custom search came back null");
            }
            return(results);
        }
Ejemplo n.º 7
0
 private void ListAll(SearchResultCollection results)
 {
     if (this.m_json)
     {
         OutputFormatting.PrintJson(results);
     }
     else
     {
         foreach (SearchResult result in results)
         {
             DirectoryEntry userEntry = result.GetDirectoryEntry();
             OutputFormatting.PrintADProperties(userEntry);
         }
     }
 }
Ejemplo n.º 8
0
        static void Entry(Options options)
        {
            ADWrapper AD;
            SearchResultCollection srCollection;
            ConsoleFileOutput      cf = null;

            if (!options.SupressBanner)
            {
                PrintBanner();
            }

            if (options.Output != null)
            {
                cf = new ConsoleFileOutput(options.Output, Console.Out);
                Console.SetOut(cf);
            }

            if (options.Insecure)
            {
                options.Port = "389";
            }

            if (options.Hostname == null && options.Domain != null)
            {
                //No IP but domains set
                AD = new ADWrapper(options.Domain, options.Username, options.Password, options.Insecure, options.JsonOut);
            }
            else if (options.Hostname != null && options.Domain != null)
            {
                //This requires the domain so it can be converted into a valid LDAP URI
                AD = new ADWrapper(options.Domain, options.Hostname, options.Port, options.Username, options.Password, options.Insecure, options.JsonOut);
            }
            else
            {
                //When no domain is supplied it has to be done locally even if the ip is set otherwise the bind won't work
                OutputFormatting.PrintVerbose("No domain supplied. This PC's domain will be used instead");
                AD = new ADWrapper(options.JsonOut);
            }

            if (options.Attribtues != null && !options.Full)
            {
                AD.attributesToReturn = options.Attribtues.Split(',');
            }

            OutputFormatting.PrintVerbose(AD.LDAP_URI);

            if (options.Groups)
            {
                srCollection = AD.GetAllGroups();
                OutputFormatting.PrintVerbose("ALL GROUPS:");
                OutputFormatting.PrintVerbose(String.Format("TOTAL NUMBER OF GROUPS: {0}", srCollection.Count));
                AD.ListAllGroups(srCollection, options.Full);
            }

            if (options.Users)
            {
                srCollection = AD.GetAllUsers();
                OutputFormatting.PrintVerbose("ALL USERS: ");
                OutputFormatting.PrintVerbose(String.Format("TOTAL NUMBER OF USERS: {0}", srCollection.Count));
                AD.ListAllUsers(srCollection, options.Full);
            }

            if (options.Computers)
            {
                srCollection = AD.GetAllComputers();
                OutputFormatting.PrintVerbose("ALL COMPUTERS: ");
                OutputFormatting.PrintVerbose(String.Format("TOTAL NUMBER OF COMPUTERS: {0}", srCollection.Count));
                AD.ListAllComputers(srCollection, options.Full);
            }

            if (options.Search != null)
            {
                srCollection = AD.GetCustomSearch(options.Search);
                OutputFormatting.PrintVerbose("CUSTOM SEARCH: ");
                OutputFormatting.PrintVerbose(String.Format("TOTAL NUMBER OF SEARCH RESULTS: {0}", srCollection.Count));
                AD.ListCustomSearch(srCollection, options.Full);
            }

            if (options.Spns)
            {
                srCollection = AD.GetAllSpns();
                OutputFormatting.PrintVerbose("ALL SPNS: ");
                OutputFormatting.PrintVerbose(String.Format("TOTAL NUMBER OF SPNS: {0}", srCollection.Count));
                AD.ListAllSpns(srCollection, options.Full);
            }

            if (options.DomainAdmins)
            {
                srCollection = AD.GetAllDomainAdmins();
                OutputFormatting.PrintVerbose("ALL DOMAIN ADMINS: ");
                OutputFormatting.PrintVerbose(String.Format("TOTAL NUMBER OF DOMAIN ADMINS: {0}", srCollection.Count));
                AD.ListAllDomainAdmins(srCollection, options.Full);
            }

            if (options.Output != null)
            {
                //Close out file handle
                cf.Close();
            }
        }