Master of Teaching | OISE @ UofT
A 'rubber ducky' is the name for a device that emulates a physical keyboard and can deliver a payload of keyboard inputs to a computer via USB at incredible speeds (milliseconds). In the video above, I wrote some C++ code to my arduino leonardo that would open a web URL using the terminal on a Mac. This is just a small demo of what is possible with a rubber ducky device, considering that they are commonly used for more nefarious reasons than what I've shown. Below I will leave the code for this project but you can also access it from my GitHub, the device has an added switch so you can plug it into a non-target computer to upload rubber ducky programs safely.
#include <Keyboard.h>
void setup() {
pinMode(2, INPUT_PULLUP); // on-off button
pinMode(13, OUTPUT); // built-in LED
Serial.begin(9600);
Keyboard.begin();
// layout(KeyboardLayout_en_US)
}
bool attack = false;
String URL = "'https://c.tenor.com/485H8xylTloAAAAd/tenor.gif'";
void loop() {
if (digitalRead(2) == 1) {
AbortAttack();
} else {
if (attack == false) {
attack = true; // assures attack only runs once
delay(500);
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(' ');
delay(200);
Keyboard.release(KEY_LEFT_GUI);
Keyboard.release(' ');
delay(200);
Keyboard.println("terminal");
delay(500);
Keyboard.println("open " + URL);
Keyboard.end();
}
}
}
void AbortAttack() { // blinks until switch is flipped
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}