Exemple #1
0
        public static bool FinalCheck(string hostIP, string userID, Main f, bool isWmiActive, bool displayTask = false)
        {
            HostInfo hostInfoUtil = new HostInfo();

            hostInfoUtil.HostIP = hostIP;
            hostInfoUtil.UserID = userID;

            bool removalTaskExists

            try
            {
                RemoteTasks remote = new RemoteTasks(hostInfoUtil, f);
                remote.GetHostInfo(true, false);

                ADTasks ad = new ADTasks(hostInfoUtil, f);
                ad.CheckLocale(true);
                ad.CheckExistingRights(true, false, false);
            }
            catch (Exception)
            {
                MsgBoxInfo("Failed to complete Final Check");
            }

            if (TargUtilities.QueryTaskScheduler(hostIP, userID))
            {
                removalTaskExists = true;
            }
            else
            {
                RemoteTasks remote = new RemoteTasks(hostInfoUtil, f);
                rem
            }

            //ADTasks adTasksVerify = new ADTasks(hostInfoUtil,f);
            //adTasksVerify.CheckLocale(isWmiActive);
            //adTasksVerify.CheckExistingRights(isWmiActive,false,false);

            string batchPath = string.Format(@"\\{0}\c$\windows\system32\RemAdmin.bat", hostIP);

            bool batchRemovalExists = File.Exists(batchPath);
            bool adminExists        = hostInfoUtil.AdminRightsExist;

            TargUtilities.MsgBoxInfo(string.Format(
                                         "Batch Exists: {0}{3}" +
                                         " Task Exists: {1}{3}" +
                                         "Admin Exists: {2}{3}",
                                         batchRemovalExists,
                                         removalTaskExists,
                                         adminExists,
                                         Environment.NewLine));

            if (batchRemovalExists && removalTaskExists && adminExists)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        private void btnGrantRights_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtUserID.Text))
            {
                Util.MsgBox.Info("User ID cannot be blank when granting rights.");
                return;
            }

            user.UserID = txtUserID.Text.Trim(); //Update UserID in case user has changed it.
            ToggleRadioControls(false);
            ToggleButtonsOnOff(false);

            try
            {
                adTasksGrant = new AdTasks(targ);
                //If Production environment query Active Directory
                //for user's full name and verify the ID exists.
                if (isProdEnv)
                {
                    adTasksGrant.FindUserActiveD();
                    if (!user.UserIDExists) //User not found in AD, cannot proceed.
                    {
                        StatusReport(2);    //cancelling...
                        return;
                    }
                }
                //Found user in AD, let's see if they already have
                //admin rights on the host machine.
                adTasksGrant.CheckExistingRights(false, false);
                remoteTasksGrant = new RemoteTasks(targ);
            }
            catch (Exception)
            {
                ClearForm(false);
                return;
            }


            bool result = MsgBoxConfirmRights();

            if (result)
            {
                if (!user.AdminRightsExist)
                {
                    adTasksGrant.GrantRights(timeSpan);       //Add user to the Administrators group on Host.
                }
                remoteTasksGrant.CreateRemovalTask(timeSpan); //Create Scheduled task to remove rights.
                eventLogs.LogAction(timeSpan, AdTasks.ADD);   //Create a log file
                StatusReport(1);
                CopyToClipboard();                            //Attempts to copy contents of txtConsole to clipboard.
            }
            else
            {
                StatusReport(2); //cancelling...
            }
            ToggleRadioControls(true);
            ToggleButtonsAndHostIP(true, true);
            ToggleButtonsOnOff(true);
            ClearForm(false);
        }
Exemple #3
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (!targDev.mainForm.GetTxtConsole.Contains("Online"))
            {
                Util.MsgBox.Info("You must connect to host first.");
                return;
            }
            RemoteTasks r = new RemoteTasks(targDev);

            r.CreateRemovalTask(2);
            button4.PerformClick();
        }
Exemple #4
0
            //***Not implemented in production, test only
            //After rights granted verifies rights exist on host,
            //& Scheduled Task exists.
            public static bool FinalCheck(TargInfo targ, bool displayTask = false)
            {
                bool        removalTaskExists;
                RemoteTasks remote;

                try
                {
                    remote = new RemoteTasks(targ);
                    remote.GetHostInfo();

                    AdTasks ad = new AdTasks(targ);
                    ad.CheckLocale();
                    ad.CheckExistingRights();
                }
                catch (Exception)
                {
                    MsgBox.Info("Failed to complete Final Check");
                }

                if (QueryTaskScheduler(targ, true))
                {
                    removalTaskExists = true;
                }
                else
                {
                    RemoteTasks remote1 = new RemoteTasks(targ);
                    removalTaskExists = remote1.jobFileExists();
                }

                bool adminExists = targ.host.user.AdminRightsExist;

                targ.mainForm.WriteToConsole(string.Format(
                                                 "Task Exists:  {0}{2}" +
                                                 "Admin Exists: {1}{2}",
                                                 removalTaskExists,
                                                 adminExists,
                                                 Environment.NewLine));

                return(removalTaskExists && adminExists);
            }
Exemple #5
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            targ.Dispose();                //Dispose of any prior data **BROKEN, FIX
            user.AdminRightsExist = false; //**Remove once Dispose is fixed.

            if (PreConnectCheck(txtHostIP.Text.Trim()))
            {
                try
                {
                    adTasksGrant = new AdTasks(targ);   //Before we can connect and fetch host info
                    adTasksGrant.CheckLocale();         //we need to check it's Locale (english / french)

                    remoteTasksGrant = new RemoteTasks(targ);
                    remoteTasksGrant.GetHostInfo();
                }
                catch (Exception connectError)
                {
                    Util.MsgBox.Info(connectError.ToString());
                    WriteToConsole("::Failed to connect to host::");
                    eventLogs.LogError(connectError);
                    ClearForm(false);
                    return;
                }

                if (string.IsNullOrWhiteSpace(txtUserID.Text)) //populate txtUserID & update UserID
                {
                    txtUserID.Text = user.CurrentUser;
                    user.UserID    = user.CurrentUser;
                }

                StatusReport(0);
                ToggleButtonsAndHostIP(false, false); //Online with host, disable Remove button & txtHostIP
            }
            else
            {
                ClearForm(false); //Set initial form load state
            }
        }
Exemple #6
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            connection.HostIP = txtIP.Text.Trim();
            Util.ConnectionTest.TestWmi(targDev);
            int cmdChoice = comboBox2.SelectedIndex;

            var         execute = (Command)cmdChoice;
            RemoteTasks r;
            AdTasks     ad;

            string[] vpnScope =
            {
                "10.40.244", "10.32.244",
                "10.40.245", "10.32.245",
                "10.40.246", "10.32.246"
            };

            bool isVpn = vpnScope.Any(s => txtIP.Text.Contains(s));

            Cursor.Current = Cursors.WaitCursor;

            switch (execute)
            {
            case Command.RightsExist:

                #region Check for Exsisting Rights (Script)

                user.AdminRightsExist = false;
                if (txtIP.Text == string.Empty || txtUser.Text == string.Empty)
                {
                    MessageBox.Show("IP & ID Cannot be blank");
                }
                else if (Util.ConnectionTest.IsHostAlive(txtIP.Text))
                {
                    user.UserID       = txtUser.Text;
                    connection.HostIP = txtIP.Text;

                    ad = new AdTasks(targDev);
                    connection.IsWmiActive = false;     //DevTools Only
                    ad.CheckLocale();
                    ad.CheckExistingRights(NoComboAdd, DevOutputFalse);

                    targDev.mainForm.WriteToConsole(user.AdminRightsExist ? "Rights Exist." : "Rights DO NOT Exist.");
                }

                #endregion

                break;

            case Command.RightsExistWmi:

                #region Check for Existing Rights(WMI)

                user.AdminRightsExist = false;
                if (txtIP.Text == string.Empty || txtUser.Text == string.Empty)
                {
                    MessageBox.Show("IP & ID Cannot be blank");
                }
                else if (Util.ConnectionTest.IsHostAlive(txtIP.Text))
                {
                    if (isVpn)
                    {
                        MessageBox.Show("Fuction does not work with VPN clients.");
                        return;
                    }

                    user.UserID       = txtUser.Text;
                    connection.HostIP = txtIP.Text;

                    ad = new AdTasks(targDev);
                    r  = new RemoteTasks(targDev);

                    r.GetHostInfo();
                    ad.CheckLocale();
                    ad.CheckExistingRights(NoComboAdd, DevOutputFalse);


                    targDev.mainForm.WriteToConsole(user.AdminRightsExist ? "Rights Exist." : "Rights DO NOT Exist.");
                }
                else
                {
                    MessageBox.Show("Host is not Online.");
                }

                #endregion

                break;

            case Command.UserExists:

                #region Check if User Esists in AD

                if (Util.ValidationCheck.isTestEnvironment())
                {
                    MessageBox.Show("Function does not work in TEST Environment");
                    return;
                }
                if (txtUser.Text == string.Empty)
                {
                    MessageBox.Show("IP & ID Cannot be blank");
                }
                else
                {
                    user.UserID = txtUser.Text;

                    ad = new AdTasks(targDev);
                    ad.FindUserActiveD();
                }

                #endregion

                break;

            case Command.ListAdmins:

                #region List all Admins on Host

                if (txtIP.Text == string.Empty)
                {
                    MessageBox.Show("IP cannot be blank");
                }
                else
                {
                    connection.HostIP      = txtIP.Text;
                    connection.IsWmiActive = false;     //DevTools Only
                    ad = new AdTasks(targDev);
                    ad.CheckLocale();
                    ad.CheckExistingRights(NoComboAdd, DevOutputTrue);
                }

                #endregion

                break;

            case Command.ListAdminsWmi:

                #region List all Admins on Host(WMI)

                if (txtIP.Text == string.Empty)
                {
                    MessageBox.Show("IP cannot be blank");
                }
                else
                {
                    if (isVpn)
                    {
                        MessageBox.Show("Fuction does not work with VPN clients.");
                        return;
                    }
                    connection.HostIP = txtIP.Text;

                    ad = new AdTasks(targDev);
                    r  = new RemoteTasks(targDev);
                    ad.CheckLocale();
                    r.GetHostInfo();
                    ad.CheckExistingRights(NoComboAdd, DevOutputTrue);
                }

                #endregion

                break;

            case Command.AddTestAdmins:

                //To use create a file named AddAdmin.bat in the System32 dir.
                //add a line for each user you want to add admin rights for
                //ex. NET LOCALGROUP ADMINISTRATORS {USERID} /ADD
                #region Add Test Admins
                if (!File.Exists(@"c:\windows\system32\AddAdmin.bat"))
                {
                    MessageBox.Show(@"File ""AddAdmin.bat"" does not exist.");
                }
                else
                {
                    const string args = "/c AddAdmin.bat";
                    Util.Tools.RunProcess(args, false);
                    MessageBox.Show("--Added test users--");
                }

                #endregion

                break;

            case Command.GetInfoByScripts:

                #region Get Info By Scripts

                if (txtIP.Text == string.Empty)
                {
                    MessageBox.Show("IP cannot be blank.");
                }
                else
                {
                    connection.HostIP = txtIP.Text;

                    r = new RemoteTasks(targDev);
                    r.GetHostInfo(DevOutputTrue);

                    targDev.mainForm.WriteToConsole(string.Format(
                                                        "==========================={0}" +
                                                        "GetInfoByScripts{0}" +
                                                        "==========================={0}" +
                                                        "Current User: {1}{0}" +
                                                        "Computer Name: {2}{0}" +
                                                        "Local Time: {3}{0}" +
                                                        "===========================",
                                                        Environment.NewLine,
                                                        user.CurrentUser,
                                                        connection.HostName,
                                                        targDev.host.removalTask.HostTime));
                }

                #endregion

                break;

            case Command.GetInfoByWmi:

                #region Get Info By WMI

                if (txtIP.Text == string.Empty)
                {
                    MessageBox.Show("IP cannot be blank.");
                }
                else
                {
                    if (isVpn)
                    {
                        MessageBox.Show("Fuction does not work with VPN clients.");
                        return;
                    }

                    connection.HostIP = txtIP.Text;
                    r = new RemoteTasks(targDev);
                    r.GetHostInfo(DevOutputTrue);
                    targDev.mainForm.WriteToConsole(string.Format(
                                                        "==========================={0}" +
                                                        "GetInfoByWMI{0}" +
                                                        "==========================={0}" +
                                                        "Current User: {1}{0}" +
                                                        "Computer Name: {2}{0}" +
                                                        "Local Time: {3}{0}" +
                                                        "===========================",
                                                        Environment.NewLine,
                                                        user.CurrentUser,
                                                        connection.HostName,
                                                        targDev.host.removalTask.HostTime));
                }

                #endregion

                break;
            }

            Cursor.Current = Cursors.Default;
        }
Exemple #7
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtHostIP.Text))
            {
                Util.MsgBox.Info("Host IP cannot be blank.");
                return;
            }

            targ.Dispose();
            ToggleButtonsOnOff(false);
            user.AdminRightsExist = false;

            if (PreConnectCheck(txtHostIP.Text.Trim()))
            {
                bool checkRights,
                     addAdminToCombo = false;
                const bool devOutput = false;

                if (string.IsNullOrWhiteSpace(user.UserID))
                {
                    checkRights     = false; //User did not specify a user id, query host for admins.
                    addAdminToCombo = true;  //Add found admins to comboAdminList
                }
                else
                {
                    checkRights = true; //user id specified, check if they have admin rights.
                }

                try
                {
                    adTasksRemove = new AdTasks(targ);
                    adTasksRemove.CheckLocale();
                    remoteTasksRemove = new RemoteTasks(targ);
                    remoteTasksRemove.GetHostInfo();
                }
                catch (Exception connectError)
                {
                    eventLogs.LogError(connectError);
                    ClearForm(false);
                    return;
                }

                //Only runs when User ID is blank.
                //Checking rights and adding admin users to comboAdminList
                if (!checkRights)
                {
                    adTasksRemove.CheckExistingRights(addAdminToCombo, devOutput);

                    if (comboAdminList.Items.Count == 0) //No admin's found
                    {
                        MessageBox.Show("No user's found with admin rights.");
                    }
                    else
                    {
                        ToggleButtonsOnOff(false);
                        //display comboAdminList box to select user to remove.
                        comboAdminList.Visible = true;
                        selectUserBox.Visible  = true;
                    }
                }
                else
                {
                    adTasksRemove.CheckExistingRights(addAdminToCombo, devOutput);

                    if (user.AdminRightsExist)
                    {
                        bool result = MsgBoxConfirmRemoval();
                        if (result)
                        {
                            adTasksRemove.RemoveRights();
                            adTasksRemove.CheckExistingRights(false, false);
                            string jobFilePath = string.Format(
                                @"\\{0}\c$\windows\tasks\{1}.job", connection.HostIP, user.UserID);
                            try
                            {
                                if (File.Exists(jobFilePath)) //Delete existing scheduled tasks
                                {
                                    File.Delete(jobFilePath);
                                }
                            }
                            catch (Exception)
                            {
                                throw;
                            }

                            //**Can implement a final check to make sure rights
                            //were removed. In tests/production use this has
                            //not failed yet.

                            StatusReport(3);
                            CopyToClipboard();
                        }
                        else if (!user.AdminRightsExist) //User specified ID does not have admin rights.
                        {
                            Util.MsgBox.Info(string.Format(
                                                 "User {0} does not have admin rights on {1}.",
                                                 user.UserID, connection.HostName));
                        }
                        else
                        {
                            StatusReport(2);
                        }
                    }
                    else
                    {
                        Util.MsgBox.Info(string.Format(
                                             "User {0} does not have admin rights on {1}.",
                                             user.UserID, connection.HostName));
                    }
                }
            }
            else
            {
                Util.MsgBox.Info("Failed to connect to host. Is host online?");
                ClearForm(false);
            }

            if (!comboAdminList.Visible)
            {
                ToggleButtonsOnOff(true);
            }
        }