Using the Digispark as a cheap USB Rubber Ducky
Tags: digispark, arduino, pentest, experiment
Published: 2019-04-05 20:40:44

---
title: "Using the Digispark as a cheap USB Rubber Ducky"
published: true
description: 
tags: [ "digispark", "arduino", "pentest", "experiment" ]
canonical_url: https://eysermans.com/post/using-the-digispark-as-a-cheap-usb-rubber-ducky
---
**Disclaimer: This post is for fun, learning and experimenting. Use these tools wisely, in no way am I encouraging malicious use of them.**

Originally posted on the 5th of april 2019 on my [own blog](https://eysermans.com/post/using-the-digispark-as-a-cheap-usb-rubber-ducky).

Last week I came across an interesting device, the [USB Rubber Ducky](https://shop.hak5.org/products/usb-rubber-ducky-deluxe). It looks like a normal USB stick but when you plug it into a computer, it emulates  a keyboard. You can load a script onto the Rubber Ducky and it will execute them as keystrokes on the computer where the stick is plugged in. Because it executes more than 1000 words per minute, the possibilities are  endless from running pentest task to malicious things like installing a backdoor.

I wanted to play around with it but unfortunately shipping the stick to Europe/Belgium costs almost as much as the stick. Luckily there is a [post on Hackernoon on how to make your own USB Rubber Ducky with a Digispark](https://hackernoon.com/low-cost-usb-rubber-ducky-pen-test-tool-for-3-using-digispark-and-duck2spark-5d59afc1910). The [Digispark](http://digistump.com/products/1) is similar to the Arduino but it's cheaper, smaller and less powerful. The end result actually looks better because it is much smaller than the Rubber Ducky. One drawback, the Digispark does not have a micro SD slot so there is no disk space to use.

<img src="https://eysermans.com/images/articles/using-the-digispark-as-a-cheap-usb-rubber-ducky/digispark-up-close.jpg" alt="Digispark up close" style="width: 50%" />

Here is it next to a pen. I'm still amazed how small it is.

<img src="https://eysermans.com/images/articles/using-the-digispark-as-a-cheap-usb-rubber-ducky/digispark-vs-pen.jpg" alt="Digispark VS pen" style="width: 50%" />

Buying these low budget components can be challenging. I have the impression that they are much easier and cheaper to get in the States. In some cases there are alternatives on [Amazon Germany](https://www.amazon.de/). But the Digispark was too cheap and shipping costs were too high. Eventually I found them on a [local webshop](https://www.conrad.be/p/joy-it-arduino-uitbreidingsprintplaat-digispark-microcontroller-1503743) for 6,49 €. I needed some other things so I could reduce the shipping costs.

To get started there are a lot of resources on the internet. But most of the scripts and blog posts are targeted for Windows. However I found an excellent blog post with a hello world example on [how to set up the Digispark as a Rubber Ducky on Mac OS X](https://pennsylforniageek.tumblr.com/post/169014885841/how-to-setup-and-run-the-digispark-attiny85-as). This is the hello world script that will be used:

```
#include "DigiKeyboard.h"

boolean didRun = false;

void setup() {}

void loop() {
  while (didRun == false) {
    DigiKeyboard.sendKeyStroke(KEY_SPACE, MOD_GUI_LEFT);
    DigiKeyboard.delay(500);
    DigiKeyboard.println("terminal");
    DigiKeyboard.delay(500);
    DigiKeyboard.println("say Hello World");
    didRun = true;
  }
}
```

This script uses the default shortcut to activate Spotlight, types `terminal` and hits enter. This should open the terminal, after waiting half a second it types and executes the command `say Hello World`. When I tried uploading this script via the Arduino IDE, it could never find my Digispark. 

<img src="https://eysermans.com/images/articles/using-the-digispark-as-a-cheap-usb-rubber-ducky/apple-adapter.jpg" alt="Apple USB tp USB-C adapter" style="width: 50%" />

I was using an Apple USB to USB-C adapter to connect the Digispark to my Macbook pro. After some googling I discovered that the middle pins in the USB connector of the Digispark are quite short and that in some cases it won't connect properly. After digging up a USB extension cable the Digispark connected and the script uploaded.

<img src="https://eysermans.com/images/articles/using-the-digispark-as-a-cheap-usb-rubber-ducky/usb-cable.jpg" alt="USB extension cable" style="width: 50%" />

So if the device is now inserted in a target machine, the script will run. While testing the hello world script I realized there is quite a lot that can go wrong:

- What if the Spotlight key shortcut has been changed?
- On my laptop, when typing `terminal` in Spotlight another file was the top result. As a result, the script did absolutely nothing.
- When testing the script in computer with an azerty keyboard layout, the characters were typed with a qwerty keyboard layout.

But in the end, it did work. The script ran within seconds from a device similar in size as a coin. Pretty cool. While doing some research, I found quite a lot of other resources and example scripts. Making a laptop saying Hello World is just the tip of the iceberg. Some more resources:

- [A collection of all kinds of Digispark scripts](https://github.com/topics/digispark-scripts)
- [Bash Bunny, similar product to the USB Rubber Ducky](https://shop.hak5.org/products/bash-bunny)
- [duck2spark, converting Rubber Ducky payloads to Digispark](https://github.com/mame82/duck2spark/)
- [digiQuack, another DuckyScript to Digispark payload converter](https://cedarctic.github.io/digiQuack/)