Page 1 of 1

Raspberry Pi as keylogger

Posted: Mon Jul 22, 2019 5:47 pm
by DiamondMiner88
So i have a usb keyboard and i need to have it output to a computer and also be recorded. I think its possible to connect the keyboard to the RasPi and then have the raspi send data to the computer. Is there a way to do it because i have no idea how. I have a Raspberry Pi 3 B+

Re: Raspberry Pi as keylogger

Posted: Mon Jul 22, 2019 11:24 pm
by W. H. Heydt
This is to ONLY record what YOU type, and not anybody else?

Re: Raspberry Pi as keylogger

Posted: Tue Jul 23, 2019 12:57 am
by uilfut
Asking for a friend

Re: Raspberry Pi as keylogger

Posted: Tue Jul 23, 2019 1:18 am
by W. H. Heydt
uilfut wrote:
Tue Jul 23, 2019 12:57 am
Asking for a friend
Pull the other leg. It's got bells on.

Re: Raspberry Pi as keylogger

Posted: Tue Jul 23, 2019 2:36 am
by jdonald
Welcome to the forums.

:D

Making a virtual keyboard or in this case a passthrough keyboard sniffer is typically implemented via a USB gadget. Unless you have software access to the target computer (in which case, this would be moot), you require OTG support so it's not possible with a Pi 3B+. You'll need a Pi Zero or Pi Zero W, but I guess that'll at least make your physical footprint smaller i.e. (slightly) reduce your chances of getting caught?

Here's a tutorial for making a Pi Zero report as an HID keyboard: https://randomnerdtutorials.com/raspber ... board-hid/

Re: Raspberry Pi as keylogger

Posted: Tue Jul 23, 2019 8:15 am
by davidcoton
Assuming for a moment that you have a legal and moral use:

Connecting a keyboard to the Pi requires a standard USB port.
Connecting the PI as a HID to the target requires USB "device" mode.
The Pi3B+, Pi3B, Pi2B, PiB+, PiB cannot do device mode because of the onboard hub.
The Pi0, PiA, PiA+, Pi3A+ have only a single USB port.

So give up now. No doubt your intentions (advertised here) have been noted by the Men in Black.

Edit: corrected typos in model list

Re: Raspberry Pi as keylogger

Posted: Tue Jul 23, 2019 11:16 am
by hippy
A Pi 4B can operate as a USB device and a USB host at the same time so that should be perfect for this task and many other 'inserted into a USB path' roles.

A Pi Zero, A, A+ or 3A+ can run in USB device mode with an external USB host module attached to achieve the same.

One could hardware hack a B, B+, 2B, 3B, 3B+ so it supports USB device operation and attach a host module, but that's a lot of effort.

Re: Raspberry Pi as keylogger

Posted: Tue Jul 23, 2019 2:16 pm
by jdonald
Good catch davidcoton on the 0, 0W, A, A+, and 3A+ having only a single USB interface.

So that leaves only the Pi 4B.

Re: Raspberry Pi as keylogger

Posted: Tue Jul 23, 2019 4:19 pm
by W. H. Heydt
davidcoton wrote:
Tue Jul 23, 2019 8:15 am
Assuming for a moment that you have a legal and moral use:
I think that's a stretch. Plus, the OP still shows only a single post. Draw your own conclusions.

Re: Raspberry Pi as keylogger

Posted: Wed Jul 24, 2019 5:38 am
by jbeale
I'm somehow reminded of a first post to an electronics forum asking (an "urgent request" actually) the best way to rig a microwave remotely to turn on long enough to ignite a can of gasoline. In reply to skeptical queries, he insisted "of course" this was only for private experimental purposes.

Re: Raspberry Pi as keylogger

Posted: Thu Apr 02, 2020 10:24 pm
by brittohalloran
Not sure about the original question, but I do have a legitimate use for a USB "keyboard intercept". I'm reading a barcode scanner which acts as a USB keyboard input and then hopefully passing along a modified version of that input to the host computer, on which I'd prefer to not have to install any software on. I'm parsing a GS1 barcode with multiple data fields and picking out only the one I need.

I'm comfortable with Python so I've started there, but open to learning C or other languages there are better libraries for this.

I thought this would be possible with a Pi Zero W connected to the computer via the main Power port (is that not a USB port, just 5V input?) and the barcode scanner connected to the USB port.

Re: Raspberry Pi as keylogger

Posted: Fri Apr 03, 2020 9:36 am
by davidcoton
brittohalloran wrote:
Thu Apr 02, 2020 10:24 pm
I thought this would be possible with a Pi Zero W connected to the computer via the main Power port (is that not a USB port, just 5V input?) and the barcode scanner connected to the USB port.
You are right, the Pi0 and the A models have only one USB port. You would need a 4B, as you will want one port acting as host and one as a device, so even an earlier B (or a model with an external hub) will not do it.

Re: Raspberry Pi as keylogger

Posted: Fri Apr 03, 2020 11:40 am
by thagrol
There are workarounds though.

Use two Pi zero. One to act as the host for the bar code scanner, one to act as the HID device. Have them communicate over their serial ports.

There are SPI to USB host chips in the wild. Though I've never used them, they should be fast enough for a low speed device like a keyboard/barcode scanner.

Depending on what the final USB host device is, run your python code on that.

Re: Raspberry Pi as keylogger

Posted: Tue Apr 07, 2020 3:39 pm
by brittohalloran
Thanks everyone. I will pursue the pure HID Pi 4 solution long term. In the short term I've gone with a serial to USB cable and a software keyboard wedge installed on the target computer. This violates my initial plan to not have to install any software on the target computer, but I have the following working successfully:

# Hardware
- Raspberry Pi 3 with standard Raspbian OS installed, powered with a 5V/2.5A wall-wort power supply
- Tera barcode scanner (Amazon) plugged into the USB port which acts as a keyboard input. Scanner set to factory settings.
- JBtek USB to Serial Cable connected to the Raspberry Pi serial TX/RX lines, and USB end connected to the target computer's USB port.

Pinout:
RED (+5V) disconnected (power via heavier duty power supply)
BLACK (GND) to Pin 6 (GND)
WHITE (TxD) to Pin 8 (GPIO 15 / TxD)
GREEN (RxD) to Pin 10 (GPIO 16 / RxD)

# Software
On the Raspberry Pi Zero W:
- Enable the hardware serial port and disable the login shell via serial by visiting `sudo raspi-config` and selecting the `Interfaces > Serial` menu item.
- Use the python `keyboard` module to record all keypresses until an `enter` is seen, then parse the input for what I'm looking for
- Use the python `pyserial` module to send the parsed output over `/dev/serial0` at a baudrate of 9600
- Run the above continuously using a systemd service so it runs automatically when plugged in

On the target host computer (intended for Windows, but anything will work):
- A serial input keyboard wedge program (such as 232key for Windows) which receives ASCII bytes over a virtual COM serial port and sends keystrokes to the OS. Match serial port baudrate / bits / stopbits, etc...

Re: Raspberry Pi as keylogger

Posted: Thu Apr 23, 2020 12:26 am
by brianj2656
What about just a passive sniffer. So it doesn't have to host or hub. Take usb female jack and solder to it on the perf board a male jack as well. Connect all the connections like normal. Power to power, gnd to gnd, and data lines like you are supposed to then add a 3rd connector with a short cable so that only 3 of the 4 wires are connected. TX, RX and GND but not power. Plug keyboard into the into the female jack and then plug the male with power into the target computer, it will provide the power for the keyboard. Then plug the third connector to the Rpi, and when it boots up have a normal keylogger installed so it logs keystrokes. But does not supply power Justin case there's a difference in pwr voltages and doesn't fry the USB power bus in either. Think of it like a keyboard splitter, this way you don't have to worry about passing through the Rpi, it just listens without any lag.

Re: Raspberry Pi as keylogger

Posted: Thu Apr 23, 2020 11:13 am
by brittohalloran
brianj2656 wrote:
Thu Apr 23, 2020 12:26 am
What about just a passive sniffer.
That would work if I just wanted to read what was passing through, but I actually want to read and intelligently modify what is being sent.

Re: Raspberry Pi as keylogger

Posted: Sun May 31, 2020 6:20 pm
by ludibrious
I'm trying to achieve something similar.

The idea is to capture and analyse data sent from a Joystick / Steering to a PS4.
I cannot simply capture the the traffic on the console, since it's locked down.
As as suggested here I've setup a RPi4 like so:

Code: Select all

 Steering Wheel --> Raspberry Pi --> PS4 
But I'm struggling to enable USB Gadget / forward traffic to the PS4.

Is there any documentation or further links how to achieve this?

Re: Raspberry Pi as keylogger

Posted: Mon Jun 01, 2020 11:57 am
by thagrol
ludibrious wrote:
Sun May 31, 2020 6:20 pm
I'm trying to achieve something similar.

The idea is to capture and analyse data sent from a Joystick / Steering to a PS4.
I cannot simply capture the the traffic on the console, since it's locked down.
As as suggested here I've setup a RPi4 like so:

Code: Select all

 Steering Wheel --> Raspberry Pi --> PS4 
But I'm struggling to enable USB Gadget / forward traffic to the PS4.

Is there any documentation or further links how to achieve this?
Using the 4B as a USB gadget has been covered a few times but to recap:
  • Gadet functionality is only available on the USB C connector
  • You'll need to find another way to supply power to the 4B as the USB host almost certainly won't be able to supply enough current. There are potential isssues here such as backfeeding power to the USB host.
  • Despite the connector being USB C it actually only provides USB 2
  • Software setup for USB gadget mode is the same as for previous generations of the Pi. Tutorials and guides written for the zero(W) apply to the 4B

Re: Raspberry Pi as keylogger

Posted: Tue Jun 02, 2020 6:12 am
by ludibrious
thagrol wrote:
Mon Jun 01, 2020 11:57 am
Using the 4B as a USB gadget has been covered a few times but to recap:
  • Gadet functionality is only available on the USB C connector
  • You'll need to find another way to supply power to the 4B as the USB host almost certainly won't be able to supply enough current. There are potential isssues here such as backfeeding power to the USB host.
  • Despite the connector being USB C it actually only provides USB 2
  • Software setup for USB gadget mode is the same as for previous generations of the Pi. Tutorials and guides written for the zero(W) apply to the 4B
Thanks, I'll give that a try. I somehow completely missed the USB-C part :? :oops: