gitwtfhub

wtf is ttyinject-rs?

0xdea/ttyinject-rs — explained in plain English

Analysis updated 2026-05-18

12RustAudience · researcherComplexity · 4/5Setup · moderate

TL;DR

A Rust port of a known Linux privilege escalation technique that exploits how su handles terminals to inject commands as root.

Mindmap

mindmap
  root((ttyinject-rs))
    What it does
      TIOCSTI tty injection
      su privilege escalation
      Rust port of ttyinject
    Tech stack
      Rust
      Linux kernel
    Use cases
      Security research
      Authorized pentesting
      Learning Rust
    Audience
      Security researchers
      Pentesters

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Study a documented Linux TIOCSTI terminal injection technique as a security research exercise.

REASON 2

Test whether a Linux system is vulnerable to this su-based privilege escalation path during authorized security assessments.

REASON 3

Learn Rust by comparing this port against the original tool it was based on.

REASON 4

Verify whether the dev.tty.legacy_tiocsti kernel setting affects a target system's exposure.

What's in the stack?

Rust

How it stacks up

0xdea/ttyinject-rsbigsaltyfishes/wallpaper-engine-for-macosganten7/navi
Stars121212
LanguageRustRustRust
Setup difficultymoderatehardmoderate
Complexity4/54/53/5
Audienceresearcherdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · moderate Time to first run · 30min

Requires a vulnerable Linux kernel configuration with the legacy TIOCSTI sysctl enabled.

License details are not stated in the README.

Wtf does this do

ttyinject-rs is a Rust rewrite of an existing tool called ttyinject, created by the author as a learning exercise while porting it from its original language to Rust. It demonstrates a long-standing quirk in the Linux kernel involving a terminal control command called TIOCSTI, which can be used to inject keystrokes into another terminal session. The README explains the exact scenario it targets: on a Linux system, a non-privileged user can end up gaining root access if the root user switches into that non-privileged account using the command su minus user. This works because switching in that way does not create a new terminal for the session, which leaves an opening for the non-privileged user to inject commands into the root user's own shell prompt using the TIOCSTI mechanism. Those injected commands copy a shell program to a temporary location and mark it so it runs with elevated privileges, then the tool deletes itself after running once from the user's shell startup file. To use it, the tool is placed inside a specific configuration folder and referenced from the user's .bashrc startup file, either by downloading a prebuilt binary from the project's releases or by building it from source using Rust's Cargo tool. Once root switches into the affected user account, the previously placed program can be used to obtain a root shell. The author notes that cleanup afterward requires manually removing the modified .bashrc line and the temporary elevated file, since the tool only runs and deletes itself once. The README documents that this was tested on a specific version of Ubuntu Linux with a related kernel setting explicitly turned on, and notes that since a certain Linux kernel version, this technique may be blocked unless that setting is enabled or unless the user already has a specific elevated capability. Credit for the original technique and tool is given to its original creator, and the project lists a changelog and a planned future feature to support custom arguments.

Yoink these prompts

Prompt 1
Explain how the TIOCSTI ioctl is being used for privilege escalation in this project.
Prompt 2
Walk me through why su not allocating a new tty enables this technique.
Prompt 3
How would I build ttyinject-rs from source using Cargo?
Prompt 4
What Linux kernel versions or settings block this technique from working?
Prompt 5
Summarize the cleanup steps needed after this tool runs once.

Frequently asked questions

wtf is ttyinject-rs?

A Rust port of a known Linux privilege escalation technique that exploits how su handles terminals to inject commands as root.

What language is ttyinject-rs written in?

Mainly Rust. The stack also includes Rust.

What license does ttyinject-rs use?

License details are not stated in the README.

How hard is ttyinject-rs to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is ttyinject-rs for?

Mainly researcher.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.