Poor Man’s Rubber ducky (with something extra)…

Digisparks are very cheap and quite versatile - and they support USB emulation! This is quite a nice property, and I’m sure I’ll release more examples of things I’ve done with this very nice ability.

I have looked at these for a while, but here’s an introductory example. This sketch can be loaded into arduino editor and compiled and sent to the digispark as usual. See here for a tutorial on how to do this.

So here’s what this does:

  1. will emulate a keyboard in the usual way
  2. will ‘type’ a string when plugged in.
  3. will type a different string if a paperclip or something is used to bridge 5v pin hole to p0 pin hole.

May come in handy to someone wanting to have ways of securing devices with long random strings. You can generate random strings with cat /dev/urandom | tr -dc 'a-zA-Z0-9!' | fold -w 128 | head -n 1 but remember that as keys move around (like “ and @ between US/UK keyboards) you can’t add too many symbols to the tr -dc argument.

Hope it’s useful to someone!

#include "DigiKeyboard.h"
#define KEY_UP_ARROW   0x52
#define KEY_DOWN_ARROW   0x51
#define KEY_LEFT_ARROW   0x50
#define KEY_RIGHT_ARROW   0x4F
#define KEY_Tab 43

void setup() {
  pinMode(1, OUTPUT); //LED on Model A 
  pinMode(0, INPUT); // pin zero
}


void loop() {
 digitalWrite(1, HIGH);
 //for(int i=0;i<70;i++){DigiKeyboard.sendKeyStroke(i, MOD_SHIFT_LEFT);delay(500);}
 DigiKeyboard.update();
 delay(1000);
 DigiKeyboard.sendKeyStroke(0); //this is generally not necessary but with some older systems it seems to prevent missing the first character after a delay
 delay(1000);
 // by default pin0 is low. Others, like pin 3, are high, but trying to use them causes issues. The best are pin 0 and pin 1, from my experiementation.
 if (digitalRead(0) == HIGH) {
  // so we bridge with a paperclip from 5v to p0
  // in order to access this program flow...
  // this could be obfuscated or encrypted/encoded to make RevEng harder to a H/W analyst
  DigiKeyboard.println("supersecret"); 
 }
 else {
  // if the pin isn't high, then we just output a friendly warning message:
  DigiKeyboard.println("fluffy kittens");
 }
 digitalWrite(1, LOW);
 delay(6000);
}