private void TimerRunSync(Object state)
        {
            List <DBUser> users = DatabaseHandler.GetSyncs();

            if (!ADHandler.ReloadGroup())
            {
                Logger.Send("Target group could not be reloaded during sync check. was the group deleted?", Logger.LogLevel.ERROR, 17);
            }

            O365Client client = new O365Client();

            try
            {
                client.GetAccessToken(ConfigHandler.O365TenantName, ConfigHandler.ClientID, ConfigHandler.ClientSecret, ConfigHandler.O365ServiceUsername, ConfigHandler.O365ServicePassword).Wait();
            }
            catch (AggregateException ae)
            {
                foreach (Exception e in ae.Flatten().InnerExceptions)
                {
                    Logger.Send("Exception thrown when requesting an Access Token from O365: " + e.Message, Logger.LogLevel.ERROR, 17);
                }
            }
            catch (Exception ex)
            {
                Logger.Send("Exception thrown when requesting an Access Token from O365: " + ex.Message, Logger.LogLevel.ERROR, 17);
            }

            foreach (DBUser user in users)
            {
                Logger.Send("Syncing password for user: "******" originally changed at " + user.TimestampDatetime.ToLocalTime().ToString(), Logger.LogLevel.INFO, 17);

                try
                {
                    client.ChangePassword(user.Username, user.Password).Wait();
                    user.Processed = SyncProcessedStatus.COMPLETE;
                }
                catch (AggregateException ae)
                {
                    foreach (Exception e in ae.Flatten().InnerExceptions)
                    {
                        Logger.Send("Exception thrown when changing users password: "******"Exception thrown when changing users password: " + ex.Message, Logger.LogLevel.ERROR, 17);
                    user.Processed = SyncProcessedStatus.FAILED;
                }
            }

            DatabaseHandler.UpdateSyncStatus(users);

            _timerSync.Change(SYNC_WAIT_TIME, Timeout.Infinite);
        }
Exemplo n.º 2
0
        private bool OnStartChecks()
        {
            if (!Logger.Initialize())
            {
                return(false);
            }

            string configFilePath = System.Configuration.ConfigurationManager.AppSettings["secureConfigFile"];

            if (configFilePath == null || configFilePath == String.Empty)
            {
                Logger.Send("App.Config file is missing the secureConfigFile setting. Cannot start the Sync service.", Logger.LogLevel.ERROR, 1);
                return(false);
            }

            if (!ConfigHandler.Initialize(configFilePath))
            {
                Logger.Send("Configuration Handler failed to initialize. The secure configuration file likely does not exist. Has the Configuration tool been run?", Logger.LogLevel.ERROR, 2);
                return(false);
            }

            if (!ConfigHandler.LoadConfig())
            {
                Logger.Send("Configuration handler failed to load settings from the secure configuration file. Likely the file is corrupt or invalid. Recreate the configuration withe the config tool.", Logger.LogLevel.ERROR, 3);
                return(false);
            }

            if (!DatabaseHandler.Initialize(ConfigHandler.DatabaseFilename))
            {
                Logger.Send("Database handler failed to initialize.", Logger.LogLevel.ERROR, 4);
                return(false);
            }

            if (!ADHandler.Initialize())
            {
                Logger.Send("AD Handler failed to initialize.", Logger.LogLevel.ERROR, 1004);
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        public void Handle(Socket client)
        {
            try
            {
                NetworkStream netStream = new NetworkStream(client);
                StreamReader  istream   = new StreamReader(netStream);
                StreamWriter  ostream   = new StreamWriter(netStream);
                string        command   = istream.ReadLine();
                if (command == "notify")
                {
                    string username = istream.ReadLine();
                    string password = istream.ReadLine();

                    Logger.Send("[Notify] Received a Password Changed Notification for: " + username, Logger.LogLevel.INFO, 13);
                    if (ADHandler.IsUserInGroup(username, "Notify"))
                    {
                        Logger.Send("[Notify]" + username + " is in the target group", Logger.LogLevel.INFO, 13);
                        DatabaseHandler.AddSync(username, password);
                    }
                    else
                    {
                        Logger.Send("[Notify]" + username + " is not in the target group", Logger.LogLevel.INFO, 13);
                    }
                }
                else if (command == "test")
                {
                    string username = istream.ReadLine();
                    string password = istream.ReadLine();

                    Logger.Send("[Filter] Received a Password Filter request for: " + username, Logger.LogLevel.INFO, 14);

                    // LSA Blocks the ability to look up user groups. Suck I know.

                    /*if (ADHandler.IsUserInGroup(username, "Filter"))
                     * {
                     *      Logger.Send(username + " is in the target group", Logger.LogLevel.INFO, 14);*/

                    bool validPassword = false;

                    int          score     = 0;
                    const string uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                    const string lowercase = "abcdefghijklmnopqrstuvwxyz";
                    const string digit     = "1234567890";
                    const string symbol    = "~`!@#$%^&*()+=_-{}[]\\|:;\"\'?/<>,.";

                    if (password.IndexOfAny(uppercase.ToCharArray()) != -1)
                    {
                        score++;
                    }
                    if (password.IndexOfAny(lowercase.ToCharArray()) != -1)
                    {
                        score++;
                    }
                    if (password.IndexOfAny(digit.ToCharArray()) != -1)
                    {
                        score++;
                    }
                    if (password.IndexOfAny(symbol.ToCharArray()) != -1)
                    {
                        score++;
                    }

                    if (score >= 3 && password.Length >= 8 && password.Length <= 16)
                    {
                        validPassword = true;
                    }

                    ostream.WriteLine(validPassword ? "t" : "f");
                    ostream.Flush();

                    Logger.Send("[Filter] Password Filter results. Length: " + password.Length.ToString() + ". Score: " + score.ToString() + ". Verdict: " + (validPassword ? "PASSED" : "DENIED"), Logger.LogLevel.INFO, 15);

                    /*}
                     * else
                     * {
                     *      Logger.Send("[Filter]" + username + " is not in the target group", Logger.LogLevel.INFO, 14);
                     *
                     *      ostream.WriteLine("t");
                     *      ostream.Flush();
                     * }*/
                }
                else
                {
                    ostream.WriteLine("ERROR");
                    ostream.Flush();

                    Logger.Send("Received bad data on network port. Possible localhost port scan?", Logger.LogLevel.ERROR, 16);
                }
            }
            catch (Exception ex)
            {
                Logger.Send("Exception thrown when handling network socket data: " + ex.Message, Logger.LogLevel.ERROR, 13);
            }
            client.Close();
        }