Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:12084
HistoryApr 05, 2006 - 12:00 a.m.

Buffer-overflow in Ultr@VNC 1.0.1 viewer and server

2006-04-0500:00:00
vulners.com
10

#######################################################################

                         Luigi Auriemma

Application: Ultr@VNC
http://www.ultravnc.com
http://ultravnc.sourceforge.net
Versions: <= 1.0.1 (and current CVS)
(tabbed_viewer 1.29 is ever the same VNC viewer 1.0.1 and
so it's vulnerable too)
Platforms: Windows
Bugs: A] client Log::ReallyPrint buffer-overflow
B] server VNCLog::ReallyPrint limited buffer-overflow
Exploitation: A] remoto, versus client
B] remoto, versus server
Date: 04 Apr 2006
Author: Luigi Auriemma
e-mail: [email protected]
web: http://aluigi.altervista.org

#######################################################################

1) Introduction
2) Bugs
3) The Code
4) Fix

#######################################################################

===============
1) Introduction

Ultr@VNC is a well known open source VNC server and viewer for Windows
very easy to use and configure.

#######################################################################

=======
2) Bugs


A] client Log::ReallyPrint buffer-overflow

During the login process a VNC client can receive three types of
replies from the server: connection failed, no authentication and
authentication required.
The first type of reply (rfbConnFailed) is followed by a text string
containing the reason of the disconnection.
Before visualizing this message Ultr@VNC logs everything in the log
file using the vnclog.Print function which adopts a buffer of 1024
bytes (LINE_BUFFER_SIZE) for storing the text.
The result is that a malicious VNC server could be able to execute
malicious code versus a vulnerable Ultr@VNC client which connects to
it.

>From vncviewer/Log.cpp:

void Log::ReallyPrint(LPTSTR format, va_list ap)
{
TCHAR line[LINE_BUFFER_SIZE];
_vstprintf(line, format, ap);
if (m_todebug) OutputDebugString(line);

if &#40;m_toconsole&#41; {
    DWORD byteswritten;
    WriteConsole&#40;GetStdHandle&#40;STD_OUTPUT_HANDLE&#41;, line, _tcslen&#40;line&#41;*sizeof&#40;TCHAR&#41;, &amp;byteswritten, NULL&#41;; 
};

if &#40;m_tofile &amp;&amp; &#40;hlogfile != NULL&#41;&#41; {
    DWORD byteswritten;
    WriteFile&#40;hlogfile, line, _tcslen&#40;line&#41;*sizeof&#40;TCHAR&#41;, &amp;byteswritten, NULL&#41;; 

}   

}


B] server VNCLog::ReallyPrint limited buffer-overflow

The logging function used by the Ultr@VNC server is affected by a
limited buffer-overflow caused by two strcat calls which add a Windows
error message to the output buffer.
Anyway there is an important detail about the exploitation of this bug.
The server is not vulnerable if the admin doesn't touch the "Log debug
infos to the WinVNC.log file" flag in the configuration, but when the
admin enables this option his server will be vulnerable forever
although he will re-disable it.

>From winvnc/winvnc/vnclog.cpp:

void VNCLog::ReallyPrint(const char* format, va_list ap)
{
time_t current = time(0);
if (current != m_lastLogTime) {
m_lastLogTime = current;
ReallyPrintLine(ctime(&m_lastLogTime));
}

    // - Write the log message, safely, limiting the output buffer size
    TCHAR line[LINE_BUFFER_SIZE];
    TCHAR szErrorMsg[LINE_BUFFER_SIZE];
    DWORD  dwErrorCode = GetLastError&#40;&#41;;
    SetLastError&#40;0&#41;;
    FormatMessage&#40; 
     FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwErrorCode,
     MAKELANGID&#40;LANG_NEUTRAL, SUBLANG_DEFAULT&#41;,&#40;char *&#41;&amp;szErrorMsg,
     LINE_BUFFER_SIZE, NULL&#41;;
_vsnprintf&#40;line, LINE_BUFFER_SIZE, format, ap&#41;;
    strcat&#40;line,&quot; --&quot;&#41;;
    strcat&#40;line,szErrorMsg&#41;;

    ReallyPrintLine&#40;line&#41;;

}

#######################################################################

===========
3) The Code

http://aluigi.altervista.org/poc/uvncbof.zip

#######################################################################

======
4) Fix

A patch will be released in the next weeks.

#######################################################################


Luigi Auriemma
http://aluigi.altervista.org