Пример #1
0
        static void Main(string [] args)
        {
            settings st1 = new settings();
            functions fn1 = new functions();
            results rs1 = new results();
            st1.baseKey = "SOFTWARE\\OLPL";
            st1.appKey = "PC-Sec";
            fn1.regCreateKeys(st1);
            st1 = fn1.getSettings(st1);
            st1.logFile = @"c:\temp\log.txt";
            st1.mode = 1;
            st1.resultURL = "https://api.olpl.org/api/sec";
            if (args.Length > 0)
            {
                if (args[0].ToUpper() == "ADMIN")
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
                }
            }
               else
            {
                Console.WriteLine("Run application on client");
                rs1 = fn1.checkMaintUser(st1,rs1);
                rs1.Result_Admin_User = fn1.checkAdministrator(st1, "Administrator");
                rs1.Result_Admin_Group = fn1.checkAdministrators(st1);

                fn1.sendResults(st1, rs1);
                Thread.Sleep(6000);
                Application.Exit();
            }
        }
Пример #2
0
        public results checkMaintUser(settings st1, results rs1)
        {
            PrincipalContext ctx = new PrincipalContext(ContextType.Machine);
            string str1 = "";
            bool changePass = true;
            // find a user
            UserPrincipal user = UserPrincipal.FindByIdentity(ctx, decryptByte(st1.adminName));
            if (user == null)
            {
                changePass = false;
                PrincipalContext systemContext = null;
                systemContext = new PrincipalContext(ContextType.Machine, null);
                UserPrincipal userPrincipal = new UserPrincipal(systemContext);
                userPrincipal.Name = decryptByte(st1.adminName);
                userPrincipal.DisplayName = "IT Administrative User";
                userPrincipal.PasswordNeverExpires = true;
                userPrincipal.SetPassword(decryptByte(st1.adminPass));
                userPrincipal.Enabled = true;
                userPrincipal.Save();
                GroupPrincipal groupPrincipal = null;
                groupPrincipal = GroupPrincipal.FindByIdentity(systemContext, "Administrators");
                groupPrincipal.Members.Add(userPrincipal);
                groupPrincipal.Save();
                RegistryKey rk = Registry.LocalMachine.OpenSubKey(st1.baseKey + "\\" + st1.appKey, true);
                rk.SetValue("p1-1", st1.adminPass, RegistryValueKind.Binary);
                rk.SetValue("pC", DateTime.Now.ToString(),RegistryValueKind.String);
                rs1.Resutl_User_Pass_Changed = DateTime.Now.ToString();

                str1 =str1+ " not found Created";
            }
            else
            {
                str1 = str1 + " Found";
                PrincipalContext systemContext = null;
                systemContext = new PrincipalContext(ContextType.Machine, null);
                GroupPrincipal groupPrincipal = null;
                groupPrincipal = GroupPrincipal.FindByIdentity(systemContext, "Administrators");
                if (groupPrincipal.Members.Contains(systemContext, IdentityType.SamAccountName, decryptByte(st1.adminName)))
                {
                    str1 = str1 + " Administrator";
                }
                else
                {
                    UserPrincipal usr = UserPrincipal.FindByIdentity(systemContext, decryptByte(st1.adminName));
                    groupPrincipal.Members.Add(usr);
                    groupPrincipal.Save();

                    str1 = str1 + " not Administrator";
                }
            }
            if (ByteArrayCompare(st1.adminPass,st1.adminPass1)!=true && changePass==true)
            {
                try
                {

                    str1 = str1 + " Password does not match";
                    PrincipalContext systemContext = null;
                    systemContext = new PrincipalContext(ContextType.Machine, null);
                    UserPrincipal usr = UserPrincipal.FindByIdentity(systemContext, decryptByte(st1.adminName));
                    usr.ChangePassword(decryptByte(st1.adminPass1), decryptByte(st1.adminPass));
                    RegistryKey rk = Registry.LocalMachine.OpenSubKey(st1.baseKey + "\\" + st1.appKey, true);
                    rk.SetValue("p1-1", st1.adminPass, RegistryValueKind.Binary);
                    rk.SetValue("pC", DateTime.Now.ToString(), RegistryValueKind.String);
                    rs1.Resutl_User_Pass_Changed = DateTime.Now.ToString();
                }
                catch(Exception e)
                {
                    str1 = e.Message;
                }

            }
            else { str1 = str1 + " Password OK"; }
            rs1.Result_Maint_User = str1;
            return rs1;
        }
Пример #3
0
        public bool sendResults(settings st1,results rs1)
        {
            try
            {
                using (WebClient client = new WebClient())
                {
                    if (rs1.Result_Admin_Group == null) { rs1.Result_Admin_Group = "Not Reported"; }
                    if (rs1.Result_Admin_User == null) { rs1.Result_Admin_User = "******"; }
                    if(rs1.Resutl_User_Pass_Changed == null){ rs1.Resutl_User_Pass_Changed = st1.timeChanged; }
                    NameValueCollection vals = new NameValueCollection();
                    vals.Add("CPUName", Environment.MachineName);
                    vals.Add("Result_Admin_Group", rs1.Result_Admin_Group);
                    vals.Add("Result_Admin_User", rs1.Result_Admin_User);
                    vals.Add("Result_Maint_User", rs1.Result_Maint_User);
                    vals.Add("Result_User_Pass_Changed", rs1.Resutl_User_Pass_Changed);
                    client.Credentials = new NetworkCredential(decryptByte(st1.connectUser), decryptByte(st1.connectPass), "olpl");
                    client.UploadValues(st1.resultURL, vals);
                }
            }
            catch (Exception e)
            {
                writeToFile(e.Message, st1);
                return false;
            }

            return true;
        }