ScriptBox

Introduction: ScriptBox

ScriptBox is an arduino based device, recognized by the computer as a keyboard, which can be used for keystroke injection.

The advantages of using the ScriptBox are:

  • You can use a pin to unlock the ScriptBox so only you can use it
  • You can have as many scripts as you want
  • You can visualize the current status of your ScriptBox (running, error, standby etc.) with the help of the RGB Led

Step 1: Parts Needed to Make the ScriptBox

If you want to build you own ScriptBox, you will need the following parts:

  • Arduino Pro Micro
  • MicroSd Module
  • 1x4 Keypad
  • RGB Led - Common Cathode
  • 3 x 330 Ohm Resistor ( I have used 220 Ohm Resistor, but the light emitted by the RGB Led it's to powerfull and uncomfortable
  • 3D Printed Box (more info will be provided)
  • MicroSD card

Step 2: Connections Diagram

I've made the following connections:

  • 1x4 Keypad - Arduino Pro Micro

pin 1 with pin 2

pin 2 with pin 3

pin 3 with pin 4

pin 4 with pin 5

pin 5 with GND

  • RGB Led - Arduino Pro Micro

GND with GND

The 3 pins from the RGB Led (using the resistors - see diagram) with 18, 19, 20 (A0, A1, A2) pins of Arduino.

Note: If you can't find the correct order to connect the pins, the RGB Led will represent different states of ScriptBox with colors different from the ones I choose. For example: Instead of showing a red light when pin was wrong, it will show a blue light. To fix this you have 2 choices:

1. Modify the initialization of the RGB Led pins in the code from Step 4(suggested):

// RGB Led pins
int redPin = 18;
int greenPin = 19;
int bluePin = 20;

So, if you have blue color when pin was wrong instead for red, you can change to this setup:

// RGB Led pins
int redPin = 20;
int greenPin = 19;
int bluePin = 18;

2. Try to find the right pin connection order

  • MicroSD Module - Arduino Pro Micro:

GND with GND

VCC with VCC

MISO with MISO (pin 14)

MOSI with MOSI (pin 16)

SCK with SCLK (pin 15)

CS with pin 7

Step 3: 3D Printed Box

Regarding the 3D Printed Box, you can:

  • make it yourself by using a CAD Software
  • download the model I created from OnShape website. Just create an account and then click on Public and search for ScriptBox or click the following link to get there in a blink of an eye:

OnShape ScriptBox Model

  • go to my GitHub account ScriptBox, and download the drawings from the "drawings" folder (step or iges format).
  • download drawings form Step 6.

Note: If you get the model from OnShape make sure two export only the "Bottom Case" and "Top Case" parts!

Step 4: Code

ScriptBox

/**
* The bellow scheme is used to identify what pin
* declaration corresponds to the pressed key.
* --------------------------------------------------
* For Example:
* To run a script by pressing "1234" the name of the
* script needs to be "2301.txt"
* --------------------------------------------------
* Pin declaration - Key pressed - Keypad wire number:
* 0 3 2
* 1 4 5
* 2 1 4
* 3 2 3
*/
// Keyboard declarations:
#include
#include
#include
#include "Keyboard.h"
File myFile;
boolean first = true;
String fileName = "";
void typeKey(uint8_t key) {
Keyboard.press(key);
delay(50);
Keyboard.release(key);
}
// RGB Led pins
int redPin = 18;
int greenPin = 19;
int bluePin = 20;
// Keypad declarations:
// Boolean for checking if the entered pin was correct
bool pin_accepted = false;
// set pin numbers
int buttonPin[] = {2, 3, 4, 5};
// read the push buttons
int buttonState = LOW;
int lastButtonState = HIGH;
// Length of the pin
int input_pin[] = {9, 9, 9, 9, 9};
// Current pin to unlock/access the scripts
int pin[] = {1, 1, 1, 1, 1};
// Input length
int input_length = 0;
// Set RGB Led color
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
// Get key pressed from keypad
void getKey (int x) {
input_pin[input_length] = x;
input_length++;
Serial.print(x);
}
// Read keypad command - command_length it's equal to number of pressed keys
void readKeypad (int command_length) {
for(int x=0; x
// read the button state
buttonState = digitalRead(buttonPin[x]);
// if the buttonState is LOW (pressed) record it
if (buttonState == LOW && buttonPin[x] == 2) {
if (buttonState != lastButtonState) {
getKey(x);
delay(50);
break;
} else {
break;
}
}
if (buttonState == LOW && buttonPin[x] == 3) {
if (buttonState != lastButtonState) {
getKey(x);
delay(50);
break;
} else {
break;
}
}
if (buttonState == LOW && buttonPin[x] == 4) {
if (buttonState != lastButtonState) {
getKey(x);
delay(50);
break;
} else {
break;
}
}
if (buttonState == LOW && buttonPin[x] == 5) {
if (buttonState != lastButtonState) {
getKey(x);
delay(50);
break;
} else {
break;
}
}
}
lastButtonState = buttonState;
}
// Check if the input command match the given command
void matchCommand(int command_length, int input_command[], int static_command[]) {
for(int x=0; x<=command_length; x++) {
input_length = x;
if(input_command[x] != static_command[x]) {
input_length = 0;
Serial.print("\n Wrong pin! \n");
setColor(255, 0, 0); // red
delay(2000);
setColor(0, 0, 255); // blue
break;
}
}
}
void Line(String l)
{
int space_1 = l.indexOf(" ");
if (space_1 == -1)
{
Press(l);
}
else if (l.substring(0,space_1) == "STRING")
{
Keyboard.print(l.substring(space_1 + 1));
}
else if (l.substring(0,space_1) == "DELAY")
{
int delaytime = l.substring(space_1 + 1).toInt();
delay(delaytime);
}
else if(l.substring(0,space_1) == "REM"){}
else
{
String remain = l;
while(remain.length() > 0)
{
int latest_space = remain.indexOf(" ");
if (latest_space == -1)
{
Press(remain);
remain = "";
}
else
{
Press(remain.substring(0, latest_space));
remain = remain.substring(latest_space + 1);
}
delay(5);
}
}
Keyboard.releaseAll();
}
void Press(String b)
{
if(b.length() == 1)
{
char c = b[0];
Keyboard.press(c);
}
else if (b.equals("ENTER"))
{
Keyboard.press(KEY_RETURN);
}
else if (b.equals("CTRL"))
{
Keyboard.press(KEY_LEFT_CTRL);
}
else if (b.equals("SHIFT"))
{
Keyboard.press(KEY_LEFT_SHIFT);
}
else if (b.equals("ALT"))
{
Keyboard.press(KEY_LEFT_ALT);
}
else if (b.equals("GUI"))
{
Keyboard.press(KEY_LEFT_GUI);
}
else if (b.equals("UP") || b.equals("UPARROW"))
{
Keyboard.press(KEY_UP_ARROW);
}
else if (b.equals("DOWN") || b.equals("DOWNARROW"))
{
Keyboard.press(KEY_DOWN_ARROW);
}
else if (b.equals("LEFT") || b.equals("LEFTARROW"))
{
Keyboard.press(KEY_LEFT_ARROW);
}
else if (b.equals("RIGHT") || b.equals("RIGHTARROW"))
{
Keyboard.press(KEY_RIGHT_ARROW);
}
else if (b.equals("DELETE"))
{
Keyboard.press(KEY_DELETE);
}
else if (b.equals("PAGEUP"))
{
Keyboard.press(KEY_PAGE_UP);
}
else if (b.equals("PAGEDOWN"))
{
Keyboard.press(KEY_PAGE_DOWN);
}
else if (b.equals("HOME"))
{
Keyboard.press(KEY_HOME);
}
else if (b.equals("ESC"))
{
Keyboard.press(KEY_ESC);
}
else if (b.equals("INSERT"))
{
Keyboard.press(KEY_INSERT);
}
else if (b.equals("TAB"))
{
Keyboard.press(KEY_TAB);
}
else if (b.equals("END"))
{
Keyboard.press(KEY_END);
}
else if (b.equals("CAPSLOCK"))
{
Keyboard.press(KEY_CAPS_LOCK);
}
else if (b.equals("F1"))
{
Keyboard.press(KEY_F1);
}
else if (b.equals("F2"))
{
Keyboard.press(KEY_F2);
}
else if (b.equals("F3"))
{
Keyboard.press(KEY_F3);
}
else if (b.equals("F4"))
{
Keyboard.press(KEY_F4);
}
else if (b.equals("F5"))
{
Keyboard.press(KEY_F5);
}
else if (b.equals("F6"))
{
Keyboard.press(KEY_F6);
}
else if (b.equals("F7"))
{
Keyboard.press(KEY_F7);
}
else if (b.equals("F8"))
{
Keyboard.press(KEY_F8);
}
else if (b.equals("F9"))
{
Keyboard.press(KEY_F9);
}
else if (b.equals("F10"))
{
Keyboard.press(KEY_F10);
}
else if (b.equals("F11"))
{
Keyboard.press(KEY_F11);
}
else if (b.equals("F12"))
{
Keyboard.press(KEY_F12);
}
else if (b.equals("SPACE"))
{
Keyboard.press(' ');
}
}
void setup() {
// Keyboard setup:
// Begining the Keyboard stream
Keyboard.begin();
// Wait 500ms
delay(500);
// Keypad setup:
// initialize the keypad pin(s) as an input
for(int x=0; x<4; x++) {
pinMode(buttonPin[x], INPUT_PULLUP);
}
// SD Card setup:
if (!SD.begin(7)) {
Serial.print("Card could not be initialized");
return;
}
// Set blue color after initialization
setColor(0, 0, 255);
// initialize the Serial Monitor @ 9600
Serial.begin(9600);
}
void loop(){
if (!pin_accepted) {
// Read pin
readKeypad(4);
if (input_length == 5) {
// Check if pin is correct
matchCommand(4, input_pin, pin);
if(input_length == 4) {
pin_accepted = true;
input_length = 0;
Serial.print("\n Code accepted \n");
// Set green color
setColor(0, 255, 0);
}
}
} else {
// Read command
readKeypad(4);
if (input_length == 4) {
input_length = 0;
for(int x=0; x<4; x++) {
fileName += input_pin[x];
}
fileName += ".txt";
// Open file from SD
myFile = SD.open(fileName);
if (myFile) {
Serial.print("\n File opened \n");
setColor(255, 0, 255); // purple
String line = "";
while (myFile.available()) {
char m = myFile.read();
if (m == '\n'){
Line(line);
line = "";
}
else if((int) m != 13)
{
line += m;
}
}
Line(line);
myFile.close();
setColor(0, 255, 0); // green
} else {
Serial.print("\n File not found! \n");
setColor(255, 0, 0); // red
delay(2000);
setColor(0, 255, 0); // green
}
fileName = "";
}
}
}
view rawScriptBox hosted with ❤ by GitHub

Step 5: How to Use It.

After making all connections, to test your ScriptBox follow this steps:

  • Insert the MicroSD card into your computer and create a .txt file with the name 1234.txt (the names of the scripts need to contains numbers from 1 to 4, and all scripts names need to be 4 numbers long)
  • Insert the MicroSD card into the MicroSD Module and connect the Arduino Pro Micro to the laptop using an USB cable
  • The RGB Led should turn blue
  • First of all you need to enter the pin, which is 5 numbers long, so you can access your scripts.The default pin is 11111. To change the pin you need to modify it in "main.ino" file:

// Current pin to unlock/access the scripts
int pin[] = {1, 1, 1, 1, 1};
  • After this you can press 1234 and your script will be executed
  • Script example:
    • Name: 1234.txt
    • Content:
DELAY 2000<br>GUI r
DELAY 500
STRING notepad
DELAY 2000
ENTER
DELAY 750
STRING It works!
ENTER
  • Many of the Rubber Ducky scripts are compatible with this or need little adjustments.

Step 6: Download Section


Share

    Recommendations

    • Tiny Home Contest

      Tiny Home Contest
    • Metalworking Contest

      Metalworking Contest
    • Water Contest

      Water Contest

    2 Discussions