Skip to content

Commit

Permalink
chore: format strings, fix move bin button
Browse files Browse the repository at this point in the history
  • Loading branch information
xadamxk committed Aug 13, 2022
1 parent 6ff7fa0 commit 4f75f3f
Showing 1 changed file with 56 additions and 68 deletions.
124 changes: 56 additions & 68 deletions RubberDuckyApp/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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!");
}
}

Expand All @@ -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);
}
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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, "<ul>", "</ul>");
// Count number of items in list
//int actualScriptCount = Regex.Matches(tempPage, "<li>").Cast<Match>().Count();

int downloadedScriptCount = dir.GetFiles().Length;

// Debug Actual & Download Count
Expand All @@ -417,18 +405,20 @@ private void CheckPayloadCount()
}
else
MessageBox.Show(
"ERROR: No Internet Connection!\nPlease connect to the Internet to download Rubber Ducky Payloads.");
@"ERROR: No Internet Connection!
Please connect to the Internet to download Rubber Ducky Payloads.");

}

private void SetPayloads()
{
// Thanks to Mr.Trvp for helping with this method.
//Alert User
MessageBox.Show("Downloading default Ducky Scripts from github.com/hak5darren/USB-Rubber-Ducky.\n" +
"The program will load once they are finished downloading.");
MessageBox.Show(@"Downloading default Ducky Scripts from github.com/hak5darren/USB-Rubber-Ducky.
" +
@"The program will load once they are finished downloading.");
//Load Wiki-Payload Page
var source = _client.DownloadString(PayloadsURL);
var source = _client.DownloadString(PayloadsUrl);
List<string> failedPayloads = new List<string>();

// Each link on Wiki-Payload Page
Expand All @@ -445,8 +435,6 @@ private void SetPayloads()
sanitized = payload.Name.Replace("/", " ").Replace("-", " ");
sanitized = sanitized.SanitizeForFile().Replace("Payload ", "");
sanitized = WebUtility.HtmlDecode(sanitized);
//if (sanitized.Contains("&#39;")) // Fix ' in title
// sanitized = sanitized.Replace("&#39;", "'");
sanitized = Regex.Replace(sanitized, @"(^\w)|(\s\w)", m => m.Value.ToUpper()); // Capitalize each word in title
if (sanitized.StartsWith(" ")) // Remove first char if string starts with a space
sanitized = sanitized.Remove(0, 1);
Expand Down Expand Up @@ -547,8 +535,8 @@ private void button4_Click(object sender, EventArgs e)
private static void PromptInvalidSelection(string item)
{
MessageBox.Show(
"ERROR! Invalid option selected!\n" + item + " is a seperator, not a payload.\n" +
"Please select a valid payload from the Payloads dropdown.");
$@"ERROR! Invalid option selected! {item} is a separator, not a payload.\n" +
@"Please select a valid payload from the Payloads dropdown.");
}

private void comboBox4_MouseHover(object sender, EventArgs e)
Expand All @@ -561,7 +549,7 @@ private void button6_Click(object sender, EventArgs e)
// Eject selected MicroSD
selectedRemovableDrive = selectedRemovableDrive.Trim('\\');
selectedRemovableDrive = selectedRemovableDrive.Trim(':');
char drive = Char.Parse(selectedRemovableDrive);
char drive = char.Parse(selectedRemovableDrive);

try
{
Expand Down

0 comments on commit 4f75f3f

Please sign in to comment.