DevKitty-io / USB-Nugget

Run DuckyScript payloads on a USB Nugget!
https://usbnugget.com
MIT License
163 stars 19 forks source link

fix: make modifier keys work #37

Closed brandonpaiz closed 2 years ago

brandonpaiz commented 2 years ago

Resolves issue https://github.com/HakCat-Tech/RubberNugget/issues/35

Keys CTRL, ALT, SHIFT are modifier keys, and need to be passed to the keyboard.sendPress function

AlexLynd commented 2 years ago

I looked into this issue, and realized older versions of the EspTinyUSB library have an issue where key modifiers aren't appended to the keycode array in hidkeyboard.cpp.
I forgot I circumvented this issue by modifying the library locally, but I've published the updated file here. Could you take a look at this and tell me if it's a viable fix?

AlexLynd commented 2 years ago

If so, we can just point the Docker image to our forked version of the EspTinyUSB library for now, and make a PR to the official repo after optimizing it :P

brandonpaiz commented 2 years ago

Whoops, notifications were going to wrong email address. Should be fixed now

A few questions for you:

  1. Can you tell me a little more about the issue you're talking about?
  2. Why do modifiers need to be added to the keycode array? Does this have something to do with the maximum number of keys that can be pressed simultaneously?
AlexLynd commented 2 years ago

Hey Brandon! I got busy chasing down bugs in a different Nugget project.
A few months ago I ran into the same issue with modifiers not working so I looked into the source code of the EspTinyUSB library, and traced down the issue to the hidkeyboard.cpp file. The standard NKRO seems to be 6 keys from most sources I could gather, and the keycode array defined here has 6 elements allocated to hold the keystrokes and modifiers. Problem is tho, I don't think there was a variable keeping track of the index of modifiers or multiple keypresses and only the first index was being addressed. However, shift still worked since technically the shift modifier w/ a character counts as a single char? I forget but can look into this more. Let me know if that makes sense :P

AlexLynd commented 2 years ago

Also I completely forgot abt this issue until I went to merge your PR and dug around in my local codebase for the EspTinyUSB library. So I might be wrong abt some of the details

brandonpaiz commented 2 years ago

Hey! Sounds like we might be talking about two slightly different issues here. There's the six-max keypress thing, and then there's this issue I've seen where mod+key doesn't work, e.g. ctrl-s

AlexLynd commented 2 years ago

Yea! And that's resultant of modifiers not being appended to the keycode array properly - I'll spin up a quick POC to see if that's still the case

brandonpaiz commented 2 years ago

Just tried it out...the Nugget doesn't seem to have any problems pressing six keys at a time. Maybe we should merge this because less broken > more broken