From Terminal Output to Arbitrary Remote Code Execution
iTerm2 terminal emulator injects linefeeds into stdin when handling certain escape sequences (tmux integration and request upload), allowing an attacker who can print to the terminal to execute arbitrary commands. The author demonstrates a self-contained exploit that uses escape sequences to manipulate the shell command line and run a command via m4.
Published on blog.solidsnail.com
It was the year of the Linux desktop 1978. Old yellowed computers were not yet old, nor yellowed.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker who can control terminal output could execute arbitrary commands on the victim's machine, though the exploit requires specific conditions such as a known command prefix and may fail depending on shell processing.
What the attacker needed
Attacker can print to victim's terminal; victim uses iTerm2; victim uses a POSIX shell (bash or zsh)
The fix
The report states that the vendor reacted swiftly with a patch, but does not detail the fix.
How it was found
- Print a crafted string containing escape sequences to the terminal.
- The escape sequences cause the terminal to push characters and linefeeds to stdin.
- The shell reads the injected linefeed and executes the manipulated command line.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A terminal emulator is the program that shows you a command line. It normally sends what you type to the shell, but some special control codes can make it send extra characters, like pressing Enter, without you doing so. Here, iTerm2 did that, so if an attacker could get some text printed on your screen, they could make your shell run a command.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.