# iTerm2 Remote Code Execution via Kitty Graphics Protocol Reply Injection (versions 3.6.1 through 3.7.8)

> A logic flaw in iTerm2's Kitty graphics protocol implementation lets a crafted file execute shell commands when its contents are merely printed (e.g. with cat) in a vulnerable terminal session. Failed image-request error replies preserve untrusted newlines and are written to the pseudoterminal, where the shell treats them as Return key presses. Fixed in iTerm2 3.7.9.

- **Published:** 2026-11-23T13:25:19Z
- **Last reviewed:** 2026-11-23T13:25:19Z
- **Canonical:** https://intel.threadlinqs.com/threat/TL-2026-6698
- **Card image:** https://intel.threadlinqs.com/og/threat/TL-2026-6698.png
- **ID:** TL-2026-6698
- **Severity:** HIGH
- **Category:** VULNERABILITY
- **Status:** ACTIVE
- **Detections:** 9 (1 shown free below) · **IOCs:** 14 (3 shown free below)
- **CVEs:** CVE-2026-41253, CVE-2020-35605

## Description

iTerm2 versions 3.6.1 through 3.7.8 on macOS, with default settings, process Kitty graphics protocol APC sequences (ESC _ G ... ESC \) embedded in any text that is printed to the terminal. Per the public write-up by ii4gsp (published 2026-11-21) the bug is a pure logic flaw (no memory corruption, no race) that chains three independent weaknesses. The issue was credited by iTerm2 to Minseong Kim (@ii4gsp) of NSHC Red Alert Labs. No CVE, GHSA or CVSS score has been published at the time of research.

Weakness 1 - no trust check on APC: VT100Terminal.m executeAPC: only checks for a 'G' prefix and returns early in tmux mode; unlike OSC handling it has no terminalIsTrusted check, so any APC reaching the parser is executed. The 'Disable potentially insecure escape sequences' setting (off by default) does not cover APC sequences, so a trust check alone would not have protected default installs. Weakness 2 - error path keeps newlines: in KittyImageController.swift, a transmit command with t=f base64-decodes the payload into a file path. For a non-existent file the isRegularFile resource lookup throws before filenameIsSafe() is ever reached, and the catch block returns 'EBADF:' plus NSError.localizedDescription, which on macOS preserves literal LF characters from the filename. Weakness 3 - reply goes to the PTY: in the default .normal verbosity the reply is always built as ESC _ G <args>;<message> ESC \ and written via screenSendReportData: to the same pseudoterminal path as keyboard input, so the shell's line discipline splits on the injected LF and executes the attacker-controlled line as a command.

Attack flow documented in the write-up: the attacker embeds an APC such as ESC _ G a=T,f=100,t=f,i=1;<base64> ESC \ in a file that looks benign (README, .md, .txt, .log, .csv, config or source file) and delivers it through a git repository, shared folder, archive or email attachment. The base64 payload decodes to '/tmp/x', LF, the command, LF, 'z'. When the victim runs cat on the file, iTerm2 consumes the APC (it is not displayed), emits the EBADF error reply into the PTY, and the shell executes the injected middle line. The PoC is a single Python 3 script that creates ./iterm2_cat_poc/README.md and demonstrates this with 'open -a Calculator'; the write-up reports 100% reproducibility on bash, zsh and fish. Constraints: the injected command must not contain '/' (it breaks URL(fileURLWithPath:) and changes the NSError message format) and must not contain an ASCII double quote (bash would enter quote mode; curly quotes from localizedDescription avoid this); the mechanism relies on macOS NSError behaviour. The write-up notes concealment of the resulting shell error noise was not explored.

Fix: iTerm2 3.7.9 (built 2026-11-20; appcast pubDate Fri, 20 Nov 2026 17:56:38 -0800, i.e. 2026-11-21 01:56 UTC). Commit a53b1bc0 adds sanitizedResponseMessage() replacing C0 controls and DEL with spaces in Kitty error replies; commit 2a63835c adds a shared NSString category (stringByReplacingControlCharactersWithSpace) extending coverage to C1 controls and applying it to Kitty drag-and-drop (OSC 72) replies and title reporting (reportSafeTitle:). Vendor release notes (full_changes.txt) label 3.7.9 'a security update' and state: 'Fixed a security issue where a crafted file, when displayed in the terminal (for example with cat), could run arbitrary commands by abusing the Kitty image and drag-and-drop protocols. Replies sent back to programs no longer include control characters that could be injected into your shell. Title reports were hardened the same way.' They report no in-the-wild exploitation. A public PoC description exists, so exploitation is trivial for anyone reading the write-up.

Context: this is the second iTerm2 'display-a-file-to-run-code' class bug in 2026 (CVE-2026-41253, SSH conductor escape-sequence RCE when displaying .txt files, published 2026-04-18), and mirrors the 2020 kitty terminal flaw CVE-2020-35605, where a filename with special characters in a graphics-protocol error message allowed code execution.

## MITRE ATT&CK

- T1566.001 Phishing: Spearphishing Attachment
- T1203 Exploitation for Client Execution
- T1204.002 User Execution: Malicious File
- T1059.004 Command and Scripting Interpreter: Unix Shell
- T1036.008 Masquerading: Masquerade File Type
- T1027 Obfuscated Files or Information

## Free detection (Splunk SPL, Microsoft KQL, Sigma)

**iTerm2 Kitty APC Reply Injection - Shell Command Within Seconds Of File Display (TL-2026-6698)** (`TL-2026-6698-SPL-001`)

Detects the behavioural signature of the iTerm2 3.6.1-3.7.8 Kitty graphics reply injection (T1203, T1204.002, T1059.004). When a crafted file is printed with cat or less, iTerm2 writes an EBADF error reply into the PTY and the interactive shell executes the injected line immediately, so a command-execution child (open, curl, osascript, nc, python and similar) starts under the same shell within about 3 seconds of a file-viewer child. The search pairs viewer and payload children by shell PID, flags shells launched by iTerm2/iTermServer, and flags the public PoC command 'open -a Calculator'. Fixed in iTerm2 3.7.9.

- **Languages:** Splunk SPL, Microsoft KQL, Sigma
- **ATT&CK:** T1203, T1204.002, T1059.004
- **Data sources:** crowdstrike_falcon:ProcessRollup2 (macOS), defender_endpoint:DeviceProcessEvents (macOS), macos_process_creation
- **Severity:** high
- **Confidence:** high

### Splunk SPL

```spl
index=edr sourcetype="crowdstrike:events:sensor" event_simpleName=ProcessRollup2 event_platform=Mac earliest=-24h
| eval proc=lower(mvindex(split(ImageFileName,"/"),-1)), parent=lower(ParentBaseFileName)
| eval role=case(match(proc,"^(zsh|bash|fish|sh)$") AND match(parent,"^(iterm2|itermserver)"),"iterm_shell", match(parent,"^(zsh|bash|fish|sh)$") AND match(proc,"^(cat|less|more|head|tail|bat|strings)$"),"viewer", match(parent,"^(zsh|bash|fish|sh)$") AND match(proc,"^(open|curl|wget|osascript|nc|ncat|python3?|perl|ruby|base64|launchctl|sh|bash|zsh)$"),"payload")
| where isnotnull(role)
| eval shell_key=aid.":".if(role="iterm_shell",TargetProcessId_decimal,ParentProcessId_decimal), viewer_time=if(role="viewer",_time,null()), term_flag=if(role="iterm_shell",1,0)
| sort 0 shell_key _time
| streamstats current=f last(viewer_time) as prev_view by shell_key
| eventstats max(term_flag) as iterm_session by shell_key
| where role="payload" AND isnotnull(prev_view) AND (_time-prev_view)<=3
| eval delay_sec=round(_time-prev_view,2), poc_match=if(like(lower(CommandLine),"%open -a calculator%"),1,0)
| table _time ComputerName UserName iterm_session delay_sec parent proc CommandLine poc_match
```

### Microsoft KQL

```kql
let Shells = dynamic(["zsh","bash","fish","sh"]);
let Viewers = DeviceProcessEvents
| where Timestamp > ago(24h)
| where FolderPath startswith "/"
| where FileName in~ ("cat","less","more","head","tail","bat","strings")
| where InitiatingProcessFileName in~ (Shells)
| project DeviceId, ShellPid = InitiatingProcessId, ViewTime = Timestamp, ViewCmd = ProcessCommandLine, TermParent = InitiatingProcessParentFileName;
DeviceProcessEvents
| where Timestamp > ago(24h)
| where FolderPath startswith "/"
| where InitiatingProcessFileName in~ (Shells)
| where FileName in~ ("open","curl","wget","osascript","nc","ncat","python3","python","perl","ruby","base64","launchctl","sh","bash","zsh")
| join kind=inner Viewers on DeviceId, $left.InitiatingProcessId == $right.ShellPid
| where Timestamp between (ViewTime .. (ViewTime + 3s))
| extend FromITerm = TermParent startswith "iTerm", PocMatch = ProcessCommandLine has "calculator"
| project Timestamp, DeviceName, AccountName, TermParent, FromITerm, ViewCmd, PayloadBinary = FileName, PayloadCmd = ProcessCommandLine, PocMatch, DelaySec = datetime_diff('second', Timestamp, ViewTime)
```

### Sigma

```yaml
title: iTerm2 Kitty APC Reply Injection - Shell Command Within Seconds Of File Display
name: tl6698_viewer
id: 0a3f6b1e-52c4-4d8a-9e17-3b6c1d7f2a01
status: experimental
description: Helper rule for TL-2026-6698 correlation. A file viewer (cat, less, head) started by an interactive shell.
author: Threadlinqs Team
date: 2026-11-23
logsource:
    category: process_creation
    product: macos
detection:
    selection:
        ParentImage|endswith: ['/zsh', '/bash', '/fish', '/sh']
        Image|endswith: ['/cat', '/less', '/more', '/head', '/tail', '/bat', '/strings']
    condition: selection
level: informational
---
title: Command Execution Tool Started By Interactive Shell
name: tl6698_payload
id: 0a3f6b1e-52c4-4d8a-9e17-3b6c1d7f2a02
status: experimental
description: Helper rule for TL-2026-6698 correlation. Execution or download tooling started by an interactive shell.
author: Threadlinqs Team
date: 2026-11-23
logsource:
    category: process_creation
    product: macos
detection:
    selection:
        ParentImage|endswith: ['/zsh', '/bash', '/fish', '/sh']
        Image|endswith: ['/open', '/curl', '/wget', '/osascript', '/nc', '/ncat', '/python3', '/perl', '/ruby', '/base64', '/launchctl']
    condition: selection
level: informational
---
title: iTerm2 Kitty APC Reply Injection - Shell Command Within Seconds Of File Display (TL-2026-6698)
id: 0a3f6b1e-52c4-4d8a-9e17-3b6c1d7f2a03
status: experimental
description: Detects a command execution tool started by the same interactive shell within 3 seconds after a file viewer, the behaviour produced when iTerm2 3.6.1-3.7.8 echoes an attacker-controlled Kitty graphics EBADF reply into the PTY. Fixed in iTerm2 3.7.9.
references:
    - https://ii4gsp.github.io/iterm2-rce/
    - https://iterm2.com/appcasts/full_changes.txt
author: Threadlinqs Team
date: 2026-11-23
tags:
    - attack.execution
    - attack.t1203
    - attack.t1204.002
    - attack.t1059.004
correlation:
    type: temporal_ordered
    rules:
        - tl6698_viewer
        - tl6698_payload
    group-by:
        - ComputerName
        - ParentProcessId
    timespan: 3s
falsepositives:
    - Developers chaining cat or less with open/curl in one command line or a shell function
    - Shell scripts and dotfiles that read a file and then launch a tool
level: high
```

**Known false positives:**

- Developer one-liners or shell functions that run cat/less and then open/curl within the same second (for example cat file; open file)
- Shell startup scripts, dotfiles or tool wrappers that read a config file and immediately launch a helper
- Automated test harnesses driving an interactive shell

**Tuning notes:** Prioritise results with iterm_session=1 and poc_match=1. Replace index=edr and the crowdstrike sourcetype with your macOS process telemetry (Jamf Protect, osquery process_events or Defender for Endpoint). Shells that started more than 24h ago will not show iterm_session=1, so widen the earliest window or enrich from a session lookup. Widen the 3 second gap to 5 seconds if endpoint timestamps are skewed. Exclude known automation accounts and tooling parents. Exposure is limited to iTerm2 3.6.1-3.7.8, so also correlate with the version-inventory detection (TL-2026-6698-KQL-003).

### 8 more detection rules (Splunk SPL, Microsoft KQL, Sigma), unlock with TL Creds

- Untrusted Text-Like File Staged Then Displayed In Terminal (iTerm2 Kitty APC Delivery) (locked: unlock with TL Creds)
- iTerm2 Kitty APC PoC Fingerprint - GUI App Launch (open / osascript) Right After File Display (locked: unlock with TL Creds)
- Vulnerable iTerm2 Version (3.6.1 - 3.7.8) Installed On macOS Endpoint (locked: unlock with TL Creds)
- iTerm2 Kitty APC PoC Artifact - iterm2_cat_poc Directory / README.md Created (locked: unlock with TL Creds)
- iTerm2 Kitty APC PoC Execution - 'open -a Calculator' Started By Interactive Shell (locked: unlock with TL Creds)
- iTerm2 Reply Injection Follow-On - curl/wget Download Into Staging Path From Interactive Shell (locked: unlock with TL Creds)
- iTerm2 Reply Injection Follow-On - Decode-And-Execute or Download-And-Execute Pipeline From Interactive Shell (locked: unlock with TL Creds)
- iTerm2 Reply Injection Follow-On - Reverse Shell or Fetch-And-Pipe One-Liner From Interactive Shell (locked: unlock with TL Creds)

Sign up free to unlock the detection rules: https://threadlinqs.com/?modal=signup

## Sample indicators (3 of 14)

Defanged, TLP:CLEAR.

- Domain: `ii4gsp[.]github[.]io`
- URL: `hxxps://iterm2[.]com/appcasts/full_changes.txt`
- File hash: `a53b1bc084fe062de44b52d03ccf713c7962ac83`

Full set of 14 indicators unlocks with TL Creds: https://threadlinqs.com/tl-creds

## Sources

- [iTerm2 Remote Code Execution Flaw Lets Hackers Run Malicious Commands by Displaying Crafted Files (Cyber Security News)](https://cybersecuritynews.com/iterm2-remote-code-execution-flaw/)
- [iTerm2 Arbitrary Command Execution via Kitty Image Protocol APC Response Injection (ii4gsp)](https://ii4gsp.github.io/iterm2-rce/)
- [iTerm2 3.7.9 release notes (full_changes.txt) - security update](https://iterm2.com/appcasts/full_changes.txt)
- [iTerm2 Sparkle appcast (Version 3.7.9 entry)](https://iterm2.com/appcasts/final_modern.xml)
- [iTerm2 fix commit 1: sanitize Kitty graphics response messages](https://github.com/gnachman/iTerm2/commit/a53b1bc084fe062de44b52d03ccf713c7962ac83)
- [iTerm2 fix commit 2: shared control-character replacement for Kitty image, DnD and title reports](https://github.com/gnachman/iTerm2/commit/2a63835ca19bbd20b0d051b33c14341b0b708d5b)
- [Kitty Graphics Protocol Specification](https://sw.kovidgoyal.net/kitty/graphics-protocol/)
- [iTerm2 source: KittyImageController.swift](https://github.com/gnachman/iTerm2/blob/master/sources/InlineImages/KittyImageController.swift)
- [iTerm2 source: VT100Terminal.m](https://github.com/gnachman/iTerm2/blob/master/sources/VT100/VT100Terminal.m)
- [Related: iTerm2 flaw abuses SSH integration (Cyber Security News)](https://cybersecuritynews.com/iterm2-flaw-abuses-ssh-integration/)
- [Related: CVE-2026-41253 iTerm2 SSH conductor escape-sequence RCE (SentinelOne)](https://www.sentinelone.com/vulnerability-database/cve-2026-41253/)
- [Related: CVE-2026-41253 (NVD)](https://nvd.nist.gov/vuln/detail/CVE-2026-41253)
- [Precedent: CVE-2020-35605 kitty graphics protocol filename error-message code execution (Tenable)](https://tenable.com/cve/CVE-2020-35605)
- [Precedent: CVE-2020-35605 (NVD)](https://nvd.nist.gov/vuln/detail/CVE-2020-35605)

## Full data

The other 8 detection rules (Splunk SPL / Microsoft KQL / Sigma) unlock with TL Creds; a free account includes daily creds: https://threadlinqs.com/?modal=signup
Indicator values unlock with TL Creds, at a lower price on Red and Purple; AI agents can query rules and IOCs through the Threadlinqs MCP server (Purple and Gold in full, 2 calls a day on a free account): https://intel.threadlinqs.com/mcp

Canonical: https://intel.threadlinqs.com/threat/TL-2026-6698
