BadUSB and DuckyScript: Writing, Testing and Defending Against Keystroke Injection
Topics: BadUSB blue team detection engineering DuckyScript keystroke injection USB device control USB Rubber Ducky USBGuard
- Courses taught
- 189
- Learners reached
- 854
- Reviews received
- 210
Plus opens every Plus course and puts the shield on your name. From USD 5 a month.
Join PlusAlready a member? Sign in
Requirements
- Comfort with the Windows and Linux command line
- A computer able to run two virtual machines with USB passthrough
- Administrator rights on your own lab VMs
- Only computers you own or are authorised in writing to test
About this course
A KSEC course on keystroke injection: how a small USB device posing as a keyboard can type into a computer, how to write and test harmless demonstration payloads for it on your own lab, and above all how to stop and detect it.
It starts with authorised use and a two virtual machine lab, then explains why computers trust keyboards and why timing and keyboard layout decide whether a script works. You write the same benign tests (a marker line, the calculator, a lock key, a banner) for the USB Rubber Ducky, the Flipper Zero Bad USB app and the Evil Crow cables, and learn where their syntax differs. The defensive half applies device control on Windows and Linux, closes the physical gaps, logs every new keyboard, joins it to the process that followed, measures inhuman typing and proves each detection with your own tests. It ends with incident response, a one page test report and a capstone that runs the whole loop.
Everything is done on computers you own, or are authorised in writing to test, and the first topic requires an acknowledgement of that before you continue. No lesson contains a payload that steals credentials, exfiltrates data, evades security tools, persists or targets anyone else’s system: the scripts are harmless demonstrations and the defender’s own commands.
Get the kit
The USB Rubber Ducky and the Evil Crow Cable, Cable Pro and Cable Wind are available from KSEC Worldwide, which ships to the UK and worldwide.
What you'll learn
- Explain why computers accept any USB keyboard and what an injected keystroke can and cannot do
- Size delays and handle keyboard layouts so a test payload runs reliably
- Write the same benign test for the USB Rubber Ducky, the Flipper Zero Bad USB app and the Evil Crow cables
- Run marker, calculator, banner and lock key tests safely on Windows and Linux lab VMs, with button gates
- Allow-list keyboards on Windows with device installation restrictions and on Linux with USBGuard
- Log new keyboards (event 6416, the kernel log, USBGuard) and join them to the process that followed
- Measure the typing rate of an injection test and use it as supporting evidence
- Respond to a suspected injection and write a one page test report
Who this course is for
- IT and security staff responsible for endpoint and USB policy
- SOC analysts and detection engineers who want a tested keyboard injection rule
- Penetration testers and red team members who need benign, reportable keystroke injection tests
- Owners of a USB Rubber Ducky, Flipper Zero or Evil Crow cable who want to use it responsibly
1 review
Reviews of courses you have completed earn 5 points, whatever the rating. How reviews work
Course discussion
Ask questions, share notes, and chat with other learners. This thread is part of the OnlySecurity community forum, separate from the in-course Q&A so general discussion does not crowd lesson-specific questions.
Open the thread on the OnlySecurity community to take part.
Curriculum
33 lessons across 7 modules
Course Content
Orientation and authorised use
What this course covers, and what it does not
Authorised use: your own lab or written permission
Your lab: two virtual machines, a test log and a safe way to plug in
Quiz: Orientation and authorised use
How keystroke injection works
One technique, several dialects: the devices and their syntax
Writing and testing benign demonstration payloads
Preventing injection: device control and ports
Detecting injection and proving your detections work
Response, reporting and the capstone
Earn a certificate
Showcase your dedication by completing this course and earning a certificate that highlights your skills.





