Introduction: USB Rubber Ducky Script Encoder (VBScript)
If you have a USB Rubber Ducky, you will know that a very annoying task, is compiling your script to a .bin file. If you have to do any sort of debugging, you will know that constant downloading of your compiled script can be a pain. So to fix this problem, I created a VBScript that can compile your code fast and easy.
You can download the compiled .exe and the source code here----------->LINK
Anyway, you are probably wondering how I made such an awesome GUI application in vbs, and if so, skip to step 3.
Step 1: Installing...
There are also instructions on how to do this in the REAMDE.txt file. Anyway, first you must create a folder in your C drive called 'temp' if you do not have one already. Also, if you do not already have java installed, you can get it from here. Next download the duckencode.jar and move the file to your c:\temp folder. Next, extract either one of the .zip files and run Duck.hta in the same directory as 'ico.ico' and 'pic.gif' if you are using the non-compiled version. Or if you are using the compiled .exe, simply run 'Duck.exe'.
Now we can move on to the next step...
Step 2: Usage...
This program is really straightforward, to use it, simply click on 'Paste from clipboard' to automatically paste in your code. Or click on load from text file, to load the script from a text file. Then your code will appear in the text box below. Make any final changes you may want to your code and hit 'Encode'. Navigate to c:\temp and move 'inject.bin' to your USB Rubber Ducky.
You may be wondering what script.txt is. What it is, is the uncompiled code from the text box. It is used as a backup of the raw code.
NOTE: If you want to make a small script, you could simply just type in your code in the text box. A fast and easy way to test out your USB Rubber Ducky.
Skip to the next step if you want to find out more about how GUIs in vbs and how this program was made, otherwise:
Thanks for reading this instructable, and if you have any questions, comments, or concerns, please post a comment or pm me.
Step 3: GUIs in VBScript
So yeah, it is possible to make GUIs in vbs. The way you do it, is by wrapping your text in a HTA. Incase you don't already know, HTA is a scripting language very similar to html used simply to wrap scripts such as vbscripts and jscripts in a GUI. Detailed explanation and tutorial here.
So now that you know what hta is, let me give you some tips on how to easily make theses. First download the HTA helpomatic (pic 2) from here. Unfortunately the original link no longer works, but luckily I saved a copy a while back. Next download and install vbsedit, which comes with htaedit.
After you have these two programs, you really need no html/hta experience to start making GUIs. Which is great for people like me, who don't want to learn hta just to make GUIs.
Now move on to the next step to see how I made the Duck Encoder...
Step 4: How I Made It
ID="DuckEncoder" VERSION="1.0" BORDER="dialog" INNERBORDER="no" MAXIMIZEBUTTON="no" ICON="ico.ico" SCROLL="no"
This sets up a few things such as the icon, border type, ect.
self.resizeTo 400, 454 Dim objFso : Set objFso = CreateObject("Scripting.FileSystemObject") If Not objFso.FileExists("c:\temp\duckencode.jar") Then MsgBox "Error, file not found: c:\temp\duckencode.jar",16,"Duck Encoder" Self.close() End If End Sub
Next, this sub, runs automatically whenever the program is first launched. What it does is resize the window then check to make sure that 'duckencode.jar' is in the correct directory.
Sub OnClickButtonbtnLoad() Dim objShlApp, objFolderLocation, strFileLocation, objFso, objFolder, colFiles, strTextFileList, objFile Dim strCompleteText Set objFso = CreateObject("Scripting.FileSystemObject") Set objShlApp = CreateObject("Shell.Application") On Error Resume Next Set objFolderLocation = objShlApp.BrowseForFolder(0, "Browse for folder containing the file: ",16384,0) If Err.Number <> 0 Then MsgBox "You must select the FOLDER containing the file.",16,"Duck Encoder" Err.Clear() Else If objFolderLocation = "" Then Exit Sub On Error Goto 0 Set objFolder = objFso.GetFolder(objFolderLocation.Self.Path & "\") Set colFiles = objFolder.Files strTextFileList = "" For Each objFile In colFiles If InStr(objFile.Name,".txt") <> False Then strTextFileList = strTextFileList & objFile.Name & vbCrLf End If Next strFileLocation = InputBox("Please enter the correct text file you wish to encode: " & vbCrLf & vbCrLf & strTextFileList,"Ducky Encoder") If Not IsEmpty(strFileLocation) Then If Not objFso.FileExists(objFolderLocation.Self.Path & "\" & strFileLocation) Then MsgBox "Error, you must choose a text file from the list!",16,"Duck Encoder" Else On Error Resume Next strFileLocation = objFolderLocation.Self.Path & "\" & strFileLocation Set objFile = objFso.OpenTextFile(strFileLocation,1,FALSE) txtScript.Value = objFile.ReadAll objFile.Close() If Err.Number <> 0 Then MsgBox "Text file is empty.",16,"Duck Encoder" End If End If End If End if End Sub
Ok, this part of the code is really confusing, this is the code for when the user clicks on 'Load from text file'. Since it is practically impossible to make a open-file dialog in hta, The program pops-up a browse for folder dialog to ask the user to select the folder containing the script file. Then the program opens up an inputbox asking the user which text file to load inside that folder. Then the program reads whatever is inside the file and puts it in the text box.
Dim objHTML, ClipboardText Set objHTML = CreateObject("htmlfile") ClipboardText = objHTML.ParentWindow.ClipboardData.GetData("text") If IsNull(ClipboardText) = True Then MsgBox "Nothing in the clipboard!",16,"Duck Encoder" Else txtScript.Value = ClipboardText End If End Sub
All this code does, is when the user clicks on 'Paste from clipboard', the program loads the text from the clipboard to the text box.
Step 5: How I Made It (part 2)
Sub OnClickButtonbtnEncode()<br> If txtScript.Value = "" Then MsgBox "There is no code!",16,"Duck Encoder" Else Dim objFso, txtScriptFile Set objFso = CreateObject("Scripting.Filesystemobject") Set txtScriptFile = objFso.OpenTextFile("c:\temp\script.txt",2,True) txtScriptFile.WriteLine(txtScript.Value) txtScriptFile.Close() idTimer = window.setTimeout("Compile", 800, "VBScript") End If End Sub Sub Compile() window.clearTimeout(idTimer) Dim objWshShl : Set objWshShl = CreateObject("WScript.Shell") objWshShl.Run "java.exe -jar c:\temp\duckencode.jar -i c:\temp\script.txt -o c:\temp\inject.bin",0 'MsgBox "Script compiled to inject.bin in c:\temp",vbOKOnly+vbInformation,"Ducky Encoder" End Sub
This code is run when you click on 'Encode'.
What it does is creates a text file called script.txt and puts whatever is inside the textbox to it. Then it waits 0.8 seconds and then compiles it.
The rest of the code just creates the GUI. It's pretty self-explanatory if you know basic hta.
We have a be nice policy.
Please be positive and constructive.