15 Dec 2022

Use an ESP32S2 as a Rubberducky AKA BadUSB

Download and install CircuitPython.

Create a file named code.py onto the ESP32S2 with this content:

import usb_hid
import time
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode

time.sleep(1)
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)
cc = ConsumerControl(usb_hid.devices)

layout.write('Hello World!\n') # send string with new-line
#kbd.send(Keycode.SHIFT, Keycode.A)  # Type capital 'A'
#kbd.send(Keycode.CONTROL, Keycode.A)  # control-A key