public void Clear() { AuditSec.Speak("", true, false, null); IDBox.Text = ""; KeyBox.Text = ""; resetUser(); }
private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { try { if (e.Url.ToString().ToLower().Equals(BlankPage.ToLower())) { URLBox.ForeColor = System.Drawing.SystemColors.InactiveCaptionText; string additionalHeaderInfo = "Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes("MyUsername" + ":" + "MyPassword")) + System.Environment.NewLine; browser.Navigate(new Uri(URLBox.Text), null, null, additionalHeaderInfo); } else { OutputBox.Text = ""; extract(); AuditSec.Speak(OutputBox.Text, true, false, null); URLBox.ForeColor = System.Drawing.Color.DarkGreen; } } catch (Exception ee) { URLBox.ForeColor = System.Drawing.Color.Red; Console.WriteLine("Error after the document completed: " + ee.ToString()); } }
void saveSettings(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } AuditSec.Exit("HotApps module ended.", () => { base.Dispose(disposing); return(true); }); }
void speakBitlocker() { if (KeyBox.Text.Length > 0) { AuditSec.Speak("The recovery key is:\n" + (spellBitLocker(KeyBox.Text) + ".").Replace(", .", "."), true, false, null /*AuditSec.TTSReplace*/); } }
private void OUBox_SelectedIndexChanged(object sender, EventArgs e) { if (Stop.Visible) { Stop.PerformClick(); } dptBox.Items.Clear(); dptBox.Text = ""; dptBox.Items.Add(""); usersInfo.Clear(); if (domainBox.Text.Length == 0) { return; } setEnableGUI(false); statusLabel.Text = "Listing the Dpts and Workstations..."; Cursor.Current = Cursors.WaitCursor; try { DirectoryEntry de = ((Domain)domainBox.SelectedItem).GetDirectoryEntry(), ou = null; foreach (DirectoryEntry de_ in de.Children) { if (de_.Properties["name"].Value.ToString().Equals(OUBox.Text)) { ou = de = de_; break; } } usersInfo.FindAll(de); statusLabel.Text = "Found " + usersInfo.getUsersCount() + " user" + (usersInfo.getUsersCount() > 1 ? "s" : "") + " in " + domainBox.Text + "/" + OUBox.Text + "/" + dptBox.Text + " Click the Play button."; string speech = "Found " + usersInfo.getUsersCount() + " user" + (usersInfo.getUsersCount() > 1 ? "s" : "") + " in " + Regex.Replace(Regex.Replace(domainBox.Text.ToUpper(), @"([^.]*)\..*", "$1"), "(.)", "$1.") + " " + OUBox.Text.ToLower() + " " + Regex.Replace(dptBox.Text.ToUpper(), "(.)", "$1.") + "."; if (firstOUBox_SelectedIndexChanged) { AuditSec.Speak(speech, false, false, null); firstOUBox_SelectedIndexChanged = false; } else { speak(speech); } } catch (Exception ee) { Console.WriteLine(ee.ToString()); } Cursor.Current = Cursors.Default; setEnableGUI(true); }
public Unlocker() { InitializeComponent(); this.Text += " v" + AuditSec.curver; AuditSec.Speak("Welcome to A.D. account unlocker.", false, false, AuditSec.TTSReplace); Console.WriteLine("Opening domain... "); try { DomainCollection dc = Forest.GetCurrentForest().Domains; Domain[] domains = new Domain[dc.Count]; dc.CopyTo(domains, 0); domainBox.Items.AddRange(domains); domainBox.Text = Domain.GetCurrentDomain().Name; } catch (Exception e) { Console.WriteLine(e.ToString()); } string me = new DirectorySearcher("(&(ObjectClass=user)(sAMAccountName=" + UserPrincipal.Current.SamAccountName + "))") .FindOne().GetDirectoryEntry().Properties["DistinguishedName"].Value.ToString(); foreach (string s in me.Split(',').Reverse()) { string[] t = s.Split(new char[] { '=' }, 2); if (t[0].Equals("OU")) { OUBox.Text = t[1]; break; } } Console.WriteLine("Setting masks... "); if (AuditSec.settings.oumask != null && AuditSec.settings.oumask.Length > 0) { OUMaskBox.Text = AuditSec.settings.oumask; } sm0 = OUMaskBox.Text; speakWorker.RunWorkerAsync(); actionsWorker.RunWorkerAsync(); new Thread(new ThreadStart(delegate { Thread.Sleep(1000); // Console.WriteLine("Loading configuration files... "); Invoke(new picpwDelegate(setpicpw)); Invoke(new welcomeButtonDelegate(welcomeButtonPerformClick)); })).Start(); }
private void SCCMCheck_FormClosed(object sender, FormClosedEventArgs e) { if (parent != null) { parent.Show(); } else { AuditSec.Exit("SCCM Client Check tool has ended.", null); } }
void saveSettings(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } //base.Dispose(disposing); AuditSec.Exit("AD Account Unlocker tool has ended.", () => { base.Dispose(disposing); return(true); }); }
private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { try { if (e.Url.ToString().ToLower().Equals(BlankPage.ToLower())) { Console.WriteLine("\n\n\n\nLoading..." + KeyID); //browser.Url = new Uri(KeyRecoveryPage); string additionalHeaderInfo = "Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes("MyUsername" + ":" + "MyPassword")) + System.Environment.NewLine; browser.Navigate(new Uri(KeyRecoveryPage), null, null, additionalHeaderInfo); submit = false; } else if (!submit) { Console.WriteLine("\n\n\n\nSubmitting..." + KeyID); //printHtml(); resetUser(); setElement("ctl00_content_DomainNameTextBox", user.Split(new char[] { '\\' })[0]); setElement("ctl00_content_UserNameTextBox", user.Split(new char[] { '\\' })[1]); setElement("ctl00_content_KeyIdTextBox", KeyID); setElement("ctl00_content_ReasonCodeSelect", reasons[8]); clickElement("ctl00_content_SubmitButton"); submit = true; } else { //printHtml(); string RecoveryKey = getElement("ctl00_content_KeyReturnFieldInvisible"); Console.WriteLine("\n\n\n\nLoaded. " + RecoveryKey); KeyBox.Text = RecoveryKey == null ? "" : RecoveryKey; if (KeyBox.Text.Length > 0) { speakBitlocker(); } else { AuditSec.Speak("Recovery Key not found.", true, false, null); MessageBox.Show("Recovery Key not found.", "Bitlocker Drive Recovery"); } } } catch (Exception ee) { Console.WriteLine("Error after the document completed: " + ee.ToString()); } }
private void speakWorker_DoWork(object sender, DoWorkEventArgs e) { while (!IsDisposed) { if (speechs.Count() > 0) { string speech = speechs[0]; speechs.RemoveAt(0); AuditSec.SpeakWait(speech, false, false, AuditSec.TTSReplace); } else { Thread.Sleep(1000); } } }
static public Image getUserPicture(String username) { Image i = null; bool again = true; string lasterror = null; while (again) { again = false; AuditSec.checkDIRXMLAccess(lasterror); if (!AuditSec.picdisabled && AuditSec.settings.picpw != null) { try { Console.WriteLine("Retrieving picture of " + username + "..."); try { DirectorySearcher s = new DirectorySearcher( new DirectoryEntry(AuditSec.defaultLdap, "cn=" + UserPrincipal.Current.SamAccountName + ",ou=USER,o=MYCOMPANY", AuditSec.settings.picpw, AuthenticationTypes.None), "(&(objectClass=MYCOMPANYUser)(cn=" + username + "))", new[] { "photo" }, SearchScope.OneLevel ); i = Image.FromStream(new MemoryStream((byte[])s.FindOne().Properties["photo"][0])); if (i != null) { return(Resize(i, 90, 120)); } //Console.WriteLine("Picture of " + username + ": " + i.ToString()); } catch (AccessViolationException ave) { throw new Exception(ave.Message); } } catch (Exception e) { lasterror = e.Message; Console.WriteLine("Picture of " + username + ": Error: " + e.Message); if (e.Message.StartsWith("Logon failure") || e.Message.EndsWith("A constraint violation occurred.") || e.Message.StartsWith("The server is unwilling to process the request")) { lasterror = "Invalid password."; AuditSec.settings.picpw = null; again = true; } } } } return(i); }
public static bool switchArgs(string[] args) { try { bool nomatch = true; for (int i = 0; i < tools_command.Length; i++) { string command = tools_command[i]; Func <Form> constr = tools_new[i]; if (args.Contains("/" + command) && command != "update") { nomatch = false; Console.WriteLine("Launching appropriate tool..."); AuditSec.readSettings(); Application.Run(constr()); } } if (nomatch) { /*if (!isAdministrator()) * { * MessageBox.Show("The setup needs to run with Elevated rights in order to execute properly.\n\n" + "Please right-click 'setup.exe' and then click 'Run as administrator'.", + "IT O p s T o o l s S u i t e"); + return true; + } + else */return(false); } else { return(true); } } catch (Exception e) { AuditSec.Exit("Fatal Error:\n\n" + e.ToString(), null); return(true); } }
public static bool resetPassword(DirectoryEntry de) { /* * using (var context = new PrincipalContext(ContextType.Domain)) * { * using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, userName)) * { * user.SetPassword("newpassword"); * // or * user.ChangePassword("oldPassword", "newpassword"); * } * } */ string newPassword = "******"; if (DialogResult.OK == AuditSec.pwInputBox("Reset user " + de.Name + " password", "New password", ref newPassword) && newPassword.Length > 0) { try { de.Invoke("SetPassword", new object[] { newPassword }); de.Properties["LockOutTime"].Value = 0; //unlock account de.Close(); return(true); } catch (Exception e) { Console.WriteLine("Reset user " + de.Name + " password: Exception: " + e.Message); return(false); } } else { return(true); } }
static bool isAdministrator() { WindowsIdentity identity = WindowsIdentity.GetCurrent(); WindowsPrincipal principal = new WindowsPrincipal(identity); bool admin = principal.IsInRole(WindowsBuiltInRole.Administrator); if (!admin) { return(false); } string test = Path.Combine(Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData), "MYCOMPANY"), "sccmqueries.wql.readme"); bool copy = false; try { copy = AuditSec.exportResource("sccmqueries_wql", test, true); } catch (Exception e) { Console.WriteLine(e.ToString()); } return(copy); }
public void createDesktopShortcuts() { Console.WriteLine("Creating desktop shortcuts..."); label1.Visible = SelectAll.Visible = SelectNone.Visible = false; List <string> selected = getSelectedTools(); for (int i = 0; i < tools_command.Length; i++) { if (tools_desc[i].Length > 0) { string command = tools_command[i], desc = tools_desc[i], icon = tools_icon[i]; string lnkpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), desc + ".lnk"); CheckBox box = tools_command[i] == "update" ? null : getCheckBoxes().First(c => c.Name == tools_command[i]); LinkLabel test = tools_command[i] == "update" ? null : getLinkLabels().First(c => c.Name == tools_command[i] + "_test"); if (box != null) { box.Enabled = false; } if (test != null) { test.Visible = false; } try { if (selected.Contains(command) || command == "update") { if (!AuditSec.exportResource(icon, Path.Combine( Application.StartupPath, icon + ".ico"), false)) { Console.WriteLine("Cannot create desktop icon. (" + icon + ")"); } IWshRuntimeLibrary.IWshShortcut lnk = (IWshRuntimeLibrary.IWshShortcut) new IWshRuntimeLibrary.WshShellClass().CreateShortcut(lnkpath); if (command == "update") { lnk.TargetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "MYCOMPANY\\AuditSec.appref-ms"); } else { lnk.TargetPath = Application.ExecutablePath; lnk.Arguments = "/" + command; } lnk.Description = "Launch " + desc + "."; lnk.IconLocation = Path.Combine(Application.StartupPath, icon + ".ico"); lnk.Save(); } else { if (box != null) { box.Checked = false; } if (File.Exists(lnkpath)) { File.Delete(lnkpath); } if (box != null) { box.Visible = false; } } } catch (Exception e) { if (box != null) { box.Checked = false; } Console.WriteLine("createDesktopShortcuts error: " + lnkpath + ": " + e.Message); } } } }
void addCheckBox(string name, string label, string icon, bool defaultsel) { if (name != "update") { int n = getCheckBoxes().Count; int items_per_column = 8; // int items_per_row = 2; int x = n / items_per_column; int y = n % items_per_column; // int x = n % items_per_row; // int y = n / items_per_row; // Console.WriteLine("X=" + x + " Y=" + y + " " + label); int column_gap = 250; int row_gap = 30; int x0 = 100; int y0 = 100; System.Windows.Forms.CheckBox box = new System.Windows.Forms.CheckBox(); box.AutoSize = true; box.Location = new System.Drawing.Point(x0 + x * column_gap, y0 + y * row_gap); box.Name = name; box.MinimumSize = box.MaximumSize = box.Size = new System.Drawing.Size(column_gap - 30, row_gap); box.TabIndex = n; box.Text = label; box.UseVisualStyleBackColor = true; box.CheckedChanged += (o, e) => { selectedCount += box.Checked ? 1 : -1; Setup.Text = selectedCount == 0 ? "Uninstall Application" : "Setup Shortcuts"; }; Image image = getIcon(icon); if (image != null) { image = new Bitmap(image, new Size(24, 24)); } box.Image = image; box.ImageAlign = System.Drawing.ContentAlignment.TopLeft; Controls.Add(box); box.Checked = defaultsel; System.Windows.Forms.LinkLabel test = new System.Windows.Forms.LinkLabel(); test.Location = new System.Drawing.Point(x0 - 30 + x * column_gap, y0 + 7 + y * row_gap); test.Name = name + "_test"; test.Size = new System.Drawing.Size(30, 20); test.Text = "test"; test.Click += (o, e) => { this.Visible = false; test.Visible = false; AuditSec.readSettings(); Thread T = new Thread(new ThreadStart(() => { Console.WriteLine("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> " + Thread.CurrentThread.Name + "\n"); try { Application.Run(tools_new[n]()); } catch (Exception ee) { Console.WriteLine("Oops! Seems this tool cannot be tested here.\n" + ee.ToString()); } this.Invoke(new showWizardDelegate(() => { wizardInstance.Visible = true; })); })); T.Name = "IT_Ops_Tools_Suite-" + name + "_test" + "-Thread"; T.SetApartmentState(ApartmentState.STA); T.Start(); }; Controls.Add(test); } }
private void SizeCollector_FormClosed(object sender, FormClosedEventArgs e) { AuditSec.Exit(this.Text, null); }
void speak(string x) { speechs.Clear(); AuditSec.Speak(x, true, false, null); }
private void SCCMCheck_Shown(object sender, EventArgs e) { AuditSec.InitializeSMS(false, MYCOMPANY_Settings.SMS_DEFAULT_SERVER, MYCOMPANY_Settings.SMS_DEFAULT_SITE); }
private void browser_Navigated(object sender, WebBrowserNavigatedEventArgs e) { AuditSec.InjectAlertBlocker(browser); //Console.WriteLine("Browser: navigated. " + e.Url); }
static public Hashtable getDIRXMLAttributes(String username) { int maxtry = 10; int retrydelay = 500; Hashtable h = null; bool again = true; int trycount = 0; string lasterror = null; while (again && trycount <= maxtry) { trycount++; again = false; AuditSec.checkDIRXMLAccess(lasterror); if (!AuditSec.picdisabled && AuditSec.settings.picpw != null) { try { //Console.WriteLine("Retrieving DirXML data of " + username + "..."); try { DirectorySearcher s = new DirectorySearcher( new DirectoryEntry(AuditSec.defaultLdap, "cn=" + UserPrincipal.Current.SamAccountName + ",ou=USER,o=MYCOMPANY", AuditSec.settings.picpw, AuthenticationTypes.None), "(&(objectClass=MYCOMPANYUser)(cn=" + username + "))", DIRXMLattr2, SearchScope.OneLevel ); SearchResult result = s.FindOne(); if (result == null) { Console.WriteLine("DirXML data of " + username + ": Error: Not found."); } ResultPropertyCollection p = result.Properties; h = new Hashtable(); for (int i = 0; i < DIRXMLattr.Length; i++) { string attr = DIRXMLattr[i]; string attr2 = DIRXMLattr2[i]; Type type = getDIRXMLtype(attr); //Console.WriteLine("Retrieving DirXML data of " + username + "/" + attribute + "..."); string value = p[attr2].Count > 0 ? p[attr2][0].ToString() : ""; if (getDIRXMLalias(attr).Equals("Decentralized")) { value = value.ToLower().Contains("decentralized") ? "Home-based" : "Office-based"; } h.Add(attr, getValue(type, value)); } //Console.WriteLine("DirXML data of " + username + ": " + h.ToString()); } catch (AccessViolationException ave) { throw new Exception(ave.Message); } } catch (Exception e) { lasterror = e.Message; if (e.Message.StartsWith("Object reference not set to an instance of an object")) { ;//not found. ok } else if (e.Message.StartsWith("A device attached to the system is not functioning")) { lasterror = e.Message; Thread.Sleep(retrydelay); again = true; } else { Console.WriteLine("DirXML data of " + username + ": " + e.Message); } if (e.Message.StartsWith("Logon failure") || e.Message.EndsWith("A constraint violation occurred.") || e.Message.StartsWith("The server is unwilling to process the request")) { lasterror = "Invalid password."; AuditSec.settings.picpw = null; again = true; } } } if (again && trycount > maxtry) { Console.WriteLine("DirXML data of " + username + ": Error: " + lasterror + "\nMaximum retry reached."); } } return(h); }
private FlowLayoutPanel addAction(String actionStr, String actionCmd, String user, bool decentralized, Image pic) { FlowLayoutPanel panel = new FlowLayoutPanel(); panel.Size = new Size(500, 50); Button button = new Button(); button.Size = new Size(450, 46); panel.Controls.Add(button); button.Text = actionStr; if (decentralized) { button.BackColor = System.Drawing.Color.LightCoral; } myWPF.LyncControl lync = null; string pres = ""; if (actionCmd.Equals("UNLOCK") || actionCmd.Equals("EXPIRING")) { bool found = false; foreach (Control c in actionsPanel.Controls) { if (c is FlowLayoutPanel && c.Controls.Count > 0 && c.Controls[0] is Button && c.Controls[0].Text.Equals(actionStr)) { found = true; break; } } if (found) { return(null); } button.Image = pic; if (button.Image != null) { panel.Size = new Size(500, 100); button.Size = new Size(450, 96); } string desc = usersInfo.getDisplaynameFromUsername(user); string sip = usersInfo.getSipFromDisplayname(desc); if (sip != null && sip.Length > 0) { lync = AuditSec.newLyncControl(this, sip, button.Parent); pres = lync.getPresenceStatus(); Console.WriteLine(sip + " = " + pres); panel.Size = new Size(500, 100); } } button.Click += delegate { button.Enabled = false; switch (actionCmd) { case "UNLOCK": if (!usersInfo.unlockAD(user)) { Cursor.Current = Cursors.Default; speak("FAILED to unlock account " + user); MessageBox.Show("FAILED to unlock account " + user, "Locked User Detection"); button.ForeColor = Color.Red; button.Enabled = true; } else { Cursor.Current = Cursors.Default; speak("Successfully unlocked account " + user); MessageBox.Show("Successfully unlocked account " + user, "Locked User Detection"); actionsPanel.Controls.Remove(button.Parent); } break; case "EXPIRING": if (lync != null) { lync.openIMWindow(); } speak("Invite user " + user + " to change the password."); MessageBox.Show("Invite user " + user + " to change the password.", "Expiring User Detection"); actionsPanel.Controls.Remove(button.Parent); break; default: actionsPanel.Controls.Remove(button.Parent); break; }//switch }; //+=Click string speech = actionStr.Replace(actionCmd + ": ", ""); speech = Regex.Replace(speech, "(.*), (.*)'s ", "$2 $1's "); speech = Regex.Replace(speech, @"\*\*\*(.*)\*\*\*", "Beware, this staff is $1."); switch (pres) { case "Free": speech += ". This user is ONLINE and free."; break; case "Busy": speech += ". This user is ONLINE but busy."; break; case "DoNotDisturb": speech += ". This user is ONLINE but very busy."; break; case "Away": speech += ". This user is ONLINE but away."; break; case "Offline": speech += ". This user is offline."; break; case "None": speech += ". This user is offline."; break; default: Console.WriteLine("status not coded: " + pres); break; } speechs.Add(speech); return(panel); }