Simulate TTY keystrokes
Simple kernel module (2.6.32-31) that simulates TTY keystrokes which are read from a character device. Incoming strings are sent to the foreground terminal.
tty_injection
is a very basic kernel module that registers a character device and echoes
incoming characters to the current TTY’s queue – and can thus be seen as a kind of “reverse keylogger”.
It was developed for and tested with kernel version 2.6.32-31.
Back then, I used it in combination with LIRC
to control an ncurses
-based media player with no other automation API on a headless machine.
However, I don’t think that there are many usecases (anymore) for tools that solely rely on
interactive input. Additionally, there could be better ways to achieve the same effect. Please note
that there might be some refactoring needed in order to be compatible with non-ancient kernel
versions.
TTY injection: Usage
After building (make
) and loading (modprobe
), a character input device will be registered. Check
kernel messages (dmesg
) for the actual device number, which can then be used to create the
corresponding node in the filesystem using mknod
. Every character piped in there will be sent to
the current foreground TTY. Note that this has to be a real terminal, not a graphical terminal
emulator for which there are other tools such as xsendkeys
or
xdotool
Warning: Be aware of that loading this module will probably be a huge security risk, since being able to write to the device will result in the ability to send any commands to the current terminal, regardless of which privileges the latter holds. And, of course, bugs might become devastating in the kernel context.