Skip to main content

Write Command to Virtual Terminal.

Project description

wrtty

wrtty is a Python script to write commands to a virtual terminal.

Note: wrtty elevates permissions with sudo because it needs root permissions.

By "virtual terminal", it is meant what is often called the "console", which is slightly different. In this case it is the "virtual terminal" controlled by commands such as chvt (e.g. sudo chvt 3).

Writing to the console can make text appear, but it won't make it execute as a command in a shell. Writing to the virtual terminal, such as /dev/tty1, commands can be run, login on console, etc.

This may be used in a situation where you have ssh access to a machine, but no X/Wayland/VNC running, but you need to run as if you are in front of the machine. This in effect simulates an operator standing in front of a machine, typing on the local keyboard.

Install

Quick install from PyPI. Python setups vary correctly, similar to this should work, such as with Debian:

sudo apt install python3-venv python3-pip
python -m venv venv
source venv/bin/activate
pip install -U setuptools pip wheel
pip install wrtty

PyPi project info:

Help

Help output:

$ wrtty --help
usage: wrtty [-h] [-s STRING] [-t TTY]

write string to tty virtual terminal

options:
  -h, --help            show this help message and exit
  -s STRING, --string STRING
                        string to write (default echo)
  -t TTY, --tty TTY     TTY to use (default /dev/tty1)

Use

Use examples:

wrtty
wrtty -s "date -uR"
wrtty -t /dev/tty2 --string "clear"

Build

Developers build thusly.

Under Debian stable (Bookworm/12).

Python setup, suit to taste:

git clone https://spacecruft.org/deepcrayon/wrtty
cd wrtty/
pyenv local 3.11 # if pyenv
python -m venv venv
source venv/bin/activate
pip install -U setuptools pip wheel poetry
poetry install

Sources

Git source code repository:

Status

WORKSFORME.

Upstream

I don't know of another application that specifically does this. There are a few old snippets in perl, C, and Python in StackExchange and blogs, but just small examples.

Some linkies:

fcntl — The fcntl and ioctl system calls

Faking input with IOCTL/TIOCSTI

RichardBronosky writevt.c

Construct a command by putting a string into a tty

Unable to fake terminal input with termios.TIOCSTI

send command to another terminal

Can I send some text to the STDIN of an active process running in a screen session?

Linux Kernel Note

I see this configuration option and note in a 6.5 kernel:

CONFIG_LEGACY_TIOCSTI:
Historically the kernel has allowed TIOCSTI, which will push
characters into a controlling TTY. This continues to be used
as a malicious privilege escalation mechanism, and provides no
meaningful real-world utility any more. Its use is considered
a dangerous legacy operation, and can be disabled on most
systems.

Say Y here only if you have confirmed that your system's
userspace depends on this functionality to continue operating
normally.

Processes which run with CAP_SYS_ADMIN, such as BRLTTY, can
use TIOCSTI even when this is set to N.

This functionality can be changed at runtime with the
dev.tty.legacy_tiocsti sysctl. This configuration option sets
the default value of the sysctl.

Symbol: LEGACY_TIOCSTI [=y]
Type  : bool
Defined at drivers/tty/Kconfig:152
Prompt: Allow legacy TIOCSTI usage
Depends on: TTY [=y]
  Location:
    -> Device Drivers
      -> Character devices
        -> Enable TTY (TTY [=y])
          -> Allow legacy TIOCSTI usage (LEGACY_TIOCSTI [=y])

:)

License

MIT.

Copyright © 2023, 2024, Jeff Moe.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wrtty-0.6.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wrtty-0.6.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file wrtty-0.6.2.tar.gz.

File metadata

  • Download URL: wrtty-0.6.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.6

File hashes

Hashes for wrtty-0.6.2.tar.gz
Algorithm Hash digest
SHA256 e42c571eb3e09e7bdb87ddfb9e8ffed2bb75d83dc9efc69a33ba3d5fa6c0d3d0
MD5 4ef7dee85a7229ddb3aabadb593f5f85
BLAKE2b-256 cb82dada65838bdf0ac0a202259948bf7cd283b02e936dd74d6ae31f1c9b783a

See more details on using hashes here.

File details

Details for the file wrtty-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: wrtty-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.6

File hashes

Hashes for wrtty-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b357cc438c66c723c9a05502de2b2ba4a72b8f05b15a8e4ca3e53d1ec60e14e8
MD5 0e3dac5f999c1604d39f7e7e654e75c6
BLAKE2b-256 a660d507974a497320922ebb6b56c5cea9b3cbe39e295685b9ebd44eeeed90c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page