TUCoPS :: HP Unsorted N :: bx3753.htm

Netrw version 127, Vim 7.2b arbitrary code execution
Arbitrary code execution in Netrw version 127, Vim 7.2b
Arbitrary code execution in Netrw version 127, Vim 7.2b

1. Summary

Product  : Vim -- Vi IMproved, Netrw
Version  : Tested with Vim 7.2b, Netrw 127
Impact   : Arbitrary code execution
Wherefrom: Local, possibly remote
Original : http://www.rdancer.org/vulnerablevim-netrw.v5.html 

Lack of sanitization throughout Netrw can lead to arbitrary code execution upon
opening a directory with a crafted name.

2. Overview

``Netrw makes reading, writing, and browsing over a network connection
easy!  [...] Netrw supports "transparent" editing of files on other
machines using urls [...]''

	-- Netrw Reference Manual (pi_netrw.txt)

For the new Vim version, the Netrw plugin has been updated with the new
fnameescape() and shellescape() functions.  However, not all of the
vulnerable statements have been sanitized, and Netrw is still vulnerable
to arbitrary code execution.

The latest version of the archive with code that we're using can be
found at: ``http://www.rdancer.org/vulnerablevim-latest.tar.bz2''. 

Best results are achieved by running ``make test'' in the root directory
of the abovementioned archive (this advisory details the ``netrw.v5''
test case):

        -------- Test results below ---------------
        Vim version 7.2b
        zip.vim version: v21
        netrw.vim version: v127
          strong  : EXPLOIT FAILED
          weak    : EXPLOIT FAILED
        tarplugin : EXPLOIT FAILED
        tarplugin.updated: EXPLOIT FAILED
        zipplugin : EXPLOIT FAILED
        zipplugin.v2: EXPLOIT FAILED
          xpm     : EXPLOIT FAILED
          xpm2    : EXPLOIT FAILED
          remote  : EXPLOIT FAILED
        gzip_vim  : EXPLOIT FAILED
        netrw     : EXPLOIT FAILED
        netrw.v2  : EXPLOIT FAILED
        netrw.v3  : VULNERABLE
        netrw.v4  : EXPLOIT FAILED
    --> netrw.v5  : VULNERABLE

3. Vulnerability

Few unsanitized statements still remain in ``netrw.vim'':

	$ grep -n exe ~/.vim/autoload/netrw.vim|grep -v -e escape -e Decho -e
executable | wc -l

We will exploit the part of code where upon opening a directory, a
string of keyboard mappings is loaded, using the ``execute'' command,
with no sanitization of the ``b:netrw_curdir'' variable, which holds the
current directory name.  In function s:BrowserMaps():

        1709    if s:didstarstar || !mapcheck("","n")
        1710     nnoremap      :Pexplore
        1711    endif
        1712    if g:netrw_mousemaps == 1
        1713     nnoremap   
:call NetrwLeftmouse(1)
        1714     nnoremap   
:call NetrwPrevWinOpen(1)
        1715     nnoremap   
:call NetrwMarkFile(1,NetrwGetWord())
   -->  1716     exe 'nnoremap   
:call NetrwLocalRm("'.b:netrw_curdir.'")'
   -->  1717     exe 'vnoremap   
:call NetrwLocalRm("'.b:netrw_curdir.'")'
        1718    endif
   -->  1719    exe 'nnoremap           :call
   -->  1720    exe 'vnoremap           :call
   -->  1721    exe 'nnoremap   D            :call
   -->  1722    exe 'vnoremap   D            :call
   -->  1723    exe 'nnoremap   R            :call
   -->  1724    exe 'vnoremap   R            :call
   -->  1725    exe 'nnoremap   m    :call
        1726    nnoremap                 :he netrw-quickhelp

4. Exploit
Run ``make test''.  See ``netrw.v5/Makefile'' for details.  If Vim is
vulnerable, number of times the payload has been run is printed.
Current version of Vim will run the payload six times.

5. Mitigation

Do not use Vim to open untrusted directories or files whose path
contains untrusted directories.

6. Copyright

This advisory is Copyright 2008 Jan Minar  

Copying welcome, under the Creative Commons ``Attribution-Share Alike''
License http://creativecommons.org/licenses/by-sa/2.0/uk/ 

Code included herein, and accompanying this advisory, may be copied
according to the GNU General Public License version 2, or the Vim
license.  See the subdirectory ``licenses''.

Various portions of the accompanying code were written by various
parties.  Those parties may hold copyright, and those portions may be
copied according to the respective licenses.

7. History

2008-07-16 Sent to: , , 

TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2024 AOH