r/LiveOverflow • • Apr 26 '20

Reverse engineering of Logitech Unifying firmware

Hi,

I have been trying to understand the unifying protocol, its security and hopefully build my own wireless devices. For now, I'm in deep in the woods, trying to get out of the trenches, which is why I'm seeking help here.

This GitHub issue details my entire journey since 2 weeks ago, the things I have done and my current progress, basically, I have gotten everything to work except encrypted keystrokes on the latest dongles. https://github.com/RoganDawes/LOGITacker/issues/55#issuecomment-617739408

In short, the unifying protocol encrypts keystrokes using a counter and AES in ECB mode. While I have been told this counter is random at each power up, I have reasonable clues and suspicion that it is not and possibly has some form of checksum etc.

To confirm my suspicion, I'm trying to look inside this firmware by Logitech: https://github.com/Logitech/fw_updates/blob/update2019-08-27/RQR12/RQR12.10/RQR12.10_B0032.hex

A quick google search yielded nothing on how to handle these shex files. Would most appreciate it if I could get some help to translate these shex files into assembly.

While I can write assembly, it is my first time trying to reverse/read others' assembly, probably will have more questions too.

Thank you.

9 Upvotes

14 comments sorted by

2

u/hewwocraziness Apr 26 '20

Take a peek at LiveOverflow's "stop playing video games" video (Cookie Clicker save file reversing) for some info on how to try to identify structures in binary data. Good luck! :)

2

u/bilogic Apr 27 '20

Do you have a link? I did not find a video that matched exactly.. thanks

1

u/bilogic Apr 27 '20 edited May 12 '20

Some updates, but before that, a bit of background:

The Logitech K270 keyboard transmits encrypted keystrokes that are basically a concatenation of a header (3 bytes), an encrypted payload (8 bytes) and the plain counter (4 bytes) that was used to encrypt the plain payload. What follows is some padding and a 1 byte checksum, all in totaling at 22 bytes.

Encrypted keystrokes transmitted by the same K270 are accepted by both a vulnerable dongle (A) and a dongle with the vulnerability patched (B), this has been verified by sniffing as well as direct RF communications, the K270 does not transmit un-encrypted keystrokes.

For the device I created, only A accepts my encrypted transmissions, B does not. However that implies that I must have gotten the AES XOR portion correct, otherwise A would not be able to decode at all. So, by my logic, that leaves the counter as the only reason the patched dongle is receiving but ignoring my transmissions.

Managed to decode the matching hex file that my dongle B is using from here: https://github.com/Logitech/fw_updates/blob/update2019-08-27/RQR12/RQR12.10/RQR12.10_B0032.hex, the instruction set is Intel 8051

0x81B5: (5/5) Memory location. Last byte of payload, must always be 0xC9, several places in the firmware checks for this, e.g. 0x2737, 0x440E

0x81B6: (5/5) Memory location. MSB of 4 byte counter til 0x81B9 (LSB)

0x2726: (3/5) Code location. Start or near the start of keystroke decryption

0x4412: (1/5) Code location. Seems to do a bunch of weird stuff to the AES counter

0x576D: (5/5) Code location. AES XOR function

I have rated my confidence level in the reverse engineering. Would appreciate any help to reverse what 0x4412 is doing. Thank you.

2020-05-12 update: 0x4412 seems to be flipping the counter between big and little endian in parts of the memory

1

u/omniacet May 07 '20

Could you tell us how do you flash a modified firmware to a dongle?

1

u/bilogic May 11 '20 edited May 12 '20

I did not do that, but from what I know, you probably need Linux, see https://github.com/BastilleResearch/mousejack

What have you modified in the firmware? I'm releasing my code here in a bit https://github.com/bilogic/logitech-unifying-device

1

u/omniacet May 12 '20

Hm, I have few things in mind: Today I got M170 tranceiver and tried to pair M570 trackball to it, but it seems incompatible, would be great if it could be reflashed to M570 firmware, but I haven’t really dig into this yet and not sure it is possible

Another thing I really want is writing custom firmware for my gamepad. Some unifying controller models can be flashed over usb with this project: https://github.com/BastilleResearch/nrf-research-firmware, so I want to write own HID class while retaining ability to reflash over usb

1

u/bilogic May 13 '20

There are only unifying and nano (non-unifying) dongles. M170 is listed as nano, you have to figure out if it uses the NRF24LU1+ chip.

Are you referring to a custom firmware for your device or dongle? What behavior do you want to customize?

1

u/omniacet May 13 '20

There are only unifying and nano (non-unifying) dongles. M170 is listed as nano, you have to figure out if it uses the NRF24LU1+ chip. Tbh, when I bought M170, I wanted to replace a dongle for trackball (and shop listed it as unifying-compatible), accurate list of unifying devices would be handy

Are you referring to a custom firmware for your device or dongle? What behavior do you want to customize? I have a 2.4Ghz gamepad, so custom firmware would run on transceiver, communicate with gamepad and provide XInput gamepad HID class for PC

1

u/bilogic May 14 '20

I would refund the M170 at the shop :)

Is your gamepad by Logitech? Nothing is going to work by flashing some random firmware onto some random hardware.

1

u/omniacet May 15 '20

My son surprisingly likes it, so I’m keeping it:)

I know that random firmware won’t work, I’m going to write my own. RFStorm uses dongle’s onboard bootloader to flash device, and these are based on 8051 mcu with data sheets available. Still gonna learn quite a lot about USB stack/HID classes and reverse communication protocol:)

1

u/mrfibreopticnz Apr 16 '23

Hi Bilogic, any update with this project, i'm very interested in it