diff --git a/RubberDuckyApp/MainForm.cs b/RubberDuckyApp/MainForm.cs index 7af01b2..ea5a80b 100644 --- a/RubberDuckyApp/MainForm.cs +++ b/RubberDuckyApp/MainForm.cs @@ -45,10 +45,10 @@ public partial class MainForm : Form "pt", "ru", "si", "sv", "tr", "us" }; - private const string EncoderURL = - "https://github.com/midnitesnake/USB-Rubber-Ducky/blob/master/Encoder/encoder.jar?raw=true"; + private const string EncoderUrl = + "https://github.com/hak5darren/USB-Rubber-Ducky/blob/master/Encoder/encoder.jar?raw=true"; - private const string PayloadsURL = + private const string PayloadsUrl = "https://github.com/hak5darren/USB-Rubber-Ducky/wiki/Payloads"; private readonly WebClient _client; @@ -140,11 +140,13 @@ private void button1_Click(object sender, EventArgs e) private void button2_Click(object sender, EventArgs e) { // Copy .bin Button - RefreshMicroSdComboBox(); - if (comboBox3.SelectedIndex != -1) // Check title array for removable disks - microSDCheck = true; + // Check title array for removable disks + if (comboBox3.SelectedIndex != -1) + { + microSDCheck = true; + } - if ( microSDCheck) + if (microSDCheck) File.Copy(duckyDirectory+"\\inject.bin",selectedRemovableDrive+"\\inject.bin", true); // .bin copied to label @@ -204,36 +206,26 @@ private void RefreshMicroSdComboBox() { foreach (DriveInfo driveInf in DriveInfo.GetDrives()) { - // Lists all USB's - if (driveInf.DriveType == DriveType.Removable) // USB Removeable Drive + // Lists all removable drivers + if (driveInf.DriveType == DriveType.Removable) { - // Current Drive - string drvName = driveInf.Name.ToString(); - string drvVolume = driveInf.VolumeLabel; - Console.WriteLine($"{drvName}:${drvVolume}"); comboBox3.Items.Add(driveInf.Name); - if (drvName == "Ducky") // If Name = Ducky - { - - } - else - { - // No USB's with Ducky as Name - } - } - else - { - // No USB's Found - MessageBox.Show("No removable storage device was found.\n" + - "Please insert the MicroSD card that will be used for your USB Rubber Ducky.\n" + - "Click \"Refresh\" when ready."); + } - } + // No removable drives found + if (comboBox3.Items.Count == 0){ + MessageBox.Show(@"No removable storage device was found. +" + + @"Please insert the MicroSD card that will be used for your USB Rubber Ducky. +" + + @"Click ""Refresh"" when ready."); + } else if (comboBox3.Items.Count > 0) + comboBox3.SelectedIndex = 0; } catch (Exception ex) { - MessageBox.Show("Error: " + ex.Message); + MessageBox.Show(@"Error: " + ex.Message); } } @@ -255,17 +247,16 @@ private void CheckDirectoryExists() { if (!Directory.Exists(duckyDirectory)) { - DialogResult result = MessageBox.Show("The directory: \"" + duckyDirectory + "\"" + " does not exist.\nWould you like to create it for this application?", - "NOTICE!", + DialogResult result = MessageBox.Show($@"The directory: {duckyDirectory} does not exist. + Would you like to create it for this application?", + @"NOTICE!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.None, MessageBoxDefaultButton.Button3); - if (result == DialogResult.Yes) // If user said yes - { - Directory.CreateDirectory(duckyDirectory); - MessageBox.Show(duckyDirectory + "has been created!"); - } + if (result != DialogResult.Yes) return; // If user didn't say yes + Directory.CreateDirectory(duckyDirectory); + MessageBox.Show($@"{duckyDirectory} has been created!"); } } @@ -279,23 +270,27 @@ private void CheckHomeDirectoryJava() { if (Directory.Exists(java32)) // Then Java32 is installed { - string[] java32subdirectories = Directory.GetDirectories(java32); - javaEXELocation = java32subdirectories.Last() + "\\bin\\java.exe"; // Selects most current version - File.Copy(javaEXELocation, javaHome); + string[] java32Subdirectories = Directory.GetDirectories(java32); + javaEXELocation = java32Subdirectories.Last() + "\\bin\\java.exe"; // Selects most current version + File.Copy(javaEXELocation, javaHome); } else if (Directory.Exists(java64)) // Then Java64 is installed { - string[] java64subdirectories = Directory.GetDirectories(java64); - javaEXELocation = java64subdirectories.Last() + "\\bin\\java.exe"; // Selects most current version + string[] java64Subdirectories = Directory.GetDirectories(java64); + javaEXELocation = java64Subdirectories.Last() + "\\bin\\java.exe"; // Selects most current version File.Copy(javaEXELocation, javaHome); } else { - MessageBox.Show("No java.exe file was found.\n\n" + - "If you do not have Java installed, please download it from Oracle and re-run this program.\n\n" + - "If you installed Java to a non-default directory, " + - "please copy your java.exe file to:\n" + duckyDirectory + " and re-run this program.", - "ERROR: No Java File Found!", + MessageBox.Show(@"No java.exe file was found. + +" + + @"If you do not have Java installed, please download it from Oracle and re-run this program. + +" + + @"If you installed Java to a non-default directory, " + + $@"please copy your java.exe file to: {duckyDirectory} and re-run this program.", + @"ERROR: No Java File Found!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } @@ -312,7 +307,7 @@ private void CheckDirectoryEncoder() using (var client = new WebClient()) { client.Headers.Add("user-agent", "Anything"); - client.DownloadFile(EncoderURL, encoderLocation); + client.DownloadFile(EncoderUrl, encoderLocation); } } } @@ -382,11 +377,13 @@ private void CheckPayloadCount() { HtmlWeb web = new HtmlWeb(); - var htmlDoc = web.Load(PayloadsURL); + var htmlDoc = web.Load(PayloadsUrl); HtmlNode markdownBody = htmlDoc.DocumentNode.SelectSingleNode(@"//*[@id='wiki-body']/div[1]"); int actualScriptCount = 0; + // Script categories foreach (HtmlNode list in markdownBody.Descendants("ul")) { + // Scripts foreach (HtmlNode item in list.ChildNodes) { if (item.NodeType == HtmlNodeType.Element) @@ -395,18 +392,9 @@ private void CheckPayloadCount() } } } - Console.WriteLine(actualScriptCount); - - // var source = _client.DownloadString(PayloadsURL); + DirectoryInfo dir = new DirectoryInfo(duckyDirectory + "\\Scripts\\Default\\"); - // Break Payloads Page into list - - //string[] test = source.Split(test2, StringSplitOptions.RemoveEmptyEntries); - //string tempPage = GetBetween(source, "