Expand file tree
Vim and Neovim before certain versions allow arbitrary code execution when opening a crafted text file because modelines can bypass the sandbox using the :source! command. An attacker could execute shell commands by tricking a user into opening a malicious file.
github.com
Published on github.com
History
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
Root cause
The modeline sandbox can be bypassed because the :source! command executes commands outside the sandbox, and functions like execute() or assert_fails() can be used to invoke it from a modeline expression.
Impact
An attacker could execute arbitrary shell commands on the victim's machine, potentially leading to a reverse shell, by convincing the victim to open a crafted file.
What the attacker needed
Victim opens a crafted file in Vim/Neovim; modelines enabled (default)
The fix
The vulnerability was fixed in Vim 8.1.1365 and Neovim 0.3.6; users should also disable modelines or modeline expressions.
How it was found
- Create a text file containing a malicious modeline.
- Ensure that the modeline option is enabled (it is by default).
- Open the file in Vim.
- The system executes the command specified in the modeline.
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.
Modelines are special comments at the start or end of a file that tell Vim how to format text. The sandbox is a restricted environment meant to prevent modelines from doing harmful things. However, a command called :source! can escape the sandbox and run any Vim command, including shell commands, so opening a malicious file can let an attacker run code on your computer.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.