Android - Can a device pretend to be a USB keyboard?

Yes. This is definitely possible, requiring no modifications or drivers on the PC. As the OP mentions, the USB identification on the phone end is ultimately done in software (in this file https://github.com/android/kernel_msm/blob/android-msm-2.6.35/drivers/usb/gadget/composite.c), and it could be modified to identify itself as a standard USB keyboard.

This change would require a couple of things.

  1. A modified kernel with a patched USB driver
  2. An Android app that could talk to some interface exposed by the modified USB driver.

There was a paper published a couple of years ago (titled Exploiting smart-phone USB connectivity for fun and profit) that described using a phone to brute-force desktop login screens. The method they used involved making the phone appear as a USB keyboard.


This doesn't exactly answer your question, but it might help in your use case.

Maybe you want to have a look at InputStick. It'll be a USB thumb drive that you pair to Android via Bluetooth. Plugged into a computer it emulates a generic USB HID to send keyboard strokes. An advanced Java API will also allow to specify i.e. device descriptors to emulate non-standard functions. It could provide a nice example that it's defined in software rather than hardware.

For reference, the developer also is working on example programs, such as a Demo Password Manager.

Tags:

Keyboard

Usb