Unknown key error with FR keyboard layout
Closed this issue · 3 comments
Hello !
I have been testing out the project for a couple of days and after a proper configuration, I have to say... It is awesome !
However, I am actually facing an issue about an "unknown key error". When I simulate a victim by browsing the URL, I can visualize the browser and press some keys, but if I want to perform an "@" for example, the server crashes with Error: Unknown key: "à"
. I have to precise that I am using a FR keyboard layout, so to make this special character, I have to press "AltGr + à".
I do think that it is due to the fact that I am using a FR keyboard layout and "puppeteer" seems to only have a US keyboard layout configured (see ./cuddlephish/node_modules/puppeteer/lib/cjs/puppeteer/common)
the "USKeyboardLayout" files). Are familiar with this error and if so, do you have a workaround or patch ?
Here is the full error:
Error: Unknown key: "à"
at assert (/home/admin/cuddlephish/node_modules/puppeteer/lib/cjs/puppeteer/common/assert.js:26:15)
at Keyboard._keyDescriptionForString (/home/admin/cuddlephish/node_modules/puppeteer/lib/cjs/puppeteer/common/Input.js:133:32)
at Keyboard.down (/home/admin/cuddlephish/node_modules/puppeteer/lib/cjs/puppeteer/common/Input.js:94:34)
at Socket.<anonymous> (file:///home/admin/cuddlephish/index.js:318:44)
at Socket.emit (node:events:513:28)
at Socket.emitUntyped (/home/admin/cuddlephish/node_modules/socket.io/dist/typed-events.js:69:22)
at /home/admin/cuddlephish/node_modules/socket.io/dist/socket.js:704:39
at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
Thank you for bringing this to my attention. It seems that because I used the puppeteer shortcut for this, I have unintentionally limited the possible key inputs:
https://pptr.dev/api/puppeteer.keyinput
Puppeteer is just a wrapper for CDP with some nice features for devs. It seems that CDP has an option to send raw key data:
https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-dispatchKeyEvent
So it looks like we could use a rawKeyDown event instead of keyDown which is used by puppeteer. I would likely have to modify the user frontend to capture the raw input data as well, but it does seem doable. I will look into this and keep the issue open for now while I experiment.
@Vince249 I just pushed a potential fix. I am no longer using puppeteer for individual keys, and am instead doing a keyDown and keyUp directly with CDP. This seems to allow many more special characters without breaking the English layout. I tried to use a French AZERTY on my Mac, and while it does now work with keys like the referenced "à", I apparently have no way to simulate an AltGr key (Mac does not specify which "⌘" key is being pressed). Please pull the change and let me know if that fixes your problem with the "@" symbol as well. If not, you may need to modify the project to detect AltGr on the client side. If that's the case, I would just try to modify the cuddlephish.html to detect AltGr and re-write the few characters that are affected by AltGr before sending the key event to the server. Check out this thread on detecting AltGr:
https://stackoverflow.com/questions/10657346/detect-alt-gr-alt-graph-modifier-on-key-press
I will leave the issue open for a few days for a response, but otherwise feel I have done what I can on this particular issue, and will be closing it soon.
Haven't heard if this fixes AltGR, but can't do more than what I already tweaked from what I can tell.