{"id":18906676,"url":"https://github.com/valentinlibouton/pizerokeystrokesinjection","last_synced_at":"2026-05-06T11:38:13.680Z","repository":{"id":168384256,"uuid":"596347150","full_name":"ValentinLibouton/PiZeroKeystrokesInjection","owner":"ValentinLibouton","description":"This project allows to inject keystrokes such as a keyboard in an automated way like the Rubber Ducky from Hak5.org does","archived":false,"fork":false,"pushed_at":"2023-04-17T08:07:03.000Z","size":389,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-01T00:21:16.107Z","etag":null,"topics":["hak5","hak5-ducky","keystroke-injection","linux","pi-zero-w","raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ValentinLibouton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-02T01:26:14.000Z","updated_at":"2024-09-25T13:56:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"63c4db9e-455d-4d99-8230-0a7d0f21a99c","html_url":"https://github.com/ValentinLibouton/PiZeroKeystrokesInjection","commit_stats":null,"previous_names":["valentinlibouton/pizerokeystrokesinjection"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ValentinLibouton/PiZeroKeystrokesInjection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ValentinLibouton%2FPiZeroKeystrokesInjection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ValentinLibouton%2FPiZeroKeystrokesInjection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ValentinLibouton%2FPiZeroKeystrokesInjection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ValentinLibouton%2FPiZeroKeystrokesInjection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ValentinLibouton","download_url":"https://codeload.github.com/ValentinLibouton/PiZeroKeystrokesInjection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ValentinLibouton%2FPiZeroKeystrokesInjection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32692623,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T08:33:17.875Z","status":"ssl_error","status_checked_at":"2026-05-06T08:33:17.221Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hak5","hak5-ducky","keystroke-injection","linux","pi-zero-w","raspberry-pi"],"created_at":"2024-11-08T09:18:21.187Z","updated_at":"2026-05-06T11:38:13.661Z","avatar_url":"https://github.com/ValentinLibouton.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PiZeroKeystrokesInjection\nThis project allows to inject keystrokes such as a keyboard in an automated way like the Rubber Ducky from Hak5.org does\n\n![image of a duck with a raspberry](https://github.com/ValentinLibouton/PiZeroKeystrokesInjection/blob/bd96f7e9aaae284f0932438f2e56a36b56301500/images/raspduck.png?raw=true)\n\n## Contents \n- [Usage](#usage)\n- [Examples](#examples)\n- [Prerequisites](#prerequisites)\n- [Pi Zero setup](#pi-zero-setup)\n- [Options](#options)\n\n## Usage\nList of commands that can be used in command_file.txt:\n\n- `STRING`  The string following this command will be typed on the keyboard\n- `DELAY`   The number after this command is the pause delay in second\n- `WRITE`   The filename following this command will be read and typed entirely on the keyboard. Here no need to put a \"STRING\" command.\n- `#`       This entire line will be ignored at runtime. Lines beginning with # are intended for your comments. Can also be used as a log via SSH.\n- `REPLAY` The first number following the REPLAY command is the number of repeats and the second number is the number of rows to repeat\n- you can also use other keystrokes such as `CTRL_LEFT ALT_LEFT DELETE` you just need to leave a space between each command.\n\nList of all specific commands:\n`CTRL_LEFT` `SHIFT_LEFT` `ALT_LEFT` `WIN` `CTRL_RIGHT` `SHIFT_RIGHT` `ALT_RIGHT` `ENTER` `ESCAPE` `BACK` `TAB` `SPACE` `CAPS_LOCK` `F1` `F2` `F3` `F4` `F5` `F6` `F7` `F8` `F9` `F10` `F11` `F12` `PRINT_SCREEN` `SCROLL_LOCK` `PAUSE` `INSERT` `HOME` `PAGE_UP` `DELETE` `END` `PAGE_DOWN` `RIGHT_ARROW` `LEFT_ARROW` `DOWN_ARROW` `UP_ARROW` `NUM_LOCK` `MENU`\n\n## Examples\n- ´STRING Hello World! @#123_°(`\n```bash\nHello World! @#123_°(\n```\n- `DELAY 3`\n- `WRITE example_file.txt` This example is available in the root\n```bash\nfor i in range(10):\n    print(\"Hello World\", i)\nrtfm = True\n\n```\n- `# This is a comment`\n- `REPLAY 2 6` replay the last 6 lines twice\n- `CTRL_LEFT s`\n- `CTRL_LEFT ALT_LEFT t`\n- `CTRL_LEFT ALT_LEFT DELETE`\n- `ALT_LEFT TAB`\n\n## Prerequisites\n### Hardware\nRaspberry Pi Zero with WiFi for file transfer via SSH\n### Software\n1. Configure WiFi and keyboard via:\n```bash\nsudo raspi-config\n```\n2. Setup Pi Zero\n\n- See **Pi Zero setup** chapter below\n\n3. Copy files projetc on Pi via SSH:\n\n- conversion.py\n- run_keystrokes.py\n\n5. Write you scrypt and copy on Pi via SSH:\n\n- command_file.txt\n\n\n## Pi Zero setup\n\n### Sources\nhttps://randomnerdtutorials.com/raspberry-pi-zero-usb-keyboard-hid/\n\n### Installation according to the original source\n#### 1 - Enabling Modules and Drivers\nThese next steps to prepare the Pi Zero board are based on the instructions from iSticktoit. First, you need to run these three commands to enable the necessary modules and drivers:\n```bash\necho \"dtoverlay=dwc2\" | sudo tee -a /boot/config.txt\necho \"dwc2\" | sudo tee -a /etc/modules\nsudo echo \"libcomposite\" | sudo tee -a /etc/modules\n```\n#### 2 - Configuring the Gadget\nNow, you have to define your Pi Zero (HID gadget) as a USB keyboard. The configuration is done via ConfigFS, a virtual file system located in /sys/.\n##### 2.1 - Creating the config script\nThe configuration is volatile, so it must run on each startup. Create a new file called isticktoit_usb in /usr/bin/ and make it executable:\n```bash\nsudo touch /usr/bin/isticktoit_usb\nsudo chmod +x /usr/bin/isticktoit_usb\n```\nThen, you need to run this script automatically at startup. Open /etc/rc.local with this command:\n```bash\nsudo nano /etc/rc.local\n```\nAdd the following before the line containing exit 0:\n```bash\n/usr/bin/isticktoit_usb # libcomposite configuration\n```\n#### 3 - Creating the gadget\nFor this project, we will turn the Raspberry Pi into a USB keyboard, but you could make it work as a Serial adapter, Ethernet adapter, and Mass Storage. Open the file with:\n```bash\nsudo nano /usr/bin/isticktoit_usb\n```\nLeave the default values, but you could even change the serial number, manufacturer and product name to fit your specific needs.\n```bash\n#!/bin/bash\ncd /sys/kernel/config/usb_gadget/\nmkdir -p isticktoit\ncd isticktoit\necho 0x1d6b \u003e idVendor # Linux Foundation\necho 0x0104 \u003e idProduct # Multifunction Composite Gadget\necho 0x0100 \u003e bcdDevice # v1.0.0\necho 0x0200 \u003e bcdUSB # USB2\nmkdir -p strings/0x409\necho \"fedcba9876543210\" \u003e strings/0x409/serialnumber\necho \"Tobias Girstmair\" \u003e strings/0x409/manufacturer\necho \"iSticktoit.net USB Device\" \u003e strings/0x409/product\nmkdir -p configs/c.1/strings/0x409\necho \"Config 1: ECM network\" \u003e configs/c.1/strings/0x409/configuration\necho 250 \u003e configs/c.1/MaxPower\n\n# Add functions here\nmkdir -p functions/hid.usb0\necho 1 \u003e functions/hid.usb0/protocol\necho 1 \u003e functions/hid.usb0/subclass\necho 8 \u003e functions/hid.usb0/report_length\necho -ne \\\\x05\\\\x01\\\\x09\\\\x06\\\\xa1\\\\x01\\\\x05\\\\x07\\\\x19\\\\xe0\\\\x29\\\\xe7\\\\x15\\\\x00\\\\x25\\\\x01\\\\x75\\\\x01\\\\x95\\\\x08\\\\x81\\\\x02\\\\x95\\\\x01\\\\x75\\\\x08\\\\x81\\\\x03\\\\x95\\\\x05\\\\x75\\\\x01\\\\x05\\\\x08\\\\x19\\\\x01\\\\x29\\\\x05\\\\x91\\\\x02\\\\x95\\\\x01\\\\x75\\\\x03\\\\x91\\\\x03\\\\x95\\\\x06\\\\x75\\\\x08\\\\x15\\\\x00\\\\x25\\\\x65\\\\x05\\\\x07\\\\x19\\\\x00\\\\x29\\\\x65\\\\x81\\\\x00\\\\xc0 \u003e functions/hid.usb0/report_desc\nln -s functions/hid.usb0 configs/c.1/\n# End functions\n\nls /sys/class/udc \u003e UDC\n```\n#### 4 - Python Script (Change according to personal use)\n* After preparing your Raspberry Pi Zero, connect it to a laptop or desktop computer through the micro USB port that is used for data and peripherals. That micro USB will both power the Pi Zero and act as a keyboard to the connected computer.\n* Establish an SSH connection with your Pi and use the next command to create a new Python script:\n  ```bash\n  nano RPi_Keyboard_Example.py\n  ```\n* Copy and paste the next Python script to your Raspberry Pi.\n  ```bash\n  #!/usr/bin/env python3\n  NULL_CHAR = chr(0)\n\n  def write_report(report):\n      with open('/dev/hidg0', 'rb+') as fd:\n          fd.write(report.encode())\n\n  # Press a\n  write_report(NULL_CHAR*2+chr(4)+NULL_CHAR*5)\n  # Release keys\n  write_report(NULL_CHAR*8)\n  # Press SHIFT + a = A\n  write_report(chr(32)+NULL_CHAR+chr(4)+NULL_CHAR*5)\n\n  # Press b\n  write_report(NULL_CHAR*2+chr(5)+NULL_CHAR*5)\n  # Release keys\n  write_report(NULL_CHAR*8)\n  # Press SHIFT + b = B\n  write_report(chr(32)+NULL_CHAR+chr(5)+NULL_CHAR*5)\n\n  # Press SPACE key\n  write_report(NULL_CHAR*2+chr(44)+NULL_CHAR*5)\n\n  # Press c key\n  write_report(NULL_CHAR*2+chr(6)+NULL_CHAR*5)\n  # Press d key\n  write_report(NULL_CHAR*2+chr(7)+NULL_CHAR*5)\n\n  # Press RETURN/ENTER key\n  write_report(NULL_CHAR*2+chr(40)+NULL_CHAR*5)\n\n  # Press e key\n  write_report(NULL_CHAR*2+chr(8)+NULL_CHAR*5)\n  # Press f key\n  write_report(NULL_CHAR*2+chr(9)+NULL_CHAR*5)\n\n  # Release all keys\n  write_report(NULL_CHAR*8)\n  ```\n#### 5 - Test\nLet’s test it, if you plug the Pi Zero to Computer #1, after a few seconds you’ll see an alert message or sound that indicates that a keyboard was connected successfully.\n\nSometimes you might see this warning message saying “USB device not recognized”. Throughout my tests, I found that you can ignore this warning message and your Pi Zero works as a keyboard without any additional configuration or drivers installation. So, you can continue and it will work just fine.\n* Computer N°1: Open any text editor program and leave your cursor in the new file:\n* Computer N°2: Establish an SSH connection with your Pi Zero and run the Python script created earlier:\n  ```bash\n  sudo python3 RPi_Keyboard_Example.py\n  ```\n* Computer N°1: The text editor has been filled\n\n\n## Options\n\n### Automatic execution of keystrokes at boot\n- `1` Copy *autostart.sh* in /home/pi/ directory\n- `2` Copy *autostart.service* in /lib/systemd/system/ directory\n- `3` Run the following commands:\n```bash\n  sudo chmod +x /home/pi/autostart.sh\n  sudo chmod 644 /lib/systemd/system/autostart.service\n  sudo systemctl daemon-reload\n  sudo systemctl enable autostart.service\n  sudo reboot\n```\nIf you want to prevent autorun on startup, you can comment out the last line of autostart.sh with `#`\n```bash\n  # python3 /home/pi/run_keystrokes.py\n  ```\n### Run once at boot\nFollow the **Automatic execution of keystrokes at boot** procedure and proceed with one of the examples below:\nFor example add at the end of *autostart.sh*:\n```bash\nrm /home/pi/command_file.txt\n```\nor\n```bash\nmv /home/pi/command_file.txt /home/pi/command_file.txt.bak\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalentinlibouton%2Fpizerokeystrokesinjection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalentinlibouton%2Fpizerokeystrokesinjection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalentinlibouton%2Fpizerokeystrokesinjection/lists"}